Code

Fix Debian bug #545940: Failure when run via ePN
[nagiosplug.git] / plugins-scripts / utils.pm.in
index 8316f9e1188c3e1cf4a1e2dcd1a2ef44e6d5322f..37cd62c3b8210f3476f0f3964491eb3a35e3caf3 100644 (file)
@@ -1,23 +1,8 @@
 # Utility drawer for Nagios plugins.
-# $Id$
 #
-# $Log$
-# Revision 1.6  2003/02/03 20:29:55  sghosh
-# change ntpdc to ntpq (Jonathan Rozes,Thomas Schimpke, bug-656237 )
-#
-# Revision 1.5  2002/10/30 05:07:29  sghosh
-# monitor mailq
-#
-# Revision 1.4  2002/05/27 02:01:09  sghosh
-#  new var - smbclient
-#
-# Revision 1.3  2002/05/10 03:49:22  sghosh
-# added programs to autoconf
-#
-# Revision 1.2  2002/05/08 05:10:35  sghosh
-#  is_hostname added, update CODES to POSIX
-#
-# 
+# This will be deprecated soon. Please use Nagios::Plugin from CPAN
+# for new plugins
+
 package utils;
 
 require Exporter;
@@ -33,12 +18,10 @@ sub is_hostname;
 
 ## updated by autoconf
 $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
-$PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ;
-$PATH_TO_NTPDC   = "@PATH_TO_NTPDC@" ;
-$PATH_TO_NTPQ    = "@PATH_TO_NTPQ@" ;
 $PATH_TO_LMSTAT  = "@PATH_TO_LMSTAT@" ;
 $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
 $PATH_TO_MAILQ   = "@PATH_TO_MAILQ@";
+$PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@";
 
 ## common variables
 $TIMEOUT = 15;
@@ -48,9 +31,7 @@ $TIMEOUT = 15;
 sub print_revision ($$) {
        my $commandName = shift;
        my $pluginRevision = shift;
-       $pluginRevision =~ s/^\$Revision: //;
-       $pluginRevision =~ s/ \$\s*$//;
-       print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
+       print "$commandName v$pluginRevision (@PACKAGE@ @VERSION@)\n";
        print "@WARRANTY@";
 }
 
@@ -69,9 +50,16 @@ sub usage {
 
 sub is_hostname {
        my $host1 = shift;
-       if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/) {
+       return 0 unless defined $host1;
+       if ($host1 =~ m/^[\d\.]+$/ && $host1 !~ /\.$/) {
+               if ($host1 =~ m/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
+                       return 1;
+               } else {
+                       return 0;
+               }
+       } elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]*(\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\.?$/) {
                return 1;
-       }else{
+       } else {
                return 0;
        }
 }