Custom Nagios plugin


#1

Hi all,
I just wrote a script to check the monitor of my cgi scripts and integrate it into nagios so that it can notify me when error occurs.

The problem is that when I run it on the command line it works perfectly but in nagios it gives a “No Output error” what am I doing wrong?

Here is a copy of the script and the nagios config below:

SCRIPT:

#!/usr/bin/perl

use strict;

########## Configure Section ############
my $url = $ARGV[0];
my $warning = $ARGV[1];
my $critical = $ARGV[2];
my $wget = wget -nv --spider -o output.nagios $url -$warning -$critical;
my $output_file = “output.nagios”;

######## Program Section #############
open(DAT, $output_file) || die (“Could not open file!”);
my @output = ;
close(DAT);

if (my @ok = grep(/OK/,@output)) {
print “HTTP: @ok\n”;
exit 0;
}

if ($critical == 1){
my @critical = grep(/ERROR/,@output);
print “CRITICAL: HTTP: @critical\n”;
exit 1;
}# end if

print “Warning: @output\n”;

NAGIOS config:
SERVICE:
#########################################################

Checking URL

########################################################

define service{
host_name url.com
service_description check-url
check_command check_url.pl!URL!1
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
}
##########################################################

CHECKCOMMAND:

check_url command definition

define command{
command_name check_url
command_line $USER1$/check_url.pl $HOSTADDRESS$ $ARG1$ $ARG2$
}

Thank you for your help.


#2

try to run it as user nagios, instead of root, on the command line.


#3

Hi Jake,
thanks for your reply, I’m actually running it as nagios and still getting the same result.


#4

Check the permissions on the file. Is it the same as the others in $USER1$ ???


#5

yes it has the same permission with $USER1$ here is a copy of some of the plugins with their permission the check_url.pl is the one with the ***

lrwxrwxrwx 1 nagios nagios 9 Nov 9 16:11 check_udp2 -> check_tcp
-rwxr-xr-x 1 nagios nagios 46451 Nov 9 16:11 check_ups
-rwxr-xr-x 1 nagios nagios 1697 Mar 2 19:46 check_url.pl ***
-rwxr-xr-x 1 nagios nagios 35218 Nov 9 16:11 check_users
-rwxr-xr-x 1 nagios nagios 3024 Nov 9 16:11 check_wave


#6

It needs to output the numeric code for “warning”, “critical”, etc. Nagios doesn’t recognize the string “WARNING” as the warning code.


#7

Use check_url_status , refer nagiosexchange.org/cgi-bin/p … 6.html;d=1