Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #TH v0.2 30/08/2013
- #Quick and Dirty Memory SNMP Poller
- if [ $# -le 3 ] && [ $# -gt 5 ]; then
- echo "Usage: $0 <hostname> <SNMP-comunity> <warning> <critical> <optional - Port>"
- echo "Warning and Critical must be in percent"
- echo "e.g 10.10.10.1 public 80 90"
- exit 127
- fi
- HOST=$1
- COMUNITY=$2
- WARN=$3
- CRITICAL=$4
- if [ -z $5 ]; then
- PORT=161
- else
- PORT=$5
- fi
- #make sure warning is less than critical
- if [ "$WARN" -ge "$CRITICAL" ]; then
- echo "WArning must be less than critical"
- exit 127
- fi
- DiskUse() {
- snmpdf -r 3 -t 1 -v 2c -c "$COMUNITY" "$HOST":$PORT 2> /dev/null |head -6|tail -5|awk '{print $3" "$4" "$5'}
- }
- DISKUSE=(`DiskUse`)
- #check at this point that the probe worked and quit if it failed
- #this is kinda crap, but the alterntive is not using bash
- if [ "${#DISKUSE[@]}" -ne 15 ]; then
- echo "SNMP problem. No data received from host."
- exit 3
- fi
- TOTAL=${DISKUSE[0]}
- USED=${DISKUSE[1]}
- BUFFERS=${DISKUSE[7]}
- CACHE=${DISKUSE[10]}
- REALUSED=$(($USED - $CACHE - $BUFFERS))
- #bash does not like floating point numbers
- printf -v PERCENTF "%.0f" `echo "scale=50; 100/$TOTAL*$REALUSED"|bc`
- if [ "$PERCENTF" -ge "$WARN" ] && [ "$PERCENTF" -le "$CRITICAL" ]; then
- echo "MEMORY WARNING - ${PERCENTF}% Used|Total ${TOTAL}KB, Buffers ${BUFFERS}KB, Cached ${CACHE}KB, Used ${REALUSED}KB"
- exit 1
- elif [ "$PERCENTF" -ge "$CRITICAL" ]; then
- echo "MEMORY CRITICAL - ${PERCENTF}% Used|Total ${TOTAL}KB, Buffers ${BUFFERS}KB, Cached ${CACHE}KB, Used ${REALUSED}KB"
- exit 2
- else
- echo "MEMORY OK - ${PERCENTF}% Used|Total ${TOTAL}KB, Buffers ${BUFFERS}KB, Cached ${CACHE}KB, Used ${REALUSED}KB"
- exit 0
- fi
Advertisement
Add Comment
Please, Sign In to add comment