diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:48:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:48:22 +0000 |
commit | 7373ce3d6988706388f136e1c06afd20a3e8d5be (patch) | |
tree | e9ae5af7d102667e5706187646db45de8238e8c4 /plugins-scripts/utils.pm.in | |
parent | Initial commit. (diff) | |
download | monitoring-plugins-upstream.tar.xz monitoring-plugins-upstream.zip |
Adding upstream version 2.3.5.upstream/2.3.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins-scripts/utils.pm.in')
-rw-r--r-- | plugins-scripts/utils.pm.in | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/plugins-scripts/utils.pm.in b/plugins-scripts/utils.pm.in new file mode 100644 index 0000000..c84769f --- /dev/null +++ b/plugins-scripts/utils.pm.in @@ -0,0 +1,69 @@ +# Utility drawer for Monitoring Plugins. +# +# This will be deprecated soon. Please use Monitoring::Plugin from CPAN +# 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 +$PATH_TO_SUDO = "@PATH_TO_SUDO@"; +$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@"; +$PATH_TO_SNMPGET = "@PATH_TO_SNMPGET@"; + +## 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; + print "$commandName v$pluginRevision (@PACKAGE@ @VERSION@)\n"; + 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; + } + } elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]*(\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\.?$/) { + return 1; + } else { + return 0; + } +} + +1; |