Code

substituted $ID$ through $Revision$ in print_revision call
[nagiosplug.git] / plugins-scripts / utils.pm.in
index ed105ddaf1f765d112e6629240ecfcf2dc809590..d68f30905f8c06782846ce32ddd03a037dc1cc06 100644 (file)
@@ -1,11 +1,9 @@
 # Utility drawer for Nagios plugins.
 # $Id$
 #
-# $Log$
-# 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;
@@ -19,9 +17,18 @@ sub usage;
 sub support();
 sub is_hostname;
 
+## updated by autoconf
+$PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
+$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;
 %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
 
+## utility subroutines
 sub print_revision ($$) {
        my $commandName = shift;
        my $pluginRevision = shift;
@@ -46,9 +53,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;
        }
 }