Code

added programs to autoconf
[nagiosplug.git] / plugins-scripts / utils.pm.in
1 # Utility drawer for Nagios plugins.
2 # $Id$
3 #
4 # $Log$
5 # Revision 1.3  2002/05/10 03:49:22  sghosh
6 # added programs to autoconf
7 #
8 # Revision 1.2  2002/05/08 05:10:35  sghosh
9 #  is_hostname added, update CODES to POSIX
10 #
11
12 package utils;
14 require Exporter;
15 @ISA = qw(Exporter);
16 @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
18 #use strict;
19 #use vars($TIMEOUT %ERRORS);
20 sub print_revision ($$);
21 sub usage;
22 sub support();
23 sub is_hostname;
25 ## updated by autoconf
26 $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
27 $PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ;
28 $PATH_TO_NTPDC   = "@PATH_TO_NTPDC@" ;
29 $PATH_TO_LMSTAT  = "@PATH_TO_LMSTAT@" ;
31 ## common variables
32 $TIMEOUT = 15;
33 %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
35 ## utility subroutines
36 sub print_revision ($$) {
37         my $commandName = shift;
38         my $pluginRevision = shift;
39         $pluginRevision =~ s/^\$Revision: //;
40         $pluginRevision =~ s/ \$\s*$//;
41         print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
42         print "@WARRANTY@";
43 }
45 sub support () {
46         my $support='@SUPPORT@';
47         $support =~ s/@/\@/g;
48         $support =~ s/\\n/\n/g;
49         print $support;
50 }
52 sub usage {
53         my $format=shift;
54         printf($format,@_);
55         exit $ERRORS{'UNKNOWN'};
56 }
58 sub is_hostname {
59         my $host1 = shift;
60         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]+)*)$/) {
61                 return 1;
62         }else{
63                 return 0;
64         }
65 }
67 1;