Page 1 of 2

Nagios return 0byte string from bash script

Posted: Mon Jun 11, 2018 6:40 am
by raja2206
Hi,
We have configured shell script to mointior unity storage via nagios, the script is working fine via CLI, but it is 0 byte output via nagios

Code: Select all

# ls -la check_unity.sh
-rwxr-xr-x 1 nagios nagios 681 Jun 11 11:19 check_unity.sh
 # cat check_unity.sh
#!/bin/bash
ucli=/usr/bin/uemcli
host=$1
user="$2"
password="$3"
check_path="$4"

if [ "`$ucli -d $host -user $user -password $password $check_path show -output csv | sed '1d' | cut -d"," -f5 | sed -e 's/\"//g' -e 's/\s.*//g' | sort | uniq | awk '{if (NR == 4) print}'`" == "OK" ] ; then
        echo "OK - no faults detected"
        exit 0
else
      echo "UNKNOWN - Unisphere CLI returned an error, unable to perform check"
       exit 1
fi
cfg file :

Code: Select all

define service{
        use                     array-service ; Inherit values from a template
        service_description     check unity Status
        host_name               unity5400   ; hostname the service is associated with
        check_command           check_unity_status!xxx!ppp!/env/ps
        normal_check_interval   10              ; Check the service every 60 minutes under normal conditions
        }
command.cfg

Code: Select all

#check_unity_general

define command{
        command_name    check_unity_status
        command_line    $USER2$/check_unity.sh $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$
}
Can you please anyone help on this issue.

Re: Nagios return 0byte string from bash script

Posted: Mon Jun 11, 2018 2:32 pm
by scottwilkerson
Can you run the command form the CLI as the nagios user?

Code: Select all

sudo su nagios -c '/full/path/to/script/check_unity.sh xxx.xxx.xxx.xxx xxx ppp /env/ps'

Re: Nagios return 0byte string from bash script

Posted: Tue Jun 12, 2018 2:29 am
by raja2206
HI, please find the output.
#/opt/nagios/libexec # sudo su nagios -c '/opt/nagios/libexec/check_unity.sh unity500 Monitor password /env/ps'
OK - no faults detected

Note : my password has special character '%' in the middle

Re: Nagios return 0byte string from bash script

Posted: Tue Jun 12, 2018 2:30 pm
by scottwilkerson
raja2206 wrote:Note : my password has special character '%' in the middle
This makes a difference....
Lets set $ARG2$ to be 'ppp' where ppp is your password, wrapping it in single quotes

Re: Nagios return 0byte string from bash script

Posted: Wed Jun 13, 2018 2:01 am
by raja2206
Hi,
I have updated the .cfg file, but still no output from nagios. However from command is working fine
define service{
use array-service ; Inherit values from a template
service_description check unity Status
host_name unity500 ; hostname the service is associated with
check_command check_unity_status!Monitor!'pppp%ppp'!/env/ps
normal_check_interval 10 ; Check the service every 60 minutes under normal conditions
}

#/opt/nagios/etc # sudo su nagios -c '/opt/nagios/libexec/check_unity.sh unity500 Monitor 'pppp%ppp'' /env/ps'
OK - no faults detected

Note : it is necessary to restart nagios service for this change ?

Re: Nagios return 0byte string from bash script

Posted: Wed Jun 13, 2018 8:38 am
by scottwilkerson
raja2206 wrote: Note : it is necessary to restart nagios service for this change ?
Yes, but you should be making the change in Configure -> CCM and then Apply Configuration not directly in the .cfg as this will get overwritten by the CCM the next time you Apply Configuration.

Re: Nagios return 0byte string from bash script

Posted: Wed Jun 13, 2018 9:47 am
by raja2206
Hi,
I have restarted the nagios services, still same error.

command.cfg file
#check_unity_general

define command{
command_name check_unity_status
command_line $USER2$/check_unity.sh $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$
}

Monitor config file

define service{
use array-service ; Inherit values from a template
service_description check unity Status
host_name unity500 ; hostname the service is associated with
check_command check_unity_status!Monitor!'pppp%ppp'!/env/ps
normal_check_interval 10 ; Check the service every 60 minutes under normal conditions
}

I have updated the script with echo output :
#!/bin/bash
ucli=/usr/bin/uemcli
#ucli=/opt/emc/uemcli/bin/uemcli.sh
host=$1
user="$2"
password="$3"
check_path="$4"

if [ "`$ucli -d $host -user $user -password $password $check_path show -output csv | sed '1d' | cut -d"," -f5 | sed -e 's/\"//g' -e 's/\s.*//g' | sort | uniq | awk '{if (NR == 4) print}'`" == "OK" ] ; then
echo "OK - no faults detected"
exit 0
else
C="`$ucli -d $host -user $user -password $password $check_path show -output csv | sed '1d' | cut -d"," -f5 | sed -e 's/\"//g' -e 's/\s.*//g' | sort | uniq | awk '{if (NR == 4) print}'`"
echo "C= $C"
# echo "UNKNOWN - Unisphere CLI returned an error, unable to perform check"
exit 1
fi

output in nagios is emptry
C=

Re: Nagios return 0byte string from bash script

Posted: Wed Jun 13, 2018 11:26 am
by scottwilkerson
looks like when it is running you are getting to the else clause.

Unfortunately we can''t really debug this from here as we don't have these systems.

Re: Nagios return 0byte string from bash script

Posted: Wed Jun 13, 2018 1:07 pm
by gormank
Try commenting the first echo and uncommenting the second. Note that a plugin returning nothing on STDOUT is not an error and that the return status ($?) is the significant part.

Re: Nagios return 0byte string from bash script

Posted: Wed Jun 13, 2018 3:52 pm
by scottwilkerson
gormank wrote:Try commenting the first echo and uncommenting the second. Note that a plugin returning nothing on STDOUT is not an error and that the return status ($?) is the significant part.
Except this isn't actually returning nothing, it is returning

Code: Select all

C=