Service Check - Argument syntax not working within GUI

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Service Check - Argument syntax not working within GUI

Post 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
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Service Check - Argument syntax not working within GUI

Post by tgriep »

Try using single quotes around the argument like the following and see if that works.

Code: Select all

'Service(SL01)'
Be sure to check out our Knowledgebase for helpful articles and solutions!
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Re: Service Check - Argument syntax not working within GUI

Post 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
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Service Check - Argument syntax not working within GUI

Post by tgriep »

Can you post the /usr/local/nagios/libexec/check_alert_script script so we can see how it functions?
Be sure to check out our Knowledgebase for helpful articles and solutions!
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Re: Service Check - Argument syntax not working within GUI

Post 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
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Service Check - Argument syntax not working within GUI

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Re: Service Check - Argument syntax not working within GUI

Post 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
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Service Check - Argument syntax not working within GUI

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked