Problem returning data from Perl Check script

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
JohnO
Posts: 6
Joined: Thu Dec 26, 2013 1:21 pm

Problem returning data from Perl Check script

Post by JohnO »

Greetings,

I'm having trouble displaying data in Nagios Core 3.5.1 that should be returned from a Perl "Check" script.

The script is a modified version of this script: http://exchange.nagios.org/directory/Pl ... mp/details

Instead of communicating with the USB port from within the script, I'm calling a shell script that executes a C program that returns a temperature.

The Request process looks something like this:

Nagios (localhost.cfg) --> check_tempr.pl --> grabtemp.sh --> pcsensor (executable)

When I run grabtemp.sh from the commandline, I get the expected result (a temperature in the form 23.33).

When I run the check_tempr.pl script from the commandline I also get the expected data.

When I look at the data in Nagios, I get formatted data returned from the check_tempr.pl script without the actual numeric temperature data.

From check_tempr.pl, I'm calling the shell script using the back quote method, which I understand to be correct. Am I missing something about calling a shell script if my intent is to pass data up yet another level to Nagios?

Here is how I'm calling the shell script from the Perl script:
$tempRead = `/usr/local/nagtemp/grabtemp.sh`;

Any ideas? What other information can I provide?

Thanks very much,

John
Attachments
check_tempr.pl
The check_temp.pl script
(1.92 KiB) Downloaded 372 times
User avatar
millisa
Posts: 69
Joined: Thu Jan 16, 2014 11:13 pm
Location: Austin, TX
Contact:

Re: Problem returning data from Perl Check script

Post by millisa »

Are you doing your command line tests as the nagios user?
If you are root, something like this:

Code: Select all

su - nagios -s /bin/bash -c "/usr/local/nagtemp/grabtemp.sh"
and

Code: Select all

su - nagios -s /bin/bash -c "/usr/local/nagtemp/check_tempr.pl -w 20 -c 25"
I'm willing to wager you are running your tests as root which is working and it's more a permission issue when running the shell script as the nagios user (which depending on the contents of that shell script could have different ways of being addressed).

(the shell script sure seems like an unnecessary additional step, do you intend to eventually move whatever that is doing into the perl script in the getTemp sub?)
JohnO
Posts: 6
Joined: Thu Dec 26, 2013 1:21 pm

Re: Problem returning data from Perl Check script

Post by JohnO »

millisa wrote:Are you doing your command line tests as the nagios user?
I hadn't been. I think you are on the right track. Two of the commands in the script need to be executed with root privileges. I also can pull all three items from the shell script up into the Perl script, which should also simplify things. Thanks for the pointer. I'll report back with either success, or perhaps another question.

Thanks again,

John
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Problem returning data from Perl Check script

Post by Box293 »

Following on from what millisa said, some commands also need a flag provided to be allowed to run as a batch job.

For example with the top command:

Code: Select all

top -n 1 -b
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
JohnO
Posts: 6
Joined: Thu Dec 26, 2013 1:21 pm

Re: Problem returning data from Perl Check script

Post by JohnO »

millisa wrote: I'm willing to wager you are running your tests as root which is working and it's more a permission issue when running the shell script as the nagios user (which depending on the contents of that shell script could have different ways of being addressed).
You gave me the pointer (and properly formed test statements) I needed! Thanks very much. It is working now.
millisa wrote: (the shell script sure seems like an unnecessary additional step, do you intend to eventually move whatever that is doing into the perl script in the getTemp sub?)
I do. I was working backwards by getting the temperature probe working first, which also needed a couple of files written/rewritten, so those three commands were in the shell script. When I went looking for a good way to tie this into Nagios without re-inventing the wheel, I came across the script I linked above, and just swapped out the original bits for that vendor probe for my existing shell script.

Thanks again!

John
Locked