Difference beetween echo return and nagios shown

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
djulien
Posts: 1
Joined: Mon Apr 06, 2020 4:37 am

Difference beetween echo return and nagios shown

Post by djulien »

Hi everyone

I try to understand a mistake :

I use an old pluggin called check_win_users (https://exchange.nagios.org/directory/P ... ck/details) to check the number of users on my RDP server.

if I execute the following command :
# su nagios /usr/lib/nagios/plugins/check_win_users.sh 172.16.0.12 NAGIOS 30 25 && echo $?

I've got this result :
4 users(s).
0

And this is perfectly correct.

But in Nagios, I've this :
"OK" -1 user(s).

Why does Nagios push "-1 user(s)." and not the result of the command as it does ?

The problem is only on the value of the result of the check commend, the rest ("user(s)") is in the echo like it does.

The following command works :

under root user or nagios user
expr $(snmpwalk 172.16.0.12 -v2c -c NAGIOS -Oqv 1.3.6.1.2.1.25.4.2.1.2 |grep winlogon.exe |wc -l) - 1

return 4



Here is the script :
#!/bin/bash

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

nbUsers=`expr $(snmpwalk $1 -v2c -c $2 -Oqv 1.3.6.1.2.1.25.4.2.1.2 |grep winlogon.exe |wc -l) - 1`

if [[ $nbUsers -gt $3 ]]
then
echo "$nbUsers utilisateur(s)."
exit $STATE_CRITICAL;
else
if [[ $nbUsers -gt $4 ]]
then
echo "$nbUsers utilisateur(s)."
exit $STATE_WARNING;
else
echo "$nbUsers utilisateur(s)."
exit $STATE_OK;
fi
fi
exit $STATE_UNKNOWN;



Someone have an idea about this difference ?

thanks a lot
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Difference beetween echo return and nagios shown

Post by cdienger »

Is the snmpwalk causing a time out? Find out how long it is taking:

Code: Select all

time snmpwalk 172.16.0.12 -v2c -c NAGIOS -Oqv 1.3.6.1.2.1.25.4.2.1.2 |grep winlogon.exe |wc -l
The timeout can be adjusted on the snmpwalk command with the '-t' flag if needed.

The service check timeout is usually set to 60, but double check it in the nagios.cfg file. The directive would look like:

Code: Select all

service_check_timeout=60
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked