Merge pull request #2032 from RincewindsHat/cleanup/check_apt
[monitoring-plugins.git] / plugins-scripts / utils.pm.in
blobc84769fb083ef39946af0759f0dc777008d58705
1 # Utility drawer for Monitoring Plugins.
3 # This will be deprecated soon. Please use Monitoring::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_SUDO = "@PATH_TO_SUDO@";
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@";
26 $PATH_TO_SNMPGET = "@PATH_TO_SNMPGET@";
28 ## common variables
29 $TIMEOUT = 15;
30 %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
32 ## utility subroutines
33 sub print_revision ($$) {
34 my $commandName = shift;
35 my $pluginRevision = shift;
36 print "$commandName v$pluginRevision (@PACKAGE@ @VERSION@)\n";
37 print "@WARRANTY@";
40 sub support () {
41 my $support='@SUPPORT@';
42 $support =~ s/@/\@/g;
43 $support =~ s/\\n/\n/g;
44 print $support;
47 sub usage {
48 my $format=shift;
49 printf($format,@_);
50 exit $ERRORS{'UNKNOWN'};
53 sub is_hostname {
54 my $host1 = shift;
55 return 0 unless defined $host1;
56 if ($host1 =~ m/^[\d\.]+$/ && $host1 !~ /\.$/) {
57 if ($host1 =~ m/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
58 return 1;
59 } else {
60 return 0;
62 } elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]*(\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\.?$/) {
63 return 1;
64 } else {
65 return 0;