zoukankan      html  css  js  c++  java
  • Zabbix的API的使用

      上一篇:Zabbix低级主动发现之MySQL多实例

      

      登录请求(返回一个token,在后面的api中需要用到)

    curl -s -X POST -H 'Content-Type:application/json' -d'
    {
        "jsonrpc": "2.0",
        "method": "user.login",
        "params": {
            "user": "Admin",
            "password": "zabbix"
            
        },
        "id": 1
    }' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool
    
    
    {
        "id": 1,
        "jsonrpc": "2.0",
        "result": "940da948f7aabb512d71c13ced76699a"
    }
    

      

      host get

    curl -s -X POST -H 'Content-Type:application/json' -d'
    {
        "jsonrpc": "2.0",
        "method": "host.get",
        "params": {
            "output":["host"]
        },
        
        "auth": "940da948f7aabb512d71c13ced76699a",
        "id": 1
    }' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool
    
    
    {
        "id": 1,
        "jsonrpc": "2.0",
        "result": [
            {
                "host": "Zabbix server",
                "hostid": "10084"
            },
            {
                "host": "linux-node2.example.com",
                "hostid": "10117"
            }
        ]
    }
    

      获取到了host和hostid  怎么查看

      添加主机的api

      修改配置

      修改了ip groupid 和templateid(删除了官方的资产信息)

    curl -s -X POST -H 'Content-Type:application/json' -d'
    {
        "jsonrpc": "2.0",
        "method": "host.create",
        "params": {
            "host": "Linux server",
            "interfaces": [
                {
                    "type": 1,
                    "main": 1,
                    "useip": 1,
                    "ip": "192.168.80.160",
                    "dns": "",
                    "port": "10050"
                }
            ],
            "groups": [
                {
                    "groupid": "2"
                }
            ],
            "templates": [
                {
                    "templateid": "10001"
                }
            ]
        },
        "auth": "940da948f7aabb512d71c13ced76699a",
        "id": 1
    }' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool
    

      添加成功

      

      创建主机api的应用脚本批量添加主机(list.txt写好需要添加主机的ip列表)

      zabbix_host_creates.sh

    #!/bin/bash
    #login
    tok=`curl -s -X POST -H 'Content-Type:application/json' -d'
    {
        "jsonrpc": "2.0",
        "method": "user.login",
        "params": {
            "user": "Admin",
            "password": "zabbix"
            
        },
        "id": 1
    }' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool`
    jsson= echo "$tok" | grep result | awk -F '"' '{print $4}'
    #create hosts
    for ip in `cat list.txt` 
    do
    curl -s -X POST -H 'Content-Type:application/json' -d'
    {
        "jsonrpc": "2.0",
        "method": "host.create",
        "params": {
            "host": '"$ip"',
            "interfaces": [
                {
                    "type": 1,
                    "main": 1,
                    "useip": 1,
                    "ip": '"$ip"',
                    "dns": "",
                    "port": "10050"
                }
            ],
            "groups": [
                {
                    "groupid": "11"
                }
            ],
            "templates": [
                {
                    "templateid": "10001"
                }
            ]
        },
        "auth": '"$jsson"',
        "id": 1
    }' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool
    done
    

      运行报错了

      下一篇:Zabbix分布式监控

      

      

  • 相关阅读:
    Java字符串操作
    easyui Combotree根据用户输入显示对应的tree值
    maven
    引用 js表单验证大全 以后方便查看用
    对象内存模型
    高级性能服务器编程模型【IOCP完成端口】开发实现【一】
    高级性能服务器编程模型【IOCP完成端口】开发实现【二】
    高级性能服务器编程模型【IOCP完成端口】开发实现【三】
    探讨【IGE】的源代码【六】,承接【五】,内存池管理。
    hive beeline详解
  • 原文地址:https://www.cnblogs.com/minseo/p/8642930.html
Copyright © 2011-2022 走看看