Getting error in plugin

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Getting error in plugin

Post 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
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Getting error in plugin

Post by bosecorp »

FYI..

Line 5 : if [ "$result" -ge $2 ]; then
Line 11: if [ "$result" -ge $3 ]; then
Line 15: if [ "$result" -lt $2 ]; then
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Getting error in plugin

Post 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.
You do not have the required permissions to view the files attached to this post.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Getting error in plugin

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Getting error in plugin

Post 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
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Getting error in plugin

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Getting error in plugin

Post 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
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Getting error in plugin

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
bosecorp
Posts: 929
Joined: Thu Jun 26, 2014 1:00 pm

Re: Getting error in plugin

Post 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.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Getting error in plugin

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