SHOW:
|
|
- or go back to the newest paste.
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 | - | json=$(cat $1 | jq -r "." -c | sed -e s/AUTH_ID/$authid/g) |
10 | + | if [ $1 = "history_get.json" ]; then |
11 | - | echo $json |
11 | + | while read line |
12 | - | curl -s -XGET -H"Content-Type:application/json-rpc" -d$json http://10.0.3.10/zabbix/api_jsonrpc.php | jq -r '.result' |
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 |