Advertisement
kazoda

Zabbix api sh 2

Aug 10th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Refer to https://github.com/zembutsu/zabbix-api-tools/blob/master/auth.sh
  4.  
  5. ## Usage ./zab.sh json_file
  6.  
  7. json='{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"id":1}'
  8. authid=$(curl -s -XGET -H"Content-Type:application/json-rpc" -d$json http://10.0.3.10/zabbix/api_jsonrpc.php | jq -r '.result')
  9.  
  10. if [ $1 = "history_get.json" ]; then
  11.         while read line
  12.         do
  13.                 json=$(cat $1 | jq -r "." -c | sed -e s/AUTH_ID/$authid/g -e s/ITEM_ID/$line/g)
  14.                 echo "ITEM-ID: $line"
  15.                 curl -s -XGET -H"Content-Type:application/json-rpc" -d$json http://10.0.3.10/zabbix/api_jsonrpc.php | jq -r '.result'
  16.                 #sleep 10
  17.         done < item.list
  18. else
  19.         json=$(cat $1 | jq -r "." -c | sed -e s/AUTH_ID/$authid/g)
  20.         curl -s -XGET -H"Content-Type:application/json-rpc" -d$json http://10.0.3.10/zabbix/api_jsonrpc.php | jq -r '.result'
  21. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement