Page 1 of 1
Service Check - Argument syntax not working within GUI
Posted: Thu Sep 17, 2020 2:53 pm
by scomdco
Please assist me and figuring out how to get this to work successfully,
This command fails if ran through the GUI, configured as a service, but it works successfully if ran through SSH in the XI instance:
I've redacted information for the sake of security:
Code: Select all
[nagios@servername ~]$ /usr/local/nagios/libexec/check_alert_script "Service(SL01)"
<B>*** UNKNOWN ***</B> Service\\(SL01\\): Status Unknown
The issue occurs if the argument has parenthesis in the value, please advise how to get around this i notice that XI is added \\ in front of each parethesis when running the check through the GUI
Through SSH:
Code: Select all
/usr/local/nagios/libexec/check_alert_script:
<B>*** OK ***</B> Service(SL01): Status Okay
I'm actually migrating this check from an old Nagios Core server we have (3.2.3), and the command works successfully within there as a service check
Re: Service Check - Argument syntax not working within GUI
Posted: Fri Sep 18, 2020 2:26 pm
by tgriep
Try using single quotes around the argument like the following and see if that works.
Re: Service Check - Argument syntax not working within GUI
Posted: Fri Sep 18, 2020 5:07 pm
by scomdco
It's still failing with that modification, i do notice however that there is two less slashes in the output with this method
Code: Select all
[nagios@servername ~]$ /usr/local/nagios/libexec/check_alert_script 'Service(SL01)'
<B>*** UNKNOWN ***</B> Service\(SL01\): Status Unknown
Re: Service Check - Argument syntax not working within GUI
Posted: Mon Sep 21, 2020 9:01 am
by tgriep
Can you post the /usr/local/nagios/libexec/check_alert_script script so we can see how it functions?
Re: Service Check - Argument syntax not working within GUI
Posted: Mon Sep 21, 2020 12:36 pm
by scomdco
Code: Select all
#!/bin/bash
# Setup ENVIRONMENT
# UnixODBC Environment
######################################
UNIXODBC=/opt/unixODBC
PATH=$UNIXODBC/bin:$PATH
LD_LIBRARY_PATH=$UNIXODBC/lib:$LD_LIBRARY_PATH
export UNIXODBC PATH LD_LIBRARY_PATH
# FreeTDS Environment
######################################
FREETDS=/opt/freetds
PATH=$FREETDS/bin:$PATH
LD_LIBRARY_PATH=$FREETDS/lib:$LD_LIBRARY_PATH
export FREETDS PATH LD_LIBRARY_PATH
if [ $# -eq 0 ]
then
echo "Usage: $0 AlertName"
exit 1
fi
AlertName=$1
checkstatus=$(/usr/bin/bsqldb -q -U 'REDACTED' -P 'REDACTED' -S REDACTEDSERVER -t \| <<EOF
use REDACTEDTABLE
exec REDACTEDSTOREDPROCEDURE
EOF
)
result=$(echo "$checkstatus" | grep "|$AlertName|" | awk -F \| '{print $3}')
if [ "$result" == "Alert" ]
then
echo "<B>*** CRITICAL ***</B> $AlertName: Status Alert"
#echo "$checkstatus" | grep "|$AlertName|" | sed 's/|/ /g'
echo "$checkstatus" | grep "|$AlertName|" | awk -F \| '{$1 = "AlertID("$1"): ";print }'
exit 2
fi
if [ "$result" == "Normal" ]
then
echo "<B>*** OK ***</B> $AlertName: Status Normal"
#echo "$checkstatus" | grep "|$AlertName|" | sed 's/|/ /g'
echo "$checkstatus" | grep "|$AlertName|" | awk -F \| '{$1 = "AlertID("$1"): ";print }'
exit 0
fi
echo "<B>*** UNKNOWN ***</B> $AlertName: Status Unknown"
#echo "$checkstatus" | grep "|$AlertName|" | sed 's/|/ /g'
echo "$checkstatus" | grep "|$AlertName|" | awk -F \| '{$1 = "AlertID("$1"): ";print }'
exit 3
Re: Service Check - Argument syntax not working within GUI
Posted: Mon Sep 21, 2020 3:16 pm
by tgriep
Thanks for the script, it should be OK.
Are you using the Run Check Command button and then getting that error?
If so, the extra \ are added to the command when that button is used to run the check.
Sometimes it add extra characters that are not needed and that is what is happening.
Use the single quotes in the argument. Activate and save the check. Apply the Config.
Go to the Home > Service Status menu and find that service and see if the check functions.
If so, then you should be OK.
Re: Service Check - Argument syntax not working within GUI
Posted: Mon Sep 21, 2020 3:46 pm
by scomdco
You're right, i enabled it and it's executing successfully, thanks for your help on this! The issue is with the Run Check Command as you stated
Re: Service Check - Argument syntax not working within GUI
Posted: Mon Sep 21, 2020 4:48 pm
by tgriep
I am glad it worked. I'll lock the post as solved but feel free to open a new one in the future for any other questions.