[Nagiosplug-help] utils.pm and %EXPORT_OK

Ralph.Grothe at itdz-berlin.de Ralph.Grothe at itdz-berlin.de
Mon Jul 4 04:01:43 CEST 2005


Hi,

I just started with Nagios and am currently about to script my
own plugins.

Before starting I read the Nagios plug-in development guidelines.

For Perl plugins they strongly recommend making use of utils.pm

Since I want to cling to Nagios plugin standards I am importing
utils.pm and
try to make use of the therein predefined variables and
functions.

There is however one (probably later added sub) that didn't make
it into the %EXPORT_OK
hash for (very crude) checking of a valid hostname.

Well, I could easily put &is_hostname in the EXPORT_OK list
but that I think would break the designed interface.

That's why I simply aliased this subname (see no strict refs
block below).
However, I feel this is an ugly cludge, fumbling with the global
symbol table.
I think to also have read in the Nagios doc somewhere where they
talk about embedded Perl
that one must not make use of package globals (similar to
mod_perl in Apache I guess).

What are the official guidelines to handle this?

Here the beginning of my sample plugin

$ head -36 check_perl_ping.pl
#!/usr/bin/perl -w

use strict;

use lib "$ENV{HOME}/libexec";

use utils qw(%ERRORS $TIMEOUT &print_revision &usage);
use Carp;
use Getopt::Long;
use Net::Ping;

# alias cludge as long as is_hostname() isn't in %EXPORT_OK of
utils.pm
{ no strict 'refs'; *is_hostname = *utils::is_hostname }

my ($plugin) = (split /\//, $0)[-1];
my $usage_fmt = 'usage: %s [-h]|[-v[v[v]]][-p port][-w
warn_thresh][-c crit_thresh][-i nic]'
                ."[-t icmp|udp|tcp]{-H node}\n";
my $transport = 'tcp';
my ($hostname, $proto, $port, $help, $verbose, $critical,
$warning, $nic_ppa);
my @seen_nics = ();

GetOptions( 
            'verbose|v+'        => \$verbose,
            'help|h'            => \$help,
            'hostname|H=s'      => \$hostname,
            'port|p=s'          => \$port,
            'critical|c=s'      => \$critical,
            'warning|w=s'       => \$warning,
            'interface|i=s'     => \$nic_ppa,
            'transport|t=s'     => \$transport,
          );

unless ($hostname and is_hostname($hostname)) {
    carp "Hostname missing or containing non-valid chars";
    usage($usage_fmt, $plugin);
}

 




More information about the Help mailing list