[Nagiosplug-devel] Nagios plugin "No Output" error
Pio Niyi
piouso at gmail.com
Tue Mar 7 03:41:02 CET 2006
Hi All,
I wrote a plugin that uses wget to check if my cgi-scripts are working
properly. The plugin works well on command line but it displays "No output"
in Nagios web page.Here is a copy of the script and the service file and
check command:
################## START PROGRAM #########################
#!/usr/bin/perl
use strict;
use Getopt::Long;
use vars qw($opt_h $opt_w $opt_c);
use lib "/usr/local/nagios/libexec";
use utils qw(%ERRORS &print_revision &support &usage);
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h, "w=s" => \$opt_w, "warning=s" =>
\$opt_w, "c=s" => \$opt_c, "critical=s" => \$opt_c);
my $PROGNAME = "check_url";
my $REVISION = '$Revision: 1.1 $';
$ENV{'PATH'}='/usr/bin/';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
########## Configure Section ############
my $url = $ARGV[0];
my $warning = $ARGV[1];
my $critical = $ARGV[2];
my $wget = `wget -nv --spider -o output.nagios $url`;
my $output_file = "output.nagios";
######## Program Section #############
open(DAT, $output_file) || die ("Could not open file!");
my @output = <DAT>;
close(DAT);
#($opt_u) || usage("URL not specified\n");
#my $opt_u = $url;
#$url) || usage("Invalid url: $opt_u\n");
($opt_w) || usage("warning threshold not specified\n");
my $warn = $1 if ($opt_w =~ /(\d{1,2})/);
($opt_c) || usage("Critical threshold not specified\n");
my $crit = $1 if ($opt_c =~ /(\d{1,2})/);
print "HTTP: $url: @output\n";
if ($warning <= 2) {
(my @warning = grep(/Authorization Required/, at output));
exit $ERRORS{'WARNING'};
}
if ($critical <= 3) {
(my @critical = grep(/ERROR/, at output));
exit $ERRORS{'CRITICAL'}
}
exit $ERRORS{'OK'} if (my @ok = grep(/OK/, at output));
sub print_usage () {
print "Usage: $PROGNAME -c <crit>\n";
}
sub print_help () {
print_revision($PROGNAME, $REVISION);
print "Copyright (c) 2006 Pius Oshinuga
######## Help Section ##################
if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
This plugin reports the script errors using the wget package.";
print_usage();
print "
-w, --warning=INTEGER
If site cannot be found or Authority required which a WARNING status will
result
-c, --critical=INTEGER
If Error occurs which a CRITICAL status will result
";
}
################### END PROGRAM ######################
#########################################################
# Checking URL
########################################################
define service{
host_name hostname.com
service_description check-url
check_command check_url!hostname.com/script.cgi!1!2
max_check_attempts 5
normal_check_interval 5
retry_check_interval 3
check_period 24x7
notification_interval 0
notification_period 24x7
notification_options c,r
contact_groups web-admins
}
##########################################################
###### Check command ########################
# check_url command definition
define command{
command_name check_url
command_line $USER1$/check_url -u $HOSTADDRESS$ -c $ARG1$
}
Thank you for your envisaged help
--
"I might be a slow walker but I never walk backwards"
-Johnny Walker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nagios-plugins.org/archive/devel/attachments/20060307/48b849dc/attachment.html>
More information about the Devel
mailing list