For 1.4.9 release
[monitoring-plugins.git] / plugins-scripts / utils.pm.in
blobd68f30905f8c06782846ce32ddd03a037dc1cc06
1 # Utility drawer for Nagios plugins.
2 # $Id$
4 # This will be deprecated soon. Please use Nagios::Plugin from CPAN
5 # for new plugins
7 package utils;
9 require Exporter;
10 @ISA = qw(Exporter);
11 @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
13 #use strict;
14 #use vars($TIMEOUT %ERRORS);
15 sub print_revision ($$);
16 sub usage;
17 sub support();
18 sub is_hostname;
20 ## updated by autoconf
21 $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
22 $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
23 $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
24 $PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
25 $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@";
27 ## common variables
28 $TIMEOUT = 15;
29 %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
31 ## utility subroutines
32 sub print_revision ($$) {
33 my $commandName = shift;
34 my $pluginRevision = shift;
35 $pluginRevision =~ s/^\$Revision: //;
36 $pluginRevision =~ s/ \$\s*$//;
37 print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
38 print "@WARRANTY@";
41 sub support () {
42 my $support='@SUPPORT@';
43 $support =~ s/@/\@/g;
44 $support =~ s/\\n/\n/g;
45 print $support;
48 sub usage {
49 my $format=shift;
50 printf($format,@_);
51 exit $ERRORS{'UNKNOWN'};
54 sub is_hostname {
55 my $host1 = shift;
56 return 0 unless defined $host1;
57 if ($host1 =~ m/^[\d\.]+$/ && $host1 !~ /\.$/) {
58 if ($host1 =~ m/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
59 return 1;
60 } else {
61 return 0;
63 } elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]*(\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\.?$/) {
64 return 1;
65 } else {
66 return 0;