Page 1 of 2

Custom Plugin not returning output

Posted: Thu Jun 20, 2013 10:16 am
by mbowden
I am attempting to get a custom plugin that I pulled of github set up and working and seem to be running into some issues. The plugin basically hits a webpage from the nagios server logs in to cas and verify it gets a cas ticket back.

This was all created through Nagios XI 2012R1.8,

I downloaded and installed the plugin on my nagios server.
figured out how to run the plugin from the command line

# perl '/usr/local/nagios/libexec/check_cas.pl' -H prod-cas-vip.bowdoin.edu -p 443 -u "/cas-web/login" -r "Success"
# OK - CAS authentication successful

I defined a command

define command {
command_name check_cas.pl
command_line perl '$USER1$/check_cas.pl' -H $ARG1$ -p $ARG2$ -u $ARG3$ -r $ARG4$
}

Then Created a service

define service {
host_name prod-cas-vip.bowdoin.edu
service_description Confirms that a cas ticket can be obtained
use generic-service
display_name Check CAS
servicegroups Prod-CAS Group
check_command check_cas.pl!prod-cas-vip.bowdoin.edu!443!"/cas-web/login"!"Success"!!!!
max_check_attempts 5
check_interval 5
retry_interval 2
active_checks_enabled 1
check_period 24x7
notification_period 24x7
contacts mbowden
register 1
}
When I run the "Test Commmand" I get the following

COMMAND: perl '/usr/local/nagios/libexec/check_cas.pl' -H prod-cas-vip.bowdoin.edu -p 443 -u "/cas-web/login" -r "Success"
OUTPUT:

Yet if I run it from the command line on the nagios server it runs fine, returning the desired output.
any thoughts, on where I made my noob mistake this time :?

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 10:20 am
by abrist
The "test check command" in the XI ui has some escaping and permission restrictions due to security concerns. Is the check itself working?

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 10:30 am
by mbowden
The Status says (null)

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 11:21 am
by sreinhardt
When you are testing this via cli, are you running as nagios or root? Can you verify the nagios user has permission to exec this script? Also after execing via cli, what is the output of "echo $?"

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 11:23 am
by mbowden
The script runs successfully under nagios and root. The output of echo $? is 0

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 11:34 am
by sreinhardt
How about if you modify your script to start with "#! /bin/perl" then alter your command definition to be:

command_line $USER1$/check_cas.pl -H $ARG1$ -p $ARG2$ -u $ARG3$ -r $ARG4$

This way the script specifically designates what should be used to execute it, and avoid any confusion for nagios when executing perl with various arguments.

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 11:47 am
by mbowden
The script can be found here
https://github.com/petegallagher/nagios ... /check_cas

already has the following ;

#! /usr/bin/perl -w
# Prevent Nagios from using the Embedded Perl Interpreter for this module
# as per http://nagios.sourceforge.net/docs/3_0/ ... dperl.html
# nagios: -epn

without perl in the command it just kicks a pile of errors;

: command not foundibexec/check_cas.pl: line 1:
: command not foundibexec/check_cas.pl: line 3:
: command not foundibexec/check_cas.pl: line 7:
: command not foundibexec/check_cas.pl: line 20:
/usr/local/nagios/libexec/check_cas.pl: line 21: use: command not found
: command not foundibexec/check_cas.pl: line 21:
/usr/local/nagios/libexec/check_cas.pl: line 22: use: command not found
: command not foundibexec/check_cas.pl: line 22:
/usr/local/nagios/libexec/check_cas.pl: line 23: syntax error near unexpected token `('
'usr/local/nagios/libexec/check_cas.pl: line 23: `use Getopt::Long qw(:config no_ignore_case);

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 12:49 pm
by abrist
Make sure you give the full path to perl in the command definition, and make sure that nagios can run perl with the path.

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 1:38 pm
by mbowden
nagios can find perl
[nagios@host libexec]$ perl --help

Usage: perl [switches] [--] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)

new command def
define command {
command_name check_cas.pl
command_line /usr/bin/perl '$USER1$/check_cas.pl' -H $ARG1$ -p $ARG2$ -u $ARG3$ -r $ARG4$
}

same results as before

Re: Custom Plugin not returning output

Posted: Thu Jun 20, 2013 3:31 pm
by scottwilkerson
edit the script and change the following line

Code: Select all

use lib "/usr/lib/nagios/plugins";
to

Code: Select all

use lib "/usr/local/nagios/libexec";