On Fri, Sep 08, 2017 at 02:24:54PM +0200, Sven Nierlein wrote:
> Hi,
> 
> you could use Module::Load (which is a perl core module) to do that:
> 
> use Module::Load qw/load/;
> eval {
>   load Monitoring::Plugin, qw/required exports/;
> };
> if($@) {
>   load Nagios::Plugin, qw/required exports/;
> }

This fails for me - Testcase:

#!/usr/bin/perl -w

use strict;
use Getopt::Long;

use Module::Load qw/autoload/;
my $module="Nagios::Plugin";
eval {
        require Nagios::Plugin;
        1;
} or do {
        $module="Monitoring::Plugin";
};

autoload $module;
my $np=new $module;

$np->nagios_exit(UNKNOWN, "Unknown");

Returns:

Bareword "UNKNOWN" not allowed while "strict subs" in use at /tmp/f line 18.

$ERRORS{UNKNOWN} is equally not imported. Using qw/UNKNOWN/ with load or 
autoload does not
change anything.

> Or just stay with Nagios::Plugin till the old systems fade out. You can use
> Monitoring::Plugin by the name "Nagios::Plugin" as well. It comes
> with a compatibility module.

The problem here is that Debian/Stretch does not seem to ship it - 

flo@p3:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 9.1 (stretch)
Release:        9.1
Codename:       stretch
flo@p3:~$ dpkg -l libmonitoring-plugin-perl
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                         Version             Architecture        
Description
+++-============================-===================-===================-=============================================================
ii  libmonitoring-plugin-perl    0.39-1              all                 family 
of perl modules to streamline writing Monitoring plugi
flo@p3:~$ perl -MNagios::Plugin 
Can't locate Nagios/Plugin.pm in @INC (you may need to install the 
Nagios::Plugin module) (@INC contains: /etc/perl 
/usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 
/usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 
/usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 
/usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base).
BEGIN failed--compilation aborted.


Flo
-- 
Florian Lohoff                                                 f...@zz.de
             UTF-8 Test: The 🐈 ran after a 🐁, but the 🐁 ran away

Attachment: signature.asc
Description: Digital signature

Reply via email to