utils.pm and check_breeze.pl

Stanley Hopcroft Stanley.Hopcroft at IPAustralia.Gov.AU
Fri Aug 8 07:50:03 CEST 2003


Dear Sir,

I am writing to thank you for your letter and say,


> From: "Jamie Baddeley" <jamie.baddeley at vpc.co.nz>
> Subject: [Nagios-users] Utils.pm & Check Breeze.pl
> 
> Hi,
> 
> I'm hacking around with Check_breeze.pl to use it for an alternative
> smnpwalk based check.
> 
> I've made the changes, and it's bascially working but for some reason it's
> not using the %ERRORS part of the utils.pm module. I tried uncommenting "use
> vars($TIMEOUT %ERRORS);" from utils.pm in an effort to fix it, but this just
> produces:
> 
> Unquoted string "utils" may clash with future reserved word at ./check_cpus
> line 8.
> Unquoted string "pm" may clash with future reserved word at ./check_cpus
> line 8.

Sounds like the script contains 'use utils.pm;'.
Should be 'use utils;'

> Operator or semicolon missing before %ERRORS at
> /usr/lib/nagios/plugins/utils.pm line 28.
> Ambiguous use of % resolved as operator % at
> /usr/lib/nagios/plugins/utils.pm line 28.
> Argument "ERRORS" isn't numeric in modulus (%) at
> /usr/lib/nagios/plugins/utils.pm line 28.
> Use of uninitialized value in modulus (%) at
> /usr/lib/nagios/plugins/utils.pm line 28.
> Illegal modulus zero at /usr/lib/nagios/plugins/utils.pm line 28.
> BEGIN failed--compilation aborted at /usr/lib/nagios/plugins/utils.pm line
> 28.
> Compilation failed in require at ./check_cpus line 9.
> BEGIN failed--compilation aborted at ./check_cpus line 9.
> 
> when I run my hacked script.
> 
> 
> Is there a good reason why "use vars..." line is commented out?

> How does one make it so the %ERRORS part of utils.pm can be called by
> another perl script?

1 Tell Perl where to load utils.pm from if it's not in the standard 
paths (eg perl -e 'print "@INC\n"' will let you know where it will 
look).

This is what the 'use lib' pragma is for.

2 Tell Perl what to import into your script with use util qw (%ERRORS 
usage).

Here's a working example

use strict ;

use Getopt::Long ;
use Samba ;
use utils ;

use vars qw($opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $debug);
use vars '$AUTOLOAD' ;
use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);

my $PROGNAME = 'check_ms_spooler' ;

The 'use vars' pragma is only used where you want global variables (ie 
not lexicals/those declared with my or our) _and_ you want 'use strict' 
to have the compiler complain before you apply chainsaw to flesh and 
blood.

In the example above, I would/have replaced the 'use vars' with 

my ($opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $debug);

HTH

Yours sincerely.
> 

-- 
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------

'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'

from Meditation 17, J Donne.


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list