Page 1 of 2

Getting error in plugin

Posted: Tue Dec 12, 2017 12:15 pm
by bosecorp
Hi,

I'm getting below error in the plugin check.

[/usr/local/nagios/libexec/check_rdpusers.sh: line 5: [: : integer expression expected
/usr/local/nagios/libexec/check_rdpusers.sh: line 11: [: : integer expression expected
/usr/local/nagios/libexec/check_rdpusers.sh: line 15: [: : integer expression expected]

But when i manually do a run check command, it works fine.
Can you please assist me here?

# cat /usr/local/nagios/libexec/check_rdpusers.sh
#!/bin/bash

result=`/usr/local/nagios/libexec/check_nrpe -H $1 -t 60 -c "check_get_rdp_info"| grep Active | awk {'print $5'} | cut -b 11-20`

if [ "$result" -ge $2 ] ; then
if [ "$result" -lt $3 ] ; then
echo "WARNING - Remote users logged in is "$result""
exit 1
fi
fi
if [ "$result" -ge $3 ] ; then
echo "CRITICAL - Remote users logged in is "$result""
exit 2
fi
if [ "$result" -lt $2 ] ; then
echo "OK - Remote users logged in is "$result""
exit 0
fi

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 12:35 pm
by bosecorp
FYI..

Line 5 : if [ "$result" -ge $2 ]; then
Line 11: if [ "$result" -ge $3 ]; then
Line 15: if [ "$result" -lt $2 ]; then

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 12:38 pm
by bosecorp
PFA screenshot, the same check runs fine with the other hosts, not sure why it gives this error for other hosts. When i run a check command manually on those servers it works fine.

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 12:54 pm
by npolovenko
Hello, @bosecorp. You said the check command works, right? Can you run:
/usr/local/nagios/libexec/check_nrpe -H $1 -t 60 -c "check_get_rdp_info"| grep Active | awk {'print $5'} | cut -b 11-20
And demonstrate us the output.
Thanks.

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 2:08 pm
by bosecorp
# /usr/local/nagios/libexec/check_nrpe -H usmacssrdsh12.bose.com $1 -t 60 -c "check_get_rdp_info"| grep Active | awk {'print $5'} | cut -b 11-20
17

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 3:01 pm
by npolovenko
@ bosecorp, I think whatever result nrpe returns is a string. You may need to convert the "result" to an integer before passing it forward to the IF functions. Also, printing out the output of the $result inside the plugin may be useful during the troubleshooting process.

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 3:26 pm
by bosecorp
i tried declaring the variable as interger

declare -i result

But it didnt worked. Not sure why the nagios check is throwing up that error. The scirpt when we run manually works fine.

# bash -x check_rdpusers.sh xxx.bose.com 25 30
+ declare -i result
++ /usr/local/nagios/libexec/check_nrpe -H xxx.bose.com -t 60 -c check_get_rdp_info
++ grep Active
++ awk '{print $5}'
++ cut -b 11-20
+ result=15
+ '[' 15 -ge 25 ']'
+ '[' 15 -ge 30 ']'
+ '[' 15 -lt 25 ']'
+ echo 'OK - Remote users logged in is 15'
OK - Remote users logged in is 15
+ exit 0

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 3:33 pm
by npolovenko
@bosecorp, Can you run the following commands on your plugin to make sure it has the right permissions?

Code: Select all

cd /usr/local/nagios/libexec/
chown apache:nagios check_rdpusers.sh
chmod +x check_rdpusers.sh

Re: Getting error in plugin

Posted: Tue Dec 12, 2017 3:51 pm
by bosecorp
I do not see any issues with the permission.
# ls -l check_rdpusers.sh
-rwxrwxr-x 1 apache nagios 518 Dec 12 15:10 check_rdpusers.sh

Please see the attachment in my previous comments, there you can clearly see that it works from most of the servers, but fails on some.

Re: Getting error in plugin

Posted: Wed Dec 13, 2017 10:44 am
by lmiltchev
The script works fine when you run it manually as a root user. Does it also work, when you run it as nagios user?

What is the OS/architecture of the "failing" servers, and the version of bash that is installed on them? Is nagios added to sudoers?