Code

pst3.c must not use nagiosplug/gnulib includes
[nagiosplug.git] / plugins-scripts / check_ntp.pl
index e844327b226ebb215f3a08e5999c48d1513974bd..5c87e0a66e66ba003b9d3b6597c0d0fd086a9993 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl -w
-
+#
 # (c)1999 Ian Cass, Knowledge Matters Ltd.
 # Read the GNU copyright stuff for all the legalese
 #
@@ -7,7 +7,6 @@
 # be installed on the system, however since it's part of the ntp suite, you 
 # should already have it installed.
 #
-# $Id$
 #
 # Nothing clever done in this program - its a very simple bare basics hack to
 # get the job done.
@@ -97,7 +96,7 @@ GetOptions
         "H=s" => \$opt_H, "hostname=s" => \$opt_H);
 
 if ($opt_V) {
-       print_revision($PROGNAME,'$Revision$ ');
+       print_revision($PROGNAME,'@NP_VERSION@');
        exit $ERRORS{'OK'};
 }
 
@@ -200,13 +199,15 @@ elsif ($ipv6) {
 ###
 
 if (!open (NTPDATE, $ntpdate . " -q $host 2>&1 |")) {
-       print "Could not open ntpdate\n";
+       print "Could not open $ntpdate: $!\n";
        exit $ERRORS{"UNKNOWN"};
 }
 
+my $out;
 while (<NTPDATE>) {
        #print if ($verbose);  # noop
        $msg = $_ unless ($msg);
+       $out .= "$_ ";
        
        if (/stratum\s(\d+)/) {
                $stratum = $1;
@@ -241,8 +242,11 @@ while (<NTPDATE>) {
        }
 
 }
+$out =~ s/\n//g;
+close (NTPDATE) || 
+    die $! ? "$out - Error closing $ntpdate pipe: $!"
+           : "$out - Exit status: $? from $ntpdate\n";
 
-close (NTPDATE); 
 # declare an error if we also get a non-zero return code from ntpdate
 # unless already set to critical
 if ( $? && !$ignoreret ) {
@@ -313,7 +317,9 @@ if ($have_ntpq) {
                        }
                        
                }
-               close NTPQ;
+               close NTPQ ||
+            die $! ? "Error closing $ntpq pipe: $!"
+                   : "Exit status: $? from $ntpq\n";
 
                # if we did not match sys.peer or pps.peer but matched # candidates only
                # generate a warning 
@@ -436,7 +442,7 @@ sub print_usage () {
 }
 
 sub print_help () {
-       print_revision($PROGNAME,'$Revision$');
+       print_revision($PROGNAME,'@NP_VERSION@');
        print "Copyright (c) 2003 Bo Kersey/Karl DeBisschop\n";
        print "\n";
        print_usage();