Vedr.: Re: checking for reboots of a host

Thomas Jens Lauritsen tjl at topdanmark.dk
Mon Aug 23 13:29:39 CEST 2004





Hi List,

I use this snmp-script....


#!/bin/sh
#
# check_booted.sh via SNMP
#
# Autor         : Thomas Jens Lauritsen <tjl at topdanmark.dk>
# Date          : 4. june 2004
# Version       : 1.0
# Description   : Script that checks if a box just has been booted via
SNMP.
# Req.          : The script uses the bc - calulator (Installed on most
*nix's)
# Advice        : Run the script for every 60 min - to keep the load down
on the cpu.
# Nagios        : In the services.cfg. Exampel:
check_booted.sh!public!100!1000!
# Info          : You have to change Oid for your system - see below (num1
and num2).
#
#                                                     crit  warn
# ./check_booted.sh <ip-address> <public> <100> <1000>
#
# Verify that there is an input
# ------------------------------
#
if [ -z "$1" ]; then
echo "usage  : check_booted.sh <hostname> <snmp-community> <crit-num1>
<warn-num2>"
echo "example: check_booted.sh 192.168.1.1 public 2 2 100 1000"
echo
exit
fi
#

# Variables
# ---------
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
SERVER=$1                    # Example: 10.0.0.3
SNMPCOMUNITY=$2              # Example: public
NUM1=$3                      # Example: "10" = 10 minutes CRITICAL
NUM2=$4                      # Example: "120"= 120 minutes WARNING

# CHECK HOST
#snmpget -v 1 $SERVER -c public .system.sysUpTime.0

# GET VALUE in Miliseconds

MILISEC=`/usr/bin/snmpget $SERVER $SNMPCOMUNITY .system.sysUpTime.0 | awk
'{ print $4  }'|bc`
#echo $MILISEC

#echo $C*$VALUE/1024/1024 | bc
>>/usr/local/nagios/libexec/$SERVER-$NUM1.txt
RESULT=`echo $MILISEC/100/60 | bc`
#echo $RESULT in minutes



# TELL NAGIOS WHAT WE COLLECTED - AND GIVE IT A STATE
if [ "$RESULT" -le "$NUM1" ] ; then
      $ECHO "BOOTED $RESULT Minutes ago..\n"
      exitstatus=$STATE_CRITICAL

elif [ "$RESULT" -le "$NUM2" ] ; then
      $ECHO "BOOTED $RESULT Minutes ago..\n"
      exitstatus=$STATE_WARNING

elif [ "$RESULT" -ge "$NUM2" ] ; then
     $ECHO "UPTIME - OK $RESULT Minutes\n"
      exitstatus=$STATE_OK

else
      $ECHO "UPTIME - UNKNOWN $RESULT Minutes\n"
      exitstatus=$STATE_UNKNOWN
fi

exit $exitstatus



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list