index 361bfe99c2d314978882f95e33783aa512064f1a..37cd62c3b8210f3476f0f3964491eb3a35e3caf3 100644 (file)
+# Utility drawer for Nagios plugins.
+#
+# This will be deprecated soon. Please use Nagios::Plugin from CPAN
+# for new plugins
+
package utils;
require Exporter;
sub print_revision ($$);
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=('UNKNOWN'=>-1,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2);
+%ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
+## utility subroutines
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@";
}
exit $ERRORS{'UNKNOWN'};
}
+sub is_hostname {
+ my $host1 = shift;
+ 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 {
+ return 0;
+ }
+}
+
1;