1,认证并取得加密字段
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.1.222/zabbix/api_jsonrpc.php;
2,获取指定或所有监控主机的hostids
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"host.get","params":{"output":["hostid"],"filter": {"host":"192.168.1.223"}},"auth": "b61b7168931be1065cd722ab44e32d2a","id": 0}' http://192.168.1.222/zabbix/api_jsonrpc.php;
zabbix下所有监控主机hostids
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"host.get","params":{"output":["hostid"]},"auth": "b61b7168931be1065cd722ab44e32d2a","id": 0}' http://192.168.1.222/zabbix/api_jsonrpc.php;
3,获得指定主机下指定监控项或是所有监控项itemids
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"item.get","params":{"output":"itemids","hostids":"10119","search":{"key_":"system.cpu.util[,idle]"}},"auth": "91aca8c1fe89c89c2e457ab18a28e79b","id": 0}' http://192.168.1.222/zabbix/api_jsonrpc.php;
zabbix下指定主机的所有itemids
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"item.get","params":{"output":["itemids"],"hostids":"10119"},"auth": "91aca8c1fe89c89c2e457ab18a28e79b","id": 0}' http://192.168.1.222/zabbix/api_jsonrpc.php
4,获取指定监控项在指定时间段的值
获取指定itemids的所有历史数据;
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"history.get","params":{"history":0,"itemids":["23902"],"output":"extend"},"auth": "91aca8c1fe89c89c2e457ab18a28e79b","id": 0}' http://192.168.1.222/zabbix/api_jsonrpc.php
获取指定监控项itemids的指定时间段历史数据;
我们获取下2014-05-01到2014-05-03期间的数据语句如下
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"history.get","params":{"history":0,"itemids":["23902"],"time_from":"1398873600","time_till":"1399046400","output":"extend"},"auth": "91aca8c1fe89c89c2e457ab18a28e79b","id": 0}' http://192.168.1.222/zabbix/api_jsonrpc.php
数据比较多,其凌乱,value就是我们要的值了;
此种使用的是秒数需将字符串时间值(2014/05/01 --转换为自1970/1/1以来的秒数值)换算一下我在这里用shell简单搞下
5,抓指定时间点的值
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"history.get","params":{"history":0,"itemids":["23902"],"time_from":"1398873600","time_till":"1399046400","output":"extend","filter":{"clock":"1399026180"}},"auth": "91aca8c1fe89c89c2e457ab18a28e79b","id": 0}' http://192.168.1.222/zabbix/api_jsonrpc.php
看抓取的数据结构完全可以给他导到xml中;
zabbix API Object specifications without the 'draft' mark are stable and can be used for production purposes
curl模拟调用zabbix JSON-RPC格式
curl -i -X POST -H 'Content-Type: application/json' -d ‘api json语句’ zabbix-server--即我的测试机http://192.168.1.222/zabbix/api_jsonrpc.php;
来个模板吧,你copy此处到你的终端吧数据语句放到''中要是没问题的话即可返回你所要的数据
curl -i -X POST -H 'Content-Type: application/json' -d
'
你的json语句拷贝与此处;
' 你的zabbix服务器api 的url
Examples,都是Ruiy根据官网及相关文档改写亲测成功的,你仅需的就是修改下你的zabbix服务器API的URL即可;
1,获取监控主机信息
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"host.get","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":4 }' http://192.168.1.222/zabbix/api_jsonrpc.php
2,zabbix版本
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"apiinfo.version","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":1 }' http://192.168.1.222/zabbix/api_jsonrpc.php
3,获取auth加密字段
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"user.authenticate","params":{"user":"admin","password":"zabbix"},"auth":null,"id":0}' http://192.168.1.222/zabbix/api_jsonrpc.php
将"method":"user.authenticate"改成"method":"user.login";
4,获取web scenario信息
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"httptest.get","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":1 }' http://192.168.1.222/zabbix/api_jsonrpc.php;
5,获取zabbix系统中以定义了的macro
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"usermacro.get","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":1 }' http://192.168.1.222/zabbix/api_jsonrpc.php
6,告警介质
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"usermedia.get","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":1 }' http://192.168.1.222/zabbix/api_jsonrpc.php
关于json的相关格式语法本人没接触也不懂,需要的同仁自己查阅;
相关的测试我也就不一一列举了,下面我把zabbix-API所以的method reference给各位同仁罗列下,参考自zabbix Official manual
我仅仅罗列method,关于每个method的动作操作(.get,.create,.delete,.update,.exists,...不足或不限制于此处罗列)省
1, action.get
2, alter.get
3, apiinfo.version
4, application
5, configuration.import/export
6, discovered host dhost/service/check/rule.get
7, event.get
8, graph.get
9, graphitem.get
10, prototype.get
11, history.get
12, host/group/interface/prototype/.get
13, icon.get
14, image.get
15, item
16, .....
好了,来点开心的,古战将熟记之宋;
岳飞帐下猛将四枪四锤。
四枪:高宠(錾金虎头枪)、陆文龙(六沉四尖双枪)、杨再兴、张宪。
四大锤:八棱紫金锤严成方(一对金锤)、梅花亮银锤岳云(一对银锤)、六方青铜锤狄雷(一对铜锤)、镔铁压油锤何元庆(一对铁锤)
宋营中武力最强的两名武将:高宠(且不管人物是否虚构,),杨继周--杨再兴之子;
宋未朝廷已近凋零(那些奸臣的嘴脸着实令我想咬他们一口),有的大将没被金人干掉,到被自家给坑了,金人兴旺...;
JSON(JavaScript structure textual representation)