shell获取zabbix监控数据
1.直接上脚本
#!/bin/bash # Zabbix登录参数 ZABBIX_URL="http://172.16.168.26:8080/zabbix/api_jsonrpc.php" ZABBIX_USER="Admin" ZABBIX_PASS="zabbix" #监控项ID ITEM_Iptables_ID=61645 #生成auth_id ID=$(curl --location --request GET ${ZABBIX_URL} \ --header 'Content-Type: application/json' \ -d'{ "jsonrpc": "2.0", "method": "user.login", "params": { "user": "'${ZABBIX_USER}'", "password": "'${ZABBIX_PASS}'" }, "auth": null, "id": 1 }') ITEM_VALUE=$(echo $ID | jq '.result') #echo ${ITEM_VALUE} #获取iptables访问量 ZABBIX_REQUEST=$( curl --location --request GET ${ZABBIX_URL} \ --header 'Content-Type: application/json' \ -d '{ "jsonrpc": "2.0", "method": "history.get", "params": { "output": "extend", "history": 3, "itemids": "'${ITEM_Iptables_ID}'", "sortfield": "clock", "sortorder": "DESC", "limit": 1 }, "auth": '${ITEM_VALUE}', "id":1 }') # 提取监控数值 ITEM_VALUE_Accout=$(echo $ZABBIX_REQUEST | jq '.result[0].value') # 打印监控数值 echo "iptables访问量: $ITEM_VALUE_Accout"