Custom Plugin not returning output

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
mbowden
Posts: 93
Joined: Thu May 03, 2012 3:52 pm

Custom Plugin not returning output

Post 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 :?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Custom Plugin not returning output

Post 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?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
mbowden
Posts: 93
Joined: Thu May 03, 2012 3:52 pm

Re: Custom Plugin not returning output

Post by mbowden »

The Status says (null)
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Custom Plugin not returning output

Post 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 $?"
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
mbowden
Posts: 93
Joined: Thu May 03, 2012 3:52 pm

Re: Custom Plugin not returning output

Post by mbowden »

The script runs successfully under nagios and root. The output of echo $? is 0
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Custom Plugin not returning output

Post 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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
mbowden
Posts: 93
Joined: Thu May 03, 2012 3:52 pm

Re: Custom Plugin not returning output

Post 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);
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Custom Plugin not returning output

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
mbowden
Posts: 93
Joined: Thu May 03, 2012 3:52 pm

Re: Custom Plugin not returning output

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Custom Plugin not returning output

Post 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";
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked