zabbix的日常监控-API

Zabbix API提供两项主要功能:
  远程管理Zabbix配置
  远程检索配置和历史数据

 

官方文档:https://www.zabbix.com/documentation/3.4/zh/manual/api

 

 

1、获取一个身份认证

[root@zabbix ~]# curl -s -X POST -H 'Content-Type:application/json' -d'{"jsonrpc": "2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth": null,"id":0}' http://10.0.0.200/zabbix/api_jsonrpc.php | python -m json.tool
{
    "id": 0,
    "jsonrpc": "2.0",
    "result": "780edf281a71f9feff572791a2e497c4"
}
[root@zabbix ~]# 
注:780edf281a71f9feff572791a2e497c4 这个就是要获取的值;

 

2、获取在线的所有主机名称

https://www.zabbix.com/documentation/3.4/zh/manual/api/reference/host/get

[root@zabbix ~]# curl -s -X POST -H 'Content-Type:application/json' -d'{"jsonrpc": "2.0","method":"host.get","params":{"output":["host"]},"auth":"780edf281a71f9feff572791a2e497c4","id":1}' http://10.0.0.200/zabbix/api_jsonrpc.php | python -m json.tool
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "host": "Zabbix server",
            "hostid": "10084"
        },
        {
            "host": "10.0.0.199",
            "hostid": "10265"
        },
        {
            "host": "db01",
            "hostid": "10259"
        }
    ]
}
[root@zabbix ~]# 

 

3、查询指定模板内有哪些项

https://www.zabbix.com/documentation/3.4/zh/manual/api/reference/template/get 

curl -s -X POST -H 'Content-Type:application/json' -d'
{
    "jsonrpc": "2.0",
    "method": "template.get",
    "params": {
        "output": "extend",
        "filter": {
            "host": [
                "Template OS Linux"
            ]
        }
    },
    "auth": "780edf281a71f9feff572791a2e497c4",
    "id": 1
}' http://10.0.0.200/zabbix/api_jsonrpc.php | python -m json.tool

  

4、添加一个主机

https://www.zabbix.com/documentation/3.4/zh/manual/api/reference/host/create

curl -s -X POST -H 'Content-Type:application/json' -d'
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "bjcnc-web01-25k-0000",  #主机名
        "interfaces": [
            {
                "type": 1,   #默认就可以
                "main": 1,
                "useip": 1,
                "ip": "10.0.0.199",   #zagent端IP地址
                "dns": "",
                "port": "10050"    #端口
            }
        ],
        "groups": [
            {
                "groupid": "15"   #组的ID
            }
        ],
        "templates": [
            {
                "templateid": "10001"  #模板ID
            }
        ]
    },
    "auth": "780edf281a71f9feff572791a2e497c4",   #更改对应的认证密钥
    "id": 1  #默认即可
}' http://10.0.0.200/zabbix/api_jsonrpc.php | python -m json.tool
注:本次只是单纯的添加,为给该主机指定模板

 

 

 

posted @ 2018-03-20 13:14  无敌仙人掌  阅读(3463)  评论(0编辑  收藏  举报
AmazingCounters.com