Nagios XI Version : 2014R2.7
pmonnag001.ops.cin.mp-emaxx.com 2.6.18-400.1.1.el5 x86_64
Red Hat Enterprise Linux Server release 5.11 (Tikanga)
Gnome is not installed
Proxy appears to be in use
The below shell script outputs the following correct results when executed from the nagios server command line.
[root@pmonnag001 ramcmon]# ./both.sh
OK: RamCache Verify: 1234 assets verified
When using the "Test Check Command" in the nagiox XI GUI, it gives the following output. Any ideas as to what I'm doing wrong?
COMMAND: /usr/local/nagios/libexec/ramcmon/both.sh -I pmonnag001
OUTPUT:
#!/bin/bash
#set -x
#./update.sh > update.out 2>&1
#./verify.sh > verify.out 2>&1
monitor_file=/usr/local/nagios/libexec/ramcmon/monitor.out
status=`sed -n 1p $monitor_file`
#status=green
message=`sed '1 d' $monitor_file`
#message='RamCache Verify: 1234 assets verified'
function ok_status
{
echo "OK: $message"
exit 0
}
function critical_status
{
echo "CRITICAL: $message"
exit 2
}
function warning_status
{
echo "WARNING: $message"
exit 1
}
if [ $status == 'red' ]
then
critical_status
elif [ $status == 'yellow' ]
then
warning_status
elif [ $status == 'green' ]
then
ok_status
fi
different results when running script
Re: different results when running script
Can you post your both.sh script so we can review it?
Some commands don't work when using the Test button, does it show correct status on the Service Details screen?
Some commands don't work when using the Test button, does it show correct status on the Service Details screen?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: different results when running script
I included the both.sh script in my original post.
I checked the service details screen and it does show the correct status.
Is there a list of the commands that don't work with the Test button?
I checked the service details screen and it does show the correct status.
Is there a list of the commands that don't work with the Test button?
Re: different results when running script
What are the permissions of /usr/local/nagios/libexec/ramcmon/both.sh?
Also - to clarify, ultimately, what do you want this script to do? You should be able to run everything through an if, rather then creating functions and doubling the work up.
Also - to clarify, ultimately, what do you want this script to do? You should be able to run everything through an if, rather then creating functions and doubling the work up.
Former Nagios Employee
Re: different results when running script
[nagios@pmonnag001 libexec]$ ls -l /usr/local/nagios/libexec/ramcmon/both.sh
-rwxr-xr-x 1 nagios users 546 Mar 1 20:51 /usr/local/nagios/libexec/ramcmon/both.sh
I want the script to get the status and the message from the monitor file and then output a message based on the status.
You make a good point about the functions so I removed those and doing everything through an if.
#!/bin/bash
#set -x
#./update.sh > update.out 2>&1
#./verify.sh > verify.out 2>&1
monitor_file=/usr/local/nagios/libexec/ramcmon/monitor.out
status=`sed -n 1p $monitor_file`
message=`sed '1 d' $monitor_file`
if [ $status == 'red' ]
then
echo "CRITICAL: $message"
exit 2
elif [ $status == 'yellow' ]
then
echo "WARNING: $message"
exit 1
elif [ $status == 'green' ]
then
echo "OK: $message"
exit 0
fi
-rwxr-xr-x 1 nagios users 546 Mar 1 20:51 /usr/local/nagios/libexec/ramcmon/both.sh
I want the script to get the status and the message from the monitor file and then output a message based on the status.
You make a good point about the functions so I removed those and doing everything through an if.
#!/bin/bash
#set -x
#./update.sh > update.out 2>&1
#./verify.sh > verify.out 2>&1
monitor_file=/usr/local/nagios/libexec/ramcmon/monitor.out
status=`sed -n 1p $monitor_file`
message=`sed '1 d' $monitor_file`
if [ $status == 'red' ]
then
echo "CRITICAL: $message"
exit 2
elif [ $status == 'yellow' ]
then
echo "WARNING: $message"
exit 1
elif [ $status == 'green' ]
then
echo "OK: $message"
exit 0
fi
Re: different results when running script
The test check command can parse things differently, then the CLI / Nagios would. It will execute as the apache user, where as Nagios will run checks as the nagios user.
Is your service check reporting the correct information?
If not, I believe permissions are the issue. What are the permissions of /usr/local/nagios/libexec/ramcmon/monitor.out and /usr/local/nagios/libexec/ramcmon?
Is your service check reporting the correct information?
If not, I believe permissions are the issue. What are the permissions of /usr/local/nagios/libexec/ramcmon/monitor.out and /usr/local/nagios/libexec/ramcmon?
Former Nagios Employee
Re: different results when running script
You're right, it was a permissions issue with /usr/local/nagios/libexec/ramcmon/monitor.out.
I fixed that and it's working now using the "test check command".
Thanks for your help!!!
I fixed that and it's working now using the "test check command".
Thanks for your help!!!
Re: different results when running script
Glad to help point you in the right direction! I'll close this out now, but feel free to open a new thread if you ever need assistance in the future.
Former Nagios Employee