check_bgp.0.4.pl : Works at command line but not within Nag

Hello, it is my first post here.

So, I installed the check_bgp pluggin that I found on NagiosExchange and it is working fine from the command line. example:

nagios@Jules-Verne:/usr/local/nagios/libexec$ ./check_bgp.0.4.pl -H 10.10.10.5 -C public -p 10.10.10.50
OK - 10.10.10.50 (AS6452) state is established(6). Established for 16d4h15m58s. Last error “Hold Timer Expired”.

But when I try to use it from within Nagios, It always return a (null) value and a critical status.

define command{
command_name check_bgp
command_line $USER1$/check_bgp.0.4.pl -H $HOSTADDRESS$ -C public -p $ARG1$
}

define service{
use generic-service
host_name Cisco6509
service_description BGP CHECK2
check_command check_bgp!10.10.10.50
max_check_attempts 2
normal_check_interval 2
retry_check_interval 2
check_period 24x7
}

I am begining to suspect that this particular Perl script might just not work with Nagios 3.0.3

Can anyone help? Or suggest another option for checking BGP peering on a Cisco router?

Thanks a lot for any help/hints as it is appreciated.

Hello :slight_smile:

I assume that you modified the script to change the “use lib” line, so that it points to the path where your libraries are.
In that case: did you use a full path (/my/path/lib) or a relative path (…/my_libs) ?
If you used a relative path: here is your error :slight_smile:

if not … well, I don’t know ^^ but you can try to troubleshoot the problem by loging at different stages the variables of the script (log them in a file; you’ll see what nagios is doing)

Thanks a lot for the answer.

Right now, I have :

use lib “/usr/lib/nagios/plugins” ;

And no, I haven’t changed anything since it was working from the command line.

"you can try to troubleshoot the problem by loging at different stages the variables of the script (log them in a file; you’ll see what nagios is doing)"
So… :cry: how would one log what nagios is doing to a file?

I am still learning my way around… so thanks for any help.

place this line after a few lines of the perl script: (I’m assuming you know a little bit about perl^^)
open(OUT,">>/var/temp/plugin.log");

then, at some points, just type:
print OUT $variable_I_want_to_test

and, at the end of the script:
close(OUT);

wait for nagios to launch the plugin and read the log file :slight_smile:

Ok,

Sorry for the delay, I wanted to make sure I had everything I can think of covered.

Here’s what I found.

I liberally used the logging capacity with Print OUT whatever from inside the perl pluggin… and it worked well.
When I use the command from the command line I get a perfect trace in plugging.log. Everything is working fine!

For example: (From the file pluggin.log)
hostname:x.x.91.254bgppeer:x.xx.91.zz community:Publicresult:HASH(0x8619180)output:xx.xx.91.zz (ASxx312) state is established(6)state:oKOutput:xx.xx.91.zz (ASxx312) state is established(6). Established for 2d4h38m47s. Last error “Hold Timer Expired”.

Next I enabled Nagios logging facility by changing the flag in Nagios.cfg and also enabling the highest level of verbose output. 2 I think.

However, when Nagios is using the script, nothing happen in the pluggin.log file and I still get (null) as the only thing that is returned.

But from nagios log file, I can see that at least the macro containing the string to call: check_bgp.0.4.pl is being started.
Presumably, this macro is to replace all the variable such as $USER1$ and $HOSTADDRESS$ and form a complete command.
As far as I can tell, the complete command is looking good. See final output in bold…
And further down, I see something similar happening with other simple command such as check_ping.

**** BEGIN MACRO PROCESSING ***********
Processing: '$USER1$/check_bgp.0.4.pl -H $HOSTADDRESS$ -C public -p xx.xx.91.50’
Processing part: ''
Not currently in macro. Running output (0): ''
Processing part: 'USER1’
Processed ‘USER1’, Clean Options: 0, Free: 0
Processed ‘USER1’, Clean Options: 0, Free: 0
Cleaning options: global=0, local=0, effective=0
Uncleaned macro. Running output (25): '/usr/local/nagios/libexec’
Just finished macro. Running output (25): '/usr/local/nagios/libexec’
Processing part: '/check_bgp.0.4.pl -H '
Not currently in macro. Running output (46): '/usr/local/nagios/libexec/check_bgp.0.4.pl -H '
Processing part: 'HOSTADDRESS’
macro_x[2] (HOSTADDRESS) match.
Processed ‘HOSTADDRESS’, Clean Options: 0, Free: 1
Processed ‘HOSTADDRESS’, Clean Options: 0, Free: 1
Cleaning options: global=0, local=0, effective=0
Uncleaned macro. Running output (59): '/usr/local/nagios/libexec/check_bgp.0.4.pl -H xx.xx.91.254’
Just finished macro. Running output (59): '/usr/local/nagios/libexec/check_bgp.0.4.pl -H xx.xx.91.254’
Processing part: ’ -C public -p 206.75.91.50’
Not currently in macro. Running output (85): '/usr/local/nagios/libexec/check_bgp.0.4.pl -H xx.xx.91.254 -C public -p xx.xx.91.zz’
Done. Final output: ‘/usr/local/nagios/libexec/check_bgp.0.4.pl -H xx.xx.91.254 -C public -p xx.xx.91.zz’
**** END MACRO PROCESSING *************

So, again, when Nagios call the pluggin, nothing is added in the pluggin.log, where I liberally dump some variable values.

This is weird. there’s got to be something simple I did not see. Either Nagios is simply not calling the pluggin, (I checked the file permissions and it looks fine) or it crash so early in the pluggin that indeed, nothing is returned.

When adding a perl pluggin, is there anything else to do? (According to the doc, you put the .pl file in /usr/local/nagios/libexec/ and change your config file to use it.)

Any idea??

Thanks a lot!!!

I’m impressed :slight_smile:
you did a great job looking for all this!

but it still doesn’t work :confused:

From what you’ve put here, I can’t see anything wrong.
I’ve read again the script, and all I can think of going wrong are the libs that may not be found (then again, I’m just guessing).

So, the thing you could try:
create a small perl script like that:

[code]#!/usr/bin/perl

my $log_file = “path_to_logfile”;

open(OUT,">>".$log_file);
my @result = /usr/local/nagios/libexec/check_bgp.0.4.pl -H 10.10.10.5 -C public -p 10.10.10.50 2>&1;

print OUT @result;

close(OUT);[/code]

(I just wrote it now, without testing it, so you may have to correct a few typos :))
Anyway, the goal is to get put the “2>&1” somewhere in the command line (you can try to put it directly in the command line definition; it may work, I don’t know :)), so that the error output is redirected to the standard output AND it is logged in the log file.

=> I hope the intention is clear enough and that may help you ^^

Finally! I found the problem and you were right from the start.

Your last reply was instrumental in getting the real output from the perl script and it was indeed complaining about the library.

(That said, I don’t know why I was able to run it from the command line from the start. with the same nagios user.)

anyway, after getting this message, I realized that the library was not right.

I had :usr/lib/nagios/libexec
and it should have been: usr/local/nagios/libexec

And so now, everything is working fine.
Thanks a lot!

Next time, I will know how to troubleshoot pluggin…

That’s the best part :slight_smile: (and the even better part, is that using this way applies to pretty much everything ^^ I do it when I code php, perl, vbs …etc)