From a9a62a4c646acac9a2db826c529efcc599786a93 Mon Sep 17 00:00:00 2001
From: Jan Wagner <waja@cyconet.org>
Date: Mon, 29 May 2017 12:37:12 +0200
Subject: [PATCH] Adding support for Monitoring::Plugin

---
 check_apache_balancer_members.pl | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

--- a/check_apache_balancer_members/check_apache_balancer_members
+++ b/check_apache_balancer_members/check_apache_balancer_members
@@ -4,9 +4,30 @@
 use LWP::Simple;
 use Data::Dump qw(dump);    #libdata-dump-perl
 use Web::Scraper;           #libweb-scraper-perl
-use Monitoring::Plugin;	    #libmonitoring-plugin-perl
 
-my $np = Monitoring::Plugin->new(
+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
+
+my $np = $plugin_module->new(
     usage => '',
     plugin => $0,
     shortname => "Balancer Members",
