命令行获取zabbix最新的issues - jq 解释json

0.安装jq

wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
chmod +x ./jq
cp jq /usr/bin
jq -r . jsonData.json

参考: https://blog.csdn.net/wangpei1949/article/details/78702272

1.获取token

[root@master ~]# cat auth.py 
#!/usr/bin/env python2.7
#coding=utf-8
import json
import urllib2
# based url and required header
url = "http://10.2.1.51/zabbix/api_jsonrpc.php"
header = {"Content-Type":"application/json"}
# auth user and password
data = json.dumps(
{
   "jsonrpc": "2.0",
   "method": "user.login",
   "params": {
   "user": "admin",
   "password": "zabbix"
},
"id": 0
})
# create request object
request = urllib2.Request(url,data)
for key in header:
   request.add_header(key,header[key])
# auth and get authid
try:
   result = urllib2.urlopen(request)
except URLError as e:
   print "Auth Failed, Please Check Your Name AndPassword:",e.code
else:
   response = json.loads(result.read())
   result.close()
print"Auth Successful. The Auth ID Is:",response['result']

Auth Successful. The Auth ID Is: 5dde049736d6a70ea4c7418b3a7dea23

2.获取最新的issues

[root@master tmp]# cat loadjson.sh 
#!/bin/bash
curl -s -X POST -H 'Content-Type:application/json' -d '{"jsonrpc": "2.0","method": "trigger.get","params": {"output": ["triggerid","description","priority","lastchange"], "filter": {"value": 1},"sortfield": "priority","sortorder": "DESC","min_severity": 1,"skipDependent": 1,"monitored": 1, "active": 1,"expandDescription": 1,"selectHosts": ["host"],"selectGroups": ["name"],"selectItems": [ "name"],"only_true": 1},"auth": "5dde049736d6a70ea4c7418b3a7dea23","id": 0}' http://10.2.1.51/zabbix/api_jsonrpc.php >/tmp/json_my.json
cd /tmp/
jq -r . json_my.json >last.json
cat /tmp/last.json|grep -i 'descri'|awk -F'"' '{print $4}'

[root@master tmp]# sh loadjson.sh
Lack of available memory on server agent-2-28
Zabbix discoverer processes more than 75% busy

参考: https://www.cnblogs.com/learningJAVA/p/7943236.html

posted @ 2019-04-28 18:43  littlevigra  阅读(457)  评论(0编辑  收藏  举报