欢迎访问linux宝典,请记住本站唯一域名:www.linuxbaodian.com

API接口管理zabbix

来源:原创    更新时间:2018-10-15 21:34:53    编辑:管理员    浏览:304

1.查看zabbix监控系统的api接口:

使用user.login登录并获得身份验证令牌

[root@localhost ~]# vim zabbix-api.sh
 
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "redhat"
    },
    "id": 1,
    "auth": null
}' http://172.25.12.10/zabbix/api_jsonrpc.php | python -m json.tool
[root@localhost ~]# ./zabbix-api.sh
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "ff50cc18e45ab6da19b8868ec780b932"            #autu
}

使用host.get得到主机信息

[root@localhost ~]# vim zabbix-api.sh
 
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
                "hostid",
                "host"
        ],
        "selectInterfaces":[
                "interfaceid",
                "ip"
        ]
    },
    "auth": "ff50cc18e45ab6da19b8868ec780b932",     #这里填写前面得到的autu
    "id": 2
}' http://172.25.12.10/zabbix/api_jsonrpc.php | python -m json.tool
[root@localhost ~]# ./zabbix-api.sh
 
{
    "id": 2,
    "jsonrpc": "2.0",
    "result": [
        {
            "host": "Zabbix server",     #zabbix server的信息
            "hostid": "10084",
            "interfaces": [
                {
                    "interfaceid": "1",
                    "ip": "127.0.0.1"
                }
            ]
        },
        {
            "host": "server1",          #被监控主机信息
            "hostid": "10256",
            "interfaces": [
                {
                    "interfaceid": "4",
                    "ip": "172.25.12.1"
                }
            ]
        }
    ]
}

使用host.delete删除zabbix监控中的主机

[root@localhost ~]# vim zabbix-api.sh
 
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.delete",
    "params": [
                "10256"        #hosttid
        ],
    "auth": "ff50cc18e45ab6da19b8868ec780b932",
    "id": 2
}' http://172.25.12.10/zabbix/api_jsonrpc.php | python -m json.tool
[root@localhost ~]# ./zabbix-api.sh 
{
    "id": 2,
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10256"
        ]
    }
}

使用host.create创建被监控主机

curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "server1",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "172.25.12.1",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "templates": [
            {
                "templateid": "10001"
            }
        ]
    },
    "id": 2,
    "auth": "ff50cc18e45ab6da19b8868ec780b932"
}' http://172.25.12.10/zabbix/api_jsonrpc.php | python -m json.tool
[root@localhost ~]# ./zabbix-api.sh 
{
    "id": 2,
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10258"
        ]
    }
}


评论区

表情

共0条评论
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

相关内容

点击排行

随机新闻

评论排行榜