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
Problem returning data from Perl Check script
Problem returning data from Perl Check script
- Attachments
-
check_tempr.pl- The check_temp.pl script
- (1.92 KiB) Downloaded 373 times
Re: Problem returning data from Perl Check script
Are you doing your command line tests as the nagios user?
If you are root, something like this:and
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?)
If you are root, something like this:
Code: Select all
su - nagios -s /bin/bash -c "/usr/local/nagtemp/grabtemp.sh"
Code: Select all
su - nagios -s /bin/bash -c "/usr/local/nagtemp/check_tempr.pl -w 20 -c 25"
(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?)
Re: Problem returning data from Perl Check script
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.millisa wrote:Are you doing your command line tests as the nagios user?
Thanks again,
John
- 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
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:
For example with the top command:
Code: Select all
top -n 1 -bAs of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Problem returning data from Perl Check script
You gave me the pointer (and properly formed test statements) I needed! Thanks very much. It is working now.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).
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.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?)
Thanks again!
John