zabbix的API调用

2024-01-09 07:07:39

zabbix的API调用

资料参考:https://www.zabbix.com/documentation/4.0/zh/manual/api

看api文档就可以了,粘两个例子吧,如果配置了域名,可以请求域名

[root@node ~]# vi zabbix_login.api
curl -XPOST -H "Content-Type: application/json-rpc" -d '
{
        "jsonrpc": "2.0",
        "method": "user.login",
        "params": {
                "user": "Admin",
                "password": "zabbix"
        },
        "id": 1,
        "auth": null
}' http://serverIP/zabbix/api_jsonrpc.php
[root@node ~]# sh zabbix.api
{"jsonrpc":"2.0","result":"8b16faa2f8c9d02f0a6694d667774bac","id":1}

拿到用户用户认证令牌后,就可以使用令牌来操作了

[root@node ~]# vi zabbix_gethost.api
 curl -XPOST -H "Content-Type: application/json-rpc" -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
            "hostid",
            "host"
        ],
        "selectInterfaces": [
            "interfaceid",
            "ip"
        ]
    },
    "id": 2,
    "auth": "8b16faa2f8c9d02f0a6694d667774bac"
}
' http://serverIP/zabbix/api_jsonrpc.php
[root@node ~]# sh zabbix_gethost.api
{"jsonrpc":"2.0","result":[{"hostid":"10442","host":"zbx-agent","interfaces":[{"interfaceid":"11","ip":"x.x.x.x"}]}],"id":2}

文章来源:https://blog.csdn.net/qq_45029110/article/details/135468947
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。