#!/usr/bin/bash # # CPU load monitor plugin for Nagios # Written by Thomas Sluyter (nagios@kilala.nl) # By request of KPN-IS, i-Provide, the Netherlands # Last Modified: 10-07-2006 # # Usage: ./check_ntp_config # # Description: # Well, there's not much to tell. We have no way of making sure that our # NTP clients are all configured in the right way, so I thought I'd make # a Nagios check for it. ^_^ # You can change the NTP config at the top of this script, to match your # own situation. # # Limitations: # This script should work properly on all implementations of Linux, Solaris # and Mac OS X. # # Output: # If the NTP client config does not match what has been defined at the # top of this script, the script will return a WARN. # # Other notes: # If you ever run into problems with the script, set the DEBUG variable # to 1. I'll need the output the script generates to do troubleshooting. # See below for details. # I realise that all the debugging commands strewn throughout the script # may make things a little harder to read. But in the end I'm sure it was # well worth adding them. It makes troubleshooting so much easier. :3 # # 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 ### DEFINING THE NTP CLIENT CONFIGURATION AS IT SHOULD BE ### NTP_SERVER="ntp.wxs.nl" ### DEBUGGING SETUP ### # Cause you never know when you'll need to squash a bug or two DEBUG="0" if [ $DEBUG -gt 0 ] then DEBUGFILE="/tmp/foobar" rm $DEBUGFILE >/dev/null 2>&1 fi ### REQUISITE NAGIOS COMMAND LINE STUFF ### print_usage() { echo "Usage: $PROGNAME" echo "Usage: $PROGNAME --help" } print_help() { echo "" print_usage echo "" echo "NTP client configuration monitor 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 ### DEFINING SUBROUTINES ### function gather_config() { case `uname` in Linux) CFGFILE="/etc/ntp.conf"; IP_SERVER=`host $NTP_SERVER | awk '{print $4}'` ;; SunOS) CFGFILE="/etc/inet/ntpd.conf"; IP_SERVER=`getent hosts $NTP_SERVER | awk '{print $2}'`;; Darwin) CFGFILE="/etc/ntp.conf"; IP_SERVER=`host $NTP_SERVER | awk '{print $4}'` ;; *) ;; esac REAL_SERVER=`cat $CFGFILE | grep ^server | awk '{print $2}'` [ $DEBUG -gt 0 ] && echo "Gather_config: Host name for required server is $NTP_SERVER." >> $DEBUGFILE [ $DEBUG -gt 0 ] && echo "Gather_config: IP address for required server is $IP_SERVER." >> $DEBUGFILE [ $DEBUG -gt 0 ] && echo "Gather_config: currently configured server is $REAL_SERVER." >> $DEBUGFILE } function check_config() { if [ $REAL_SERVER != $NTP_SERVER ] then if [ $REAL_SERVER != $IP_SERVER ] then echo "NOK - NTP client is not configured to speak to $NTP_SERVER" exit $STATE_WARNING fi fi } ### FINALLY, THE MAIN ROUTINE ### gather_config check_config # Nothing caused us to exit early, so we're okay. echo "OK - NTP client configured correctly." exit $STATE_OK