zabbix-api

一、API官方文档

https://www.zabbix.com/documentation/4.0/zh/manual/api

https://www.zabbix.com/documentation/5.0/zh/manual/api

二、使用示例

1、获取zabbix token 

curl -s -X POST http://192.168.1.1/zabbix/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "zaAdmin!@#$2019"
    },
    "id": 1,
    "auth": null
}' | python -m json.tool 

返回用户身份验证令牌:

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "8ef873a332822d8acdf6b6f6e4fb2398"
}

2、使用api检索主机

curl -s -X POST http://192.168.1.1/zabbix/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.get",
	"params": {
		"output": [
			"hostid",
			"host"
		],
		"selectInterfaces": [
			"interfaceid",
			"ip"
		]
	},
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' | python -m json.tool 

检索指定ip主机

curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.get",
	"params": {
		"filter": {
			"host": [
				"10.2.33.100"
			]
		},
		"selectInterfaces": [
			"interfaceid",
			"ip"
		]
	},
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' http://192.168.1.1/zabbix/api_jsonrpc.php | python -m json.tool 

3、使用api添加主机

curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.create",
	"params": {
		"host": "servername-192.168.1.2"
		"interfaces": [
		   {
			"type": 1,
			"main": 1,
			"useip": 1,
			"ip": "192.168.1.2",
			"dns": "",
			"port": "10050"
		    }
		],
		"groups": [
		    {
		        "groupid": "2"
		    }
		],
		"tags": [
		    {
		        "tag": "Host name",
			"value": "servername-192.168.1.2"
		    }
		],
		"templates": [
		    {
		        "templateid": "10001"
		    }
		]
	},
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' http://192.168.1.1/zabbix/api_jsonrpc.php | python -m json.tool 

4、使用api删除主机

curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.delete",
	"params": [
	    "10065"
	],
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' http://192.168.1.1/zabbix/api_jsonrpc.php | python -m json.tool 

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯飙的蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值