]> git.michaelhowe.org Git - packages/a/afs-monitor.git/commitdiff
More correctly check and report syntax errors
authorRuss Allbery <rra@stanford.edu>
Tue, 19 Oct 2010 16:48:49 +0000 (09:48 -0700)
committerRuss Allbery <rra@stanford.edu>
Tue, 19 Oct 2010 16:48:49 +0000 (09:48 -0700)
Print an UNKNOWN status on standard output on syntax errors in all
scripts, rather than reporting the problem only to standard error.
Check that the host to check was specified and report a syntax error
if it wasn't.  Thanks, Tobias Wolter.

NEWS
check_afsspace
check_bos
check_rxdebug
check_udebug

diff --git a/NEWS b/NEWS
index ee8362d1286c39147312bea331e57008e5e48d1b..641eab0b0e0d1fb926bf941be1856574abda1621 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,3 +9,8 @@ afs-monitor 2.0 (unreleased)
     salvage), check_bos now reports a warning stating that, rather than a
     critical error showing the auxiliary status line.  Reported by Steve
     Rader.
+
+    Print an UNKNOWN status on standard output on syntax errors in all
+    scripts, rather than reporting the problem only to standard error.
+    Check that the host to check was specified and report a syntax error
+    if it wasn't.  Thanks, Tobias Wolter.
index 1104402c5d657b994f3c664afb00b132d5e1cf70..29da098cc3d77c6893299ad0de074c7b6fc66179 100755 (executable)
@@ -46,6 +46,15 @@ $VOS ||= '/usr/bin/vos';
 # Implementation
 ##############################################################################
 
+# Report a syntax error and exit.  We do this via stdout in order to satisfy
+# the Nagios plugin output requirements, but also report a more conventional
+# error via stderr in case people are calling this outside of Nagios.
+sub syntax {
+    print "AFS UNKNOWN - ", join ('', @_), "\n";
+    warn "$0: ", join ('', @_), "\n";
+    exit 3;
+}
+
 # Parse command line options.
 my ($help, $host, $version);
 Getopt::Long::config ('bundling', 'no_ignore_case');
@@ -54,7 +63,8 @@ GetOptions ('c|critical=i' => \$CRITICAL,
             'h|help'       => \$help,
             't|timeout=i'  => \$TIMEOUT,
             'V|version'    => \$version,
-            'w|warning=i'  => \$WARNINGS) or exit 3;
+            'w|warning=i'  => \$WARNINGS)
+    or syntax ("invalid option");
 if ($help) {
     print "Feeding myself to perldoc, please wait....\n";
     exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
@@ -63,13 +73,10 @@ if ($help) {
     print "check_afsspace $version\n";
     exit 0;
 }
-if (@ARGV) {
-    warn "Usage: $0 [-hv] [-c <level>] [-w <level>] -H <host>\n";
-    exit 3;
-}
+syntax ("extra arguments on command line") if @ARGV;
+syntax ("host to check not specified") unless (defined $host);
 if ($WARNINGS > $CRITICAL) {
-    warn "$0: warning level $WARNINGS greater than critical level $CRITICAL\n";
-    exit 3;
+    syntax ("warning level $WARNINGS greater than critical level $CRITICAL");
 }
 
 # Set up the alarm.
index e0363b81c8c45a109a3f1d9456fc3d04cd54dca3..67a06eb70c155f80b0a09b407c5a95b31e63a8db 100755 (executable)
--- a/check_bos
+++ b/check_bos
@@ -57,13 +57,23 @@ our @OKAY = (
 # Implementation
 ##############################################################################
 
+# Report a syntax error and exit.  We do this via stdout in order to satisfy
+# the Nagios plugin output requirements, but also report a more conventional
+# error via stderr in case people are calling this outside of Nagios.
+sub syntax {
+    print "BOS UNKNOWN - ", join ('', @_), "\n";
+    warn "$0: ", join ('', @_), "\n";
+    exit 3;
+}
+
 # Parse command line options.
 my ($help, $host, $version);
 Getopt::Long::config ('bundling', 'no_ignore_case');
 GetOptions ('H|hostname=s' => \$host,
             'h|help'       => \$help,
             't|timeout=i'  => \$TIMEOUT,
-            'V|version'    => \$version) or exit 3;
+            'V|version'    => \$version)
+    or syntax ("invalid option");
 if ($help) {
     print "Feeding myself to perldoc, please wait....\n";
     exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
@@ -72,11 +82,8 @@ if ($help) {
     print "check_bos $version\n";
     exit 0;
 }
-if (@ARGV) {
-    print "Usage: $0 [-hv] [-t <timeout>] -H <host>\n";
-    warn "Usage: $0 [-hv] [-t <timeout>] -H <host>\n";
-    exit 3;
-}
+syntax ("extra arguments on command line") if @ARGV;
+syntax ("host to check not specified") unless (defined $host);
 
 # Set up the alarm.
 $SIG{ALRM} = sub {
index 1d138b5d8e2e5ff1b980ab2fae02fcc030b1f4b3..4e497fd0ee4f3c2fc39a0cff50a1fa9a35a8ad59 100755 (executable)
@@ -48,6 +48,15 @@ $RXDEBUG ||= '/usr/bin/rxdebug';
 # Implementation
 ##############################################################################
 
+# Report a syntax error and exit.  We do this via stdout in order to satisfy
+# the Nagios plugin output requirements, but also report a more conventional
+# error via stderr in case people are calling this outside of Nagios.
+sub syntax {
+    print "AFS UNKNOWN - ", join ('', @_), "\n";
+    warn "$0: ", join ('', @_), "\n";
+    exit 3;
+}
+
 # Parse command line options.
 my ($help, $host, $version);
 Getopt::Long::config ('bundling', 'no_ignore_case');
@@ -56,7 +65,8 @@ GetOptions ('c|critical=i' => \$CRITICAL,
             'h|help'       => \$help,
             't|timeout=i'  => \$TIMEOUT,
             'V|version'    => \$version,
-            'w|warning=i'  => \$WARNINGS) or exit 3;
+            'w|warning=i'  => \$WARNINGS)
+    or syntax ("invalid option");
 if ($help) {
     print "Feeding myself to perldoc, please wait....\n";
     exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
@@ -65,13 +75,10 @@ if ($help) {
     print "check_rxdebug $version\n";
     exit 0;
 }
-if (@ARGV) {
-    warn "Usage: $0 [-hv] [-c <level>] [-w <level>] -H <host>\n";
-    exit 3;
-}
+syntax ("extra arguments on command line") if @ARGV;
+syntax ("host to check not specified") unless (defined $host);
 if ($WARNINGS > $CRITICAL) {
-    warn "$0: warning level $WARNINGS greater than critical level $CRITICAL\n";
-    exit 3;
+    syntax ("warning level $WARNINGS greater than critical level $CRITICAL");
 }
 
 # Set up the alarm.
index 00db9b23f7d0c39cfbdab05ef16ec111bb6e5b42..a486eb8fe808118cd62a81eb1640736934c73a79 100755 (executable)
@@ -40,6 +40,15 @@ $UDEBUG ||= '/usr/bin/udebug';
 # Implementation
 ##############################################################################
 
+# Report a syntax error and exit.  We do this via stdout in order to satisfy
+# the Nagios plugin output requirements, but also report a more conventional
+# error via stderr in case people are calling this outside of Nagios.
+sub syntax {
+    print "UBIK UNKNOWN - ", join ('', @_), "\n";
+    warn "$0: ", join ('', @_), "\n";
+    exit 3;
+}
+
 # Parse command line options.
 my ($help, $host, $port, $version);
 Getopt::Long::config ('bundling', 'no_ignore_case');
@@ -47,7 +56,8 @@ GetOptions ('H|hostname=s' => \$host,
             'h|help'       => \$help,
             'p|port=i'     => \$port,
             't|timeout=i'  => \$TIMEOUT,
-            'V|version'    => \$version) or exit 3;
+            'V|version'    => \$version)
+    or syntax ("invalid option");
 if ($help) {
     print "Feeding myself to perldoc, please wait....\n";
     exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
@@ -56,10 +66,9 @@ if ($help) {
     print "check_udebug $version\n";
     exit 0;
 }
-if (@ARGV || !(defined ($host) && defined ($port))) {
-    warn "Usage: $0 [-hv] [-t <timeout>] -H <host> -p <port>\n";
-    exit 3;
-}
+syntax ("extra arguments on command line") if @ARGV;
+syntax ("host to check not specified") unless (defined $host);
+syntax ("port to check not specified") unless (defined $port);
 
 # Set up the alarm.
 $SIG{ALRM} = sub {