How do I use the Nagios::Plugin perl module?
The Nagios::Plugin perl module can be obtained from two main locations:
- from the nagiosplug tarball with an extra configure option
- from CPAN
If you install from the nagiosplug tarball, the perl module will be installed in $prefix/perl.
If you install from CPAN, the perl module will be installed by default into your perl's system directories.
To write your plugin, you should start it with:
use FindBin;
use lib "$FindBin::Bin/../perl/lib";
use Nagios::Plugin;
This bit of code tells perl to look for the Nagios::Plugin module in a directory relative to where the plugin is executed - this is a hard dependency. If Nagios::Plugin is not found there, perl's system directories will be searched.
This approach allows a system administrator to decide whether they want Nagios::Plugin installed via system directories or within the $prefix area of the plugins.
- Printer-friendly version
- Login or register to post comments
Hello Plug-in Developers,
so far I haven't been using your Nagios::Plugin module for my own custom Perl plug-ins.
This wasn't necessary because my plug-ins were never intended for distribution.
However, I appreciate your efforts in providing us with a CPAN module to make it easier
for us non-developers to cling to the plug-in developer's guidelines.
Nevertheless, I find it a bit awkward that you advise the Perl plug-in authors to first pull in that FindBin module (which I have never used so far) just to grope around in the vicinity of the plug-in's location for possible non-standard Perl module locations.
Having configured my CPAN/Config.pm and being root on my hosts
I naturally prefer the perl -MCPAN 'install Nagios::Plugin way of installing Perl modules, no matter what various Linux distro's or Unices' package managers deem appropriate as installation target for various Perl modules.
Thus I would suggest to first try to load Nagios::Plugin and only if this fails
doing the poking with FindBin.
Of course one then cannot use the modules as this is already happening at compile time.
(sorry, preview shows that indentations get lost despite html tagging)
e.g.
#!/usr/bin/perl
use strict;
use warnings;
eval { require Nagios::Plugin && Nagios::Plugin->import };
if ($@) {
# assume a relatively recent Perl where FindBin is in core
no warnings;
require FindBin;
unshift @INC, map "$FindBin::Bin/$_",
qw(perl lib perl/lib ../perl ../lib ../perl/lib);
local $" = "\n\t";
eval {
require Nagios::Plugin && Nagios::Plugin->import
}
or die "Couldn't locate Nagios::Plugin in \n\t@INC\n";
}
Hi ragro,
The idea is that N::P could be in ../perl/lib, but if it isn't then the system directories would be used.
So just continue to install N::P on your systems in the standard perl directories and make sure ../perl/lib doesn't contain N::P and there should be no difference.
I fail to see how your suggestion is nicer: there is still a dependency on FindBin.
Ton