--- check_ntp 2006-02-20 10:26:15.000000000 +0100 +++ check_ntp_new 2006-02-24 13:40:12.000000000 +0100 @@ -61,8 +61,8 @@ use POSIX; use strict; use Getopt::Long; -use vars qw($opt_V $opt_h $opt_H $opt_t $opt_w $opt_c $opt_O $opt_j $opt_k $verbose $PROGNAME $def_jitter $ipv4 $ipv6); -use lib "nagios/plugins"; +use vars qw($opt_V $opt_h $opt_H $opt_t $opt_w $opt_c $opt_O $opt_j $opt_k $opt_s $verbose $PROGNAME $def_jitter $ipv4 $ipv6); +use lib "/usr/lib/nagios/plugins/"; use utils qw($TIMEOUT %ERRORS &print_revision &support); $PROGNAME="check_ntp"; @@ -94,6 +94,7 @@ "j=s" => \$opt_j, "jwarn=i" => \$opt_j, # jitter warning if above this number "k=s" => \$opt_k, "jcrit=i" => \$opt_k, # jitter critical if above this number "t=s" => \$opt_t, "timeout=i" => \$opt_t, + "s=s" => \$opt_s, "stratum=i" => \$opt_s, "H=s" => \$opt_H, "hostname=s" => \$opt_H); if ($opt_V) { @@ -152,6 +153,7 @@ my $stratum = -1; +my $lowstratum = 13; my $ignoreret = 0; my $answer = undef; my $offset = undef; @@ -165,6 +167,11 @@ my $ntpdate_error = $ERRORS{'UNKNOWN'}; my $jitter_error = $ERRORS{'UNKNOWN'}; + +if ($opt_s) { + $lowstratum=$opt_s; +} + # some systems don't have a proper ntpq (migrated from ntpdc) my $have_ntpq = undef; if ($utils::PATH_TO_NTPQ && -x $utils::PATH_TO_NTPQ ) { @@ -240,6 +247,11 @@ } } + if ($stratum >= $lowstratum) { + $ntpdate_error = $ERRORS{"WARNING"}; + $msg = "Syncronized to local clock"; + $ignoreret=1; + } } close (NTPDATE); @@ -432,7 +444,7 @@ #### subs sub print_usage () { - print "Usage: $PROGNAME -H [-46] [-O] [-w ] [-c ] [-j ] [-k ] [-v verbose]\n"; + print "Usage: $PROGNAME -H [-46] [-O] [-w ] [-c ] [-j ] [-k ] [-v verbose] [-s ]\n"; } sub print_help () { @@ -456,6 +468,10 @@ If jitter/dispersion is specified with -j or -k and ntpq times out, then a warning is returned.\n +-s (--stratum) + A stratum value higher than this will result in a warning state. Most Linux\n + systems run at stratum 13 if they have no external reference clock. + Defaults to 13. -4 (--use-ipv4) Use IPv4 connection -6 (--use-ipv6)