Page 1 of 1

No output when running script from Test Command option

Posted: Fri Apr 08, 2016 1:36 pm
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

Re: No output when running script from Test Command option

Posted: Fri Apr 08, 2016 1:53 pm
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?

Re: No output when running script from Test Command option

Posted: Fri Apr 08, 2016 2:22 pm
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

Re: No output when running script from Test Command option

Posted: Fri Apr 08, 2016 2:37 pm
by ssax
What is the output of this command:

Code: Select all

ls -l /usr/local/nagios/libexec/check_load_avg.sh

Re: No output when running script from Test Command option

Posted: Fri Apr 08, 2016 2:38 pm
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

Re: No output when running script from Test Command option

Posted: Mon Apr 11, 2016 11:01 am
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.