check_sieve: Add support to detect perl monitoring and nagios plugins

This commit is contained in:
Jan Wagner 2017-07-09 17:29:17 +02:00
parent ba39a8dcef
commit 5b545ac648
3 changed files with 44 additions and 1 deletions

View file

@ -1,6 +1,6 @@
Homepage: https://raw.githubusercontent.com/alan-hicks/check_sieve/master/check_sieve.pl
Watch: https://raw.githubusercontent.com/alan-hicks/check_sieve/master/check_sieve.pl \$VERSION\ =\ '([0-9.]+)'
Recommends: libio-socket-inet6-perl, monitoring-plugins-common | nagios-plugins-common
Recommends: libio-socket-inet6-perl, libmonitoring-plugin-perl | libmonitoring-plugin-perl
Version: 1.02
Uploaders: Jan Wagner <waja@cyconet.org>
Description: plugin checking for a running Sieve daemon

View file

@ -0,0 +1,42 @@
--- a/check_sieve/check_sieve
+++ b/check_sieve/check_sieve
@@ -36,7 +36,6 @@
use warnings;
use IO::Socket::INET6;
use Time::HiRes;
-use Nagios::Plugin;
use vars qw($VERSION $PROGNAME);
use vars qw($start $duration $sock $family $code $line $implementation);
@@ -48,8 +47,30 @@
$PROGNAME = basename($0);
+sub load_module {
+ my @names = @_;
+ my $module;
+ for my $name (@names) {
+ my $file = $name;
+ # requires need either a bare word or a file name
+ $file =~ s{::}{/}gsxm;
+ $file .= '.pm';
+ eval {
+ require $file;
+ $name->import();
+ $module = $name;
+ };
+ last if $module;
+ }
+ return $module;
+}
+
+my $plugin_module;
+
+$plugin_module = load_module( 'Monitoring::Plugin', 'Nagios::Plugin' ); #libmonitoring-plugin-perl or libnagios-plugin-perl
+
# Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory)
-my $p = Nagios::Plugin->new(
+my $p = $plugin_module->new(
usage => "Usage: %s
[ -v|--verbose ]
[ -H|--host <host>]

View file

@ -6,5 +6,6 @@ check_ipsec/20_remove_gateway
check_mysql_slave//epn
check_sieve/epn
check_sieve/10_pathes
check_sieve/MonitoringPlugin
check_tftp/epn
check_tomcat/epn