-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Try this one:
#!/usr/bin/perl use strict; use warnings; my $mod; BEGIN { for my $try (qw/Nagios::Plugin Monitoring::Plugin/) { eval "use $try"; if(!$@) { $mod = $try; last; } } }; my $np = $mod->new(); $np->nagios_exit(UNKNOWN, "Unknown"); On 08.09.2017 15:16, Florian Lohoff wrote: > 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 > - -- Sven Nierlein sven.nierl...@consol.de ConSol* GmbH http://www.consol.de Franziskanerstrasse 38 Tel.:089/45841-439 81669 Muenchen Fax.:089/45841-111 -----BEGIN PGP SIGNATURE----- iLMEAQEIAB0WIQTy+Xc3tZrMySwj+Mf4wcoIpXue1wUCWbKbsQAKCRD4wcoIpXue 11v3A/9CvwAEtMew7Vt8rZpAZ/prsE+SgAs7zWFno7pcJIQ5ovXzIxbxRgLll/gj WjbEXVuJkSI5oLse1Ez+9CTznxm4R1iHqCWyxU8dxm3STH/h/uYeSAkr6rBAEH4d mJeAHIO+jAf7HZzIxjUAHFF0Aeij8fKC3W1m+JtjssTAKxtt3A== =NkAX -----END PGP SIGNATURE-----