zabbix API 使用

作者: print("") 分类: linux 发布时间: 2018-04-13 17:56

zabbix 官方地址

https://www.zabbix.com/documentation/3.0/manual/api/reference/user/login

这里弄几个简单的例子 官方都介绍了

curl -s -X POST -H 'Content-type:application/json' -d ' 
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "Wu123456.."
    },
    "id": 1
}' http://192.168.57.132/zabbix/api_jsonrpc.php | python -mjson.tool



65b234ea48bdfa55019b2799b063251a



curl -s -X POST -H 'Content-type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"]
    },
    "auth": "65b234ea48bdfa55019b2799b063251a",
    "id": 1
}'  http://192.168.57.132/zabbix/api_jsonrpc.php | python -mjson.tool



1. 验证
curl -s -X POST -H 'Content-type:application/json' -d ' 
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "Wu123456.."
    },
    "id": 1
}' http://192.168.57.132/zabbix/api_jsonrpc.php | python -mjson.tool

SessionID:
21f86cdc5f6d103a3100e7aaa2f01a8c

2、请求API ,附带上SessionID
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.57.131",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "templates": [
            {
                "templateid": "10001"
            }
        ]
      
    },
    "auth": "21f86cdc5f6d103a3100e7aaa2f01a8c",
    "id": 1
}' http://192.168.57.132/zabbix/api_jsonrpc.php | python -mjson.tool

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

您的电子邮箱地址不会被公开。