Fix typo
[monitoring-plugins.git] / plugins-scripts / utils.pm.in
blob37cd62c3b8210f3476f0f3964491eb3a35e3caf3
1 # Utility drawer for Nagios plugins.
3 # This will be deprecated soon. Please use Nagios::Plugin from CPAN
4 # for new plugins
6 package utils;
8 require Exporter;
9 @ISA = qw(Exporter);
10 @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
12 #use strict;
13 #use vars($TIMEOUT %ERRORS);
14 sub print_revision ($$);
15 sub usage;
16 sub support();
17 sub is_hostname;
19 ## updated by autoconf
20 $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
21 $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
22 $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
23 $PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
24 $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@";
26 ## common variables
27 $TIMEOUT = 15;
28 %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
30 ## utility subroutines
31 sub print_revision ($$) {
32 my $commandName = shift;
33 my $pluginRevision = shift;
34 print "$commandName v$pluginRevision (@PACKAGE@ @VERSION@)\n";
35 print "@WARRANTY@";
38 sub support () {
39 my $support='@SUPPORT@';
40 $support =~ s/@/\@/g;
41 $support =~ s/\\n/\n/g;
42 print $support;
45 sub usage {
46 my $format=shift;
47 printf($format,@_);
48 exit $ERRORS{'UNKNOWN'};
51 sub is_hostname {
52 my $host1 = shift;
53 return 0 unless defined $host1;
54 if ($host1 =~ m/^[\d\.]+$/ && $host1 !~ /\.$/) {
55 if ($host1 =~ m/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
56 return 1;
57 } else {
58 return 0;
60 } elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]*(\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\.?$/) {
61 return 1;
62 } else {
63 return 0;