Check Peers script: wrong output nagios
Posted: Mon Aug 17, 2015 3:56 am
output in nagios is diffrent.
Nagios output is always:
when i run the script manualy:
below the script:
Nagios output is always:
Code: Select all
ok.
Code: Select all
Problems
vogels: 0/ 10
tijhuis: 0/ 3
sh: 0/ 19
Code: Select all
#!/bin/bash
#
# Description: Check peers
#
melding=0;
COUNT_NOT_OK=$(asterisk -rx "sip show peers" | grep "Lagged\|UNREACHABLE\|UNKNOWN" | awk -F '/' '{print $1}' | sed 's/[^a-Z]*//g'| uniq | sort -n | \sort -rn);
arr=$(echo $COUNT_NOT_OK | tr " " "\n");
for x in $arr
do
COUNT_UN=$(asterisk -rx "sip show peers" | grep $x | grep "Lagged\|UNREACHABLE\|UNKNOWN" | awk '{print ""}' | uniq -c | sort -n);
COUNT_OK=$(asterisk -rx "sip show peers" | grep $x | grep "OK" | awk '{print ""}' | uniq -c | sort -n);
if [ "$COUNT_UN" = "" ]; then
COUNT_UN=0;
fi
if [ "$COUNT_OK" = "" ]; then
COUNT_OK=0;
fi
total=$((COUNT_UN+COUNT_OK));
#echo "totaal: $total"
procent=$(($total*50/100))
if [ $total == 1 ] && [ $COUNT_UN == 1 ] || [ $total == 2 ] && [ $COUNT_UN == 2 ] ; then
melding=2;
elif [ $total -gt 2 ] && [ $COUNT_UN -gt $procent ]; then
melding=2;
elif [ $total -gt 2 ] && [ $COUNT_UN -eq $total ]; then
melding=2;
fi
done
if [ $melding = 0 ]; then
echo "ok.";
if [ "$arr" != "" ]; then
for y in $arr
do
COUNT_UN=$(asterisk -rx "sip show peers" | grep $y | grep "Lagged\|UNREACHABLE|\UNKNOWN" | awk '{print ""}' | uniq -c | sort -n);
COUNT_OK=$(asterisk -rx "sip show peers" | grep $y | grep "OK" | awk '{print ""}' | uniq -c | sort -n);
if [ "$COUNT_UN" = "" ]; then
COUNT_UN=0;
fi
if [ "$COUNT_OK" = "" ]; then
COUNT_OK=0;
fi
total=$((COUNT_UN+COUNT_OK));
echo $y: $COUNT_UN"/" $total;
done
fi
exit $melding;
elif [[ ${melding} == "2" ]]; then
echo "Problems";
if [ "$arr" != "" ]; then
for y in $arr
do
COUNT_UN=$(asterisk -rx "sip show peers" | grep $y | grep "Lagged\|UNREACHABLE|\UNKNOWN" | awk '{print ""}' | uniq -c | sort -n);
COUNT_OK=$(asterisk -rx "sip show peers" | grep $y | grep "OK" | awk '{print ""}' | uniq -c | sort -n);
if [ "$COUNT_UN" = "" ]; then
COUNT_UN=0;
fi
if [ "$COUNT_OK" = "" ]; then
COUNT_OK=0;
fi
total=$((COUNT_UN+COUNT_OK));
echo $y: $COUNT_UN"/" $total;
done
fi
exit $melding;
else
echo "Cant read output.";
exit 3;
fi