1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #!/bin/bash
url=adresse zabbix
function zbx_login {
resp=$(curl -3 -k -X POST -H 'Content-Type:application/json' -d'{"jsonrpc": "2.0","method":"user.authenticate","params":{"user":"gdi","password":"gd"},"auth": null,"id":0}' $url)
echo $resp | awk -F=":" -v RS="," '$1~/"result"/ {print}' | cut -d '"' -f4
}
function zbx_get_host {
resp=$(curl -3 -k -X POST -H 'Content-Type: application/json' -d "{\"jsonrpc\":\"2.0\",\"method\":\"host.get\",\"params\":{\"output\":\"extend\",\"sortfield\":\"hostid\"},\"auth\":\"$(zbx_login)\",\"id\":0}" $url)
echo $resp | awk -F=":" -v RS="," '$1~/"host"/ {print}' | cut -d '"' -f4
}
function zbx_get_item {
resp=$(curl -3 -k -X POST -H 'Content-Type: application/json' -d "{\"jsonrpc\":\"2.0\",\"method\":\"item.get\",\"params\":{\"output\":\"extend\",\"host\":\"$1\"},\"auth\":\"$(zbx_login)\",\"id\":0}" $url)
echo $resp | awk -F=":" -v RS="," '$1~/"itemid"/ {print}' | cut -d '"' -f4
}
function zbx_get_history {
resp=`curl -3 -k -X POST -H 'Content-Type: application/json' -d "{\"jsonrpc\":\"2.0\",\"method\":\"history.get\",\"params\":{\"itemids\":\"$2\",\"history\":[1,2,3,4],\"output\":\"extend\",\"time_from\":\"$3\",\"time_till\":\"$4\",\"limit\":1},\"auth\":\"$(zbx_login)\",\"id\":0}" $url`
echo $resp | awk -F=":" -v RS="," '$1~/"value"/ {print}' | cut -d '"' -f4
}
host=$(zbx_get_host)
declare -a host_array
host_array=(${host// / })
rm /home/gd/result.txt 2>/dev/null
touch /home/gd/result.txt
declare -a item_array
for i in ${host_array[@]};
do
item=$(zbx_get_item $i)
item_array=(${item// / })
echo -n $i";">>/home/gd/result.txt
for x in ${item_array[@]};
do
echo -n $x";">>/home/gd/result.txt
done
item_array=()
echo "" >> /home/gd/result.txt
done |
Partager