bin bash Основной скрипт мониторинга по snmp RC1 wres tail -n res tmp

  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
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#Основной скрипт мониторинга по snmp
#v 0.6 RC1
wres(){
tail -n 2 res > tmp && cat tmp > res && echo $1 >> res && rm tmp
}
wget --http-user --http-password http:///list.php -O prep_list -o /dev/null
for SERVER in `cat commented`
do
cat prep_list | grep -v $SERVER > temp && cat temp > prep_list
done
rm temp
cat prep_list > _list
rm prep_list
echo "" > latmp
cat anotherservers >> _list
LINES=`cat _list | grep -v "#" | sort | uniq | grep '.' | wc -l`
rm log
rm _log
rm _lag
for UNIC in `cat _list | grep -v "#" | awk '{print($2)}' | sort | uniq`
do
for IP in `cat _list | grep -v "#" | sort | uniq | grep $UNIC | awk '{print($1)}'`
do
snmpstatus -c $UNIC -v 1 -L e $IP > servers/log.$IP 2>&1 &
TYPE=""
TYPE=`cat _list | grep -v "#" | sort | uniq | grep $IP | awk '{print($3)}'`
#echo $TYPE
if [ "$TYPE" == "nix" ]
then
snmpwalk -c $UNIC -v 1 $IP -O v .1.3.6.1.4.1.2021.10.1.5.3 > latmp.$IP 2>&1 && LA=`cat latmp.$IP | grep -v "Time" | grep -o "[0-9]*"` && echo "$LA $IP" > serverla/la.$IP && rm latmp.$IP &
fi
while [ `ps ax | grep snmp | grep -v grep | wc -l` -ge 5 ]
do
sleep 3s
done
#echo "snmpstatus -c $UNIC -v 1 -L e $IP | grep UDP >> log"
done
done
while [ `ps ax | grep snmp | grep -v grep | wc -l` -ne 0 ]
do
sleep 2s
done
cat servers/log.* >> _log
rm servers/log.*
cat serverla/la.* >> _lag
rm serverla/la.*
for LAIP in `cat _lag | awk '{print($2)}'`
do
LAS=`cat _lag | grep $LAIP | awk '{print($1)}'`
#`cat _list | grep -v "#" | sort | uniq | grep $IP | awk '{print($3)}'`
if [ $LAS -gt 1000 ]
then
echo "$LAIP's LA is abnormal and = $LAS"
fi
done
cat _log | grep -v "Timeout" | grep "UDP" > log
for GUESS in `cat _log | grep "Timeout" | awk '{print($5)}'`
do
MATCH=`cat _list | grep $GUESS | awk '{print($1)}'`
echo "$MATCH is n/a"
done
DONE=`cat log | wc -l`
RES=$(($LINES-$DONE))
#echo $RES
if [ "$RES" = "0" ];
then wres 0
else wres 1
fi
for NUM in `cat res`
do
I=$(($I+$NUM))
done
ZZ=`cat res | tail -n 1`
if [ "$ZZ" != "0" ]
then
#case "$I" in
# 0) echo "Its ok";;
# 3) mplayer /home/v2nek/monit/Dance.mp3;;
# *) echo "Hmmm..";;
#esac
if [ "$I" = "3" ];
#then mplayer /home/v2nek/monit/Dance.mp3
then echo "shit..."
else echo "Hmmm.."
fi
else echo "Its ok"