19、zabbix api
版权声明:原创作品,谢绝转载!否则将追究法律责任。 ————— 作者:kirin
api:应用程序接口
什么是调用api
怎么调用api,发起一个http请求
curl "http://apis.juhe.cn/simpleWeather/query?city=昌平 &key=3dae6629acd8689e9b12f8bb4f"
{"reason":"查询成功!","result":{"city":"昌平","realtime":
{"temperature":"13","humidity":"15","info":"晴","wid":"00","direct":"西风","power":"2级","aqi":"67"},"future":
[{"date":"2021-02-05","temperature":"1\/13℃","weather":"晴","wid":
{"day":"00","night":"00"},"direct":"西风转西北风"},
{"date":"2021-02-06","temperature":"-3\/13℃","weather":"多云","wid":
{"day":"01","night":"01"},"direct":"西北风转南风"},
{"date":"2021-02-07","temperature":"-5\/5℃","weather":"晴","wid":
{"day":"00","night":"00"},"direct":"东南风转北风"},
{"date":"2021-02-08","temperature":"-5\/5℃","weather":"多云转晴","wid":
{"day":"01","night":"00"},"direct":"东南风转西北风"},
{"date":"2021-02-09","temperature":"-3\/9℃","weather":"多云转晴","wid":
{"day":"01","night":"00"},"direct":"东南风转西北风"}]},"error_code":0}
调用zabbix-api
获取token
curl -X POST -H 'Content-Type:application/json-rpc' -d
'
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": 1,
"auth": null
}' http://10.0.0.71/api_jsonrpc.php
返回结果;
{"jsonrpc":"2.0","result":"6d33c0a88b0d55d7860eea70005
c5b5b","id":1}
token='6d33c0a88b0d55d7860eea70005c5b5b'
删除主机
curl -X POST -H 'Content-Type:application/json-rpc' -d
'
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
10372
],
"auth": "'$token'",
"id": 1
}' http://10.0.0.71/api_jsonrpc.php
返回结果
{"jsonrpc":"2.0","result":{"hostids":[10372]},"id":1}
创建主机
curl -X POST -H 'Content-Type:application/json-rpc' -d
'
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "10.0.0.8",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "10.0.0.8",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "17"
}
],
"templates": [
{
"templateid": "10357"
}
]
},
"auth": "'$token'",
"id": 1
}' http://10.0.0.71/api_jsonrpc.php
返回结果:
{"jsonrpc":"2.0","result":{"hostids":
["10377"]},"id":1}
批量创建主机
[root@web01 ~]# cat piliang_create_host.sh
#!/bin/bash
token='6d33c0a88b0d55d7860eea70005c5b5b'
for n in `echo 10.0.0.{50..100}`
do
curl -X POST -H 'Content-Type:application/json-rpc' -d
'
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "'$n'",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "10.0.0.8",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "17"
}
],
"templates": [ {
"templateid": "10357"
}
]
},
"auth": "'$token'",
"id": 1
}' http://10.0.0.71/api_jsonrpc.php
done
本文来自博客园,作者:kirin(麒麟),转载请注明原文链接:https://www.cnblogs.com/kirin365/articles/16387172.html