zabbix - API 入门 - 未完待续

官网介绍:

Zabbix API allows you to programmatically retrieve and modify the configuration of Zabbix and provides access to historical data. It is widely used to:

  • Create new applications to work with Zabbix;
  • Integrate Zabbix with third party software;
  • Automate routine tasks.

The Zabbix API is a web based API and is shipped as part of the web frontend. It uses the JSON-RPC 2.0 protocol which means two things:

  • The API consists of a set of separate methods;
  • Requests and responses between the clients and the API are encoded using the JSON format.

===================================

1. 获取auth

curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth":null,"id":0}' http://192.168.4.142/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Fri, 24 May 2019 00:29:31 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 68
Connection: close
Content-Type: application/json

{"jsonrpc":"2.0","result":"aab4f7f7be4778f2fab229980f4a95c4","id":0}

2. 获取主机信息

curl -i -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["host","hostid"],
        "filter": {
            "host": [
                "dbw01at.daodao.com",
                "dbw01bt.daodao.com"
            ]
        }
    },
    "auth": "aab4f7f7be4778f2fab229980f4a95c4",
    "id": 1
}' http://192.168.4.142/api_jsonrpc.php

3. 获取主机组信息

curl -i -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "hostgroup.get",
    "params": {
        "output": ["groupid","name"],
        "selectGroups": "extend",
        "filter": {
            "name": [
                "DataCenter T"
            ]
        }
    },
    "auth": "aab4f7f7be4778f2fab229980f4a95c4",
    "id": 1
}' http://192.168.4.142/api_jsonrpc.php

4. 获取监控项id

curl -i -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
        "output": ["itemid", "name", "key_"],
        "hostids": "10138",
        "search": {
            "key_": "cpu"
        }
    },
    "auth": "aab4f7f7be4778f2fab229980f4a95c4",
    "id": 1
}' http://192.168.4.142/api_jsonrpc.php

5. 获取某项监控数据

curl -i -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "history.get",
    "params": {
        "output": "extend",
        "history": 0,
        "itemids": "33583",
        "sortfield": "clock",
        "sortorder": "DESC",
        "limit": 10
    },
    "auth": "aab4f7f7be4778f2fab229980f4a95c4",
    "id": 1
}' http://192.168.4.142/api_jsonrpc.php

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值