1 # Utility drawer for Nagios plugins.
2 # $Id$
3 #
4 # $Log$
5 # Revision 1.9 2006/10/19 18:44:53 tonvoon
6 # Allow hostnames beginning with digits (O'Shaughnessy Evans - 1567390)
7 #
8 # Revision 1.8 2006/06/07 14:23:12 seanius
9 # removed stale references to PATH_TO_NTPFOO, as it's no longer used.
10 #
11 # Revision 1.7 2003/04/13 04:25:36 sghosh
12 # update for check_mailq - qmail support
13 #
14 # Revision 1.6 2003/02/03 20:29:55 sghosh
15 # change ntpdc to ntpq (Jonathan Rozes,Thomas Schimpke, bug-656237 )
16 #
17 # Revision 1.5 2002/10/30 05:07:29 sghosh
18 # monitor mailq
19 #
20 # Revision 1.4 2002/05/27 02:01:09 sghosh
21 # new var - smbclient
22 #
23 # Revision 1.3 2002/05/10 03:49:22 sghosh
24 # added programs to autoconf
25 #
26 # Revision 1.2 2002/05/08 05:10:35 sghosh
27 # is_hostname added, update CODES to POSIX
28 #
29 #
30 package utils;
32 require Exporter;
33 @ISA = qw(Exporter);
34 @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
36 #use strict;
37 #use vars($TIMEOUT %ERRORS);
38 sub print_revision ($$);
39 sub usage;
40 sub support();
41 sub is_hostname;
43 ## updated by autoconf
44 $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
45 $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
46 $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
47 $PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
48 $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@";
50 ## common variables
51 $TIMEOUT = 15;
52 %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
54 ## utility subroutines
55 sub print_revision ($$) {
56 my $commandName = shift;
57 my $pluginRevision = shift;
58 $pluginRevision =~ s/^\$Revision: //;
59 $pluginRevision =~ s/ \$\s*$//;
60 print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
61 print "@WARRANTY@";
62 }
64 sub support () {
65 my $support='@SUPPORT@';
66 $support =~ s/@/\@/g;
67 $support =~ s/\\n/\n/g;
68 print $support;
69 }
71 sub usage {
72 my $format=shift;
73 printf($format,@_);
74 exit $ERRORS{'UNKNOWN'};
75 }
77 sub is_hostname {
78 my $host1 = shift;
79 if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)$/) {
80 return 1;
81 }else{
82 return 0;
83 }
84 }
86 1;