Search code examples
bashzabbix

how to create multi user paramerter in zabbix from a script


This is a shell script return 2 values one for packet loss percentage and another for True or False :

SERVER_IP=$1

checkip=`ping -c 2 -W 2 $SERVER_IP | grep "packet loss" | cut -d " " -f 6  | cut -d "%" -f1`
test1=$? 
echo $checkip 
if [ $test1 -eq 0 ]; then

 echo "1"

else

 echo "0"

fi 

in zabbix when you create an item you enter only one parameter with value but i have 2 values one packet loss and second for ping result (0 and 1)

how can i create two items 1 for packet lost percentage and second for ping health check with only this script? i dont want to create another one


Solution

  • Thanks to Andre

    try this script this will guide you to what exactly you want :

    #!/bin/bash
    
        case $1 in
    
        packetloss) ping -c2 -W1 -q 8.8.8.8 | grep -oP '\d+(?=% packet loss)' ;;
        timeout) ping -c2 -q 8.8.8.8 | grep 'time' | awk -F',' '{ print$4}' | awk '{print $2}' | cut -c 1-4 ;;
        *) echo "Use: packetloss , timeout";;
    
        esac
    

    try (im in zsh):

    zabbix_agentd -t ping.loss\[timeout\]   
    ping.loss[timeout]                            [t|1000]
    

    or in zabbix server use get ( im also in zsh here too):

    zabbix_get -s 172.20.4.49 -k ping.loss\[timeout\]         
    1001
    

    now create items with these keys.