2005-07-01 00:00:00
This script was written at the time I was hired by UPC / Liberty Global.
Basic monitor that checks if the server is up and running. It checks for a process and whether the server has drifted from its higher level Stratum server.
This script was quickly hacked together for my current customer, as a Q&D solution for their monitoring needs. It's no beauty, but it works. Written in ksh and tested with:
The script sends a Critical if:
A) One or more processes are not running, or
B) The server's clock has drifted too far from its higher level Stratum server.
Requires the "check_ntp" plugin which is part of the default monitor package.
UPDATE 19/06/2006:
Cleaned up the script a bit and added some checks that are considered the Right Thing to do. Should have done this -way- earlier!
#!/usr/bin/bash # # NTP server process monitor plugin for Nagios # Written by Thomas Sluyter (nagiosATkilalaDOTnl) # By request of DTV Labs, Liberty Global, the Netherlands # Last Modified: 19-06-2006 # # Usage: ./check_ntp_s # # Description: # This plugin determines whether the Nagios client is functioning # properly as an NTP server. It does this by checking: # * Are all required processes running? # * Is the server's time up to scratch with its higher stratum server? # # Limitations: # Currently this plugin will only function correctly on Solaris systems. # # Output: # The script returns a CRIT when one of the abovementioned criteria # is not matched. # # Host OS check and warning message if [ `uname` != "SunOS" ] then echo "WARNING:" echo "This script was originally written for use on Solaris." echo "You may run into some problems running it on this host." echo "" echo "Please verify that the script works before using it in a" echo "live environment. You can easily disable this message after" echo "testing the script." echo "" fi # You may have to change this, depending on where you installed your # Nagios plugins PATH="/usr/bin:/usr/sbin:/bin:/sbin" LIBEXEC="/usr/local/nagios/libexec" . $LIBEXEC/utils.sh print_usage() { echo "Usage: $PROGNAME" echo "Usage: $PROGNAME --help" } print_help() { echo "" print_usage echo "" echo "NTP server plugin for Nagios" echo "" echo "This plugin not developped by the Nagios Plugin group." echo "Please do not e-mail them for support on this plugin, since" echo "they won't know what you're talking about :P" echo "" echo "For contact info, read the plugin itself..." } while test -n "$1" do case "$1" in --help) print_help; exit $STATE_OK;; -h) print_help; exit $STATE_OK;; *) print_usage; exit $STATE_UNKNOWN;; esac done check_processes() { PROCESS="0" if [ `ps -ef | grep xntpd | grep -v grep | grep -v nagios | wc -l` -lt 1 ]; then PROCESS=1;fi if [ $PROCESS -eq 1 ]; then echo "NTP-S NOK - One or more processes not running" exitstatus=$STATE_CRITICAL exit $exitstatus fi } check_time() { TIME="0" #SERVERS="ntp0.nl.net ntp1.nl.net ntp2.nl.net" SERVERS="nl-ams99z-a02-01" for SERV in `echo $SERVERS`; do if [ `/usr/local/nagios/libexec/check_ntp -H $SERV | awk '{print $2}'` != "OK:" ]; then TIME=1 else TIME=0 break fi done if [ $TIME -eq 1 ]; then echo "NTP-S NOK - Time not in synch with higher Stratum." exitstatus=$STATE_CRITICAL exit $exitstatus fi } check_processes check_time echo "NTP-S OK - Everything running like it should" exitstatus=$STATE_OK exit $exitstatus
kilala.nl tags: nagios, unix, programming,
View or add comments (curr. 1)
Posted by Gene Siepka (website)
Hi.. just a suggestion on your check_ntp_s script for nagios. Not sure if you keep up on this still or not but....
In the check_time function.. making the SERVERS variable read from /etc/inet/ntp.conf makes this totally portable to any Solaris system.
SERVERS=`grep server /etc/inet/ntp.conf | awk '{print $2}'`
quick and dirty but this way if one ever has to change ntp servers, they don't have to worry about going back and fixing monitors..
Great scripts you have nagios BTW! They've been a great help.
Thanks
-Gene Siepka
All content, with exception of "borrowed" blogpost images, or unless otherwise indicated, is copyright of Tess Sluijter. The character Kilala the cat-demon is copyright of Rumiko Takahashi and used here without permission.
You are free to use this specific work, to share and distribute it and to adapt it for your own purposes. However, you must attribute this work as mine and you must share all of your alterations. Click on the logo, or follow this link for full details.