No output when running script from Test Command option

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
operations_asavie
Posts: 33
Joined: Tue Dec 22, 2015 7:07 am

No output when running script from Test Command option

Post by operations_asavie »

Hi,

Im having a problem when running a snmp script from the test command option. It shows no output as below:

Testing check from command line...

COMMAND: $USER$/check_load_avg.sh 192.xxx.xxx.xxx
OUTPUT:

However when I run the command from the CLI I get the expected results:


# su nagios
#./check_load_avg.sh 192.xxx.xxx.xxx
OK- Load Average: 1min=0.23, 5min=0.17, 15min=0.19 | '1min Load Avg'=0.23, '5min Load Avg'=0.17, '15min Load Avg'=0.19

The contents of the script is below:

#!/bin/bash
hostaddress="$1"

check_load_avg=($(snmpwalk -v2c -c community $hostaddress .1.3.6.1.4.1.2021.10 | grep -i laLoad.[1-3] | cut -d"=" -f 2 | cut -d" " -f3 | sed 'N;s/\n/ /' | sed 'N;s/\n/ /' | awk '{print $1" " $2 " " $3}'))

one_min_avg=${check_load_avg[0]}
five_min_avg=${check_load_avg[1]}
fifteen_min_avg=${check_load_avg[2]}

if [[ -z "$1" ]]

then echo "Incorrect syntax, please use check_load_average <ipaddress>"

exit 3

elif [[ -z "$check_load_avg" ]];

then "echo test"
exit 3

else

echo "OK- Load Average: 1min=$one_min_avg, 5min=$five_min_avg, 15min=$fifteen_min_avg | '1min Load Avg'=$one_min_avg, '5min Load Avg'=$five_min_avg, '15min Load Avg'=$fifteen_min_avg"

exit 0

fi



Thanks for the help in advance.

Fearghal
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: No output when running script from Test Command option

Post by hsmith »

If you run it using the test button you're running it as the apache user. You're running it as whatever user on the command line. This is one of the reasons that button can be a little unreliable sometimes. Have you created the check and tested to see that it runs on its own?
Former Nagios Employee.
me.
operations_asavie
Posts: 33
Joined: Tue Dec 22, 2015 7:07 am

Re: No output when running script from Test Command option

Post by operations_asavie »

Hi,

Yes I have created the check against one of our hosts, its the same host ip that I'm testing via the cli and I get the result below:

Critical 3m 16s 4/5 2016-04-08 20:19:54 (Return code of 127 is out of bounds - plugin may be missing)

Thanks,
Fearghal
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: No output when running script from Test Command option

Post by ssax »

What is the output of this command:

Code: Select all

ls -l /usr/local/nagios/libexec/check_load_avg.sh
operations_asavie
Posts: 33
Joined: Tue Dec 22, 2015 7:07 am

Re: No output when running script from Test Command option

Post by operations_asavie »

Hi,

See output below:

# ls -l /usr/local/nagios/libexec/check_load_avg.sh
-rwxr-xr-x 1 root nagios 742 Apr 8 19:04 /usr/local/nagios/libexec/check_load_avg.sh

Thanks,
Fearghal
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: No output when running script from Test Command option

Post by rkennedy »

You'll want to update the permissions for check_load_avg.sh -

Code: Select all

chown apache:nagios check_load_avg.sh
Then try again, and let us know the result.
Former Nagios Employee
Locked