pkg-monitoring-plugins/plugins-scripts/utils.pm.in

70 lines
1.5 KiB
Perl
Raw Permalink Normal View History

2014-07-11 19:01:00 +00:00
# Utility drawer for Monitoring Plugins.
2013-11-26 22:53:19 +00:00
#
2014-07-11 19:01:00 +00:00
# This will be deprecated soon. Please use Monitoring::Plugin from CPAN
2013-11-26 22:53:19 +00:00
# for new plugins
package utils;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
#use strict;
#use vars($TIMEOUT %ERRORS);
sub print_revision ($$);
sub usage;
sub support();
sub is_hostname;
## updated by autoconf
2016-11-30 11:36:55 +00:00
$PATH_TO_SUDO = "@PATH_TO_SUDO@";
2013-11-26 22:53:19 +00:00
$PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
$PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
$PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
$PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@";
2023-10-18 07:29:37 +00:00
$PATH_TO_SNMPGET = "@PATH_TO_SNMPGET@";
2013-11-26 22:53:19 +00:00
## common variables
$TIMEOUT = 15;
%ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
## utility subroutines
sub print_revision ($$) {
my $commandName = shift;
my $pluginRevision = shift;
2013-11-26 22:54:42 +00:00
print "$commandName v$pluginRevision (@PACKAGE@ @VERSION@)\n";
2013-11-26 22:53:19 +00:00
print "@WARRANTY@";
}
sub support () {
my $support='@SUPPORT@';
$support =~ s/@/\@/g;
$support =~ s/\\n/\n/g;
print $support;
}
sub usage {
my $format=shift;
printf($format,@_);
exit $ERRORS{'UNKNOWN'};
}
sub is_hostname {
my $host1 = shift;
return 0 unless defined $host1;
if ($host1 =~ m/^[\d\.]+$/ && $host1 !~ /\.$/) {
if ($host1 =~ m/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
return 1;
} else {
return 0;
}
2013-11-26 22:53:44 +00:00
} elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]*(\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\.?$/) {
2013-11-26 22:53:19 +00:00
return 1;
} else {
return 0;
}
}
1;