Nagios return 0byte string from bash script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
raja2206
Posts: 7
Joined: Mon Jun 11, 2018 5:07 am

Nagios return 0byte string from bash script

Post 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.
Last edited by tmcdonald on Mon Jun 11, 2018 11:21 am, edited 1 time in total.
Reason: Please use [code][/code] tags around code output
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios return 0byte string from bash script

Post 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'
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
raja2206
Posts: 7
Joined: Mon Jun 11, 2018 5:07 am

Re: Nagios return 0byte string from bash script

Post 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
Last edited by raja2206 on Wed Jun 13, 2018 9:22 pm, edited 1 time in total.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios return 0byte string from bash script

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
raja2206
Posts: 7
Joined: Mon Jun 11, 2018 5:07 am

Re: Nagios return 0byte string from bash script

Post 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 ?
Last edited by raja2206 on Wed Jun 13, 2018 9:22 pm, edited 2 times in total.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios return 0byte string from bash script

Post 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.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
raja2206
Posts: 7
Joined: Mon Jun 11, 2018 5:07 am

Re: Nagios return 0byte string from bash script

Post 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=
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios return 0byte string from bash script

Post 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.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Nagios return 0byte string from bash script

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios return 0byte string from bash script

Post 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=
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked