Nagios ignoring a variable in web interface


#1

Hello all. I am writing a Plugin to monitor AIX UNIX CPU Utilization. When I execute it interactively in a shell all is well, yet when Nagios runs it the variable is ignored. The following is the plugin:

#!/usr/bin/perl -w

use strict;
use warnings;
use Getopt::Long;
use Net::SSH qw(sshopen2);
use vars qw( $HOST $USER $TIME $CURRENT $WARN $CRITICAL @OUTPUT @TEMP $EXIT );

GetOptions(     "H=s"           => \$HOST,
                "U=s"           => \$USER,
                "W=i"           => \$WARN,
                "C=i"           => \$CRITICAL,
                "T=i"           => \$TIME);

&HELP unless ( ($HOST) && ($USER) && ($WARN) && ($CRITICAL) );

$TIME = "1" unless ($TIME);
sshopen2("$USER\@$HOST", *READER, *WRITER, "sar $TIME 1 |tail -1 |awk '{print \$5}'") || die "SSH: $!";
chomp(@OUTPUT = (<READER>));
close READER;
close WRITER;

$CURRENT = sprintf("%d",$OUTPUT[0]);
print $CURRENT,"\n"; ## <-------------------------------- This variable gets ignored by Nagios

sub HELP {

#######################################################################
        print qq^
Nagios - AIX 5.3 CPU Utilization Plugin v1.0

This plugin logs into a remote AIX system via SSH and runs the sar utility
to gather CPU utilization. It assumes that you have SSH public key
authentication setup between the monitoring server and the remote AIX server.

-H <HOSTNAME>           Hostname or IP Address *
-U <USERNAME>           Username *
-W <WARNING>            Percent Warning threshold *
-C <CRITICAL>           Percent Critical Threshold *
-T <TIME_INTERVAL>      How long to run sar in seconds ( default is 15 sec )

* Denotes required option

Sample:

$0 -H testaix.domain.com -U watcher -W 80 -C 95

The above will log into testaix.domain.com as user watcher and check current
CPU utilization via AIX sar utility. Once this value is gatehered this plugin
will send a warining (exit 1) if CPU is 80% utilized, and a critical
alert (exit 2) if 90%. If neither condition exist will set CPU as OK (exit 0)

^;
########################################################################

        exit;
}

Any suggestions would be greatly appreciated!!!