Different results from CLI and XI GUI

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Different results from CLI and XI GUI

Post by elade »

Hi,

I have an script which run in nagios server (localhost).
The script run a ssh command and all working in CLI.
When I run the script via XI GUI I get a different result.
I thought that because the SSH key was for other user and I changed it to nagios user but still the same).
SSH from localhost to the server is working.
I have scripts which run the same thing (ssh command via script) but they were configured in old version of NagiosXI (4.X).
NagiosXI version 5.5.8
I upgrade the version 3 weeks ago and it’s the first time I’m having trouble adding new monitor in localhost.

This is the configuration in the server:
Script:
-rwxr-xr-x 1 root nagios 1077 Feb 5 18:51 check_test_status.py
Nrpe.cfg:
dont_blame_nrpe=1
command[check_test_status]=sudo -S /usr/local/nagios/libexec/check_test_status.py $ARG1$ $ARG2$
sudoers:
nagios ALL=NOPASSWD:/usr/local/nagios/libexec/check_test_status.py
respond from CLI
/usr/local/nagios/libexec/check_test_status.py 10.10.10.10 test
OK: no errors
Respond from XI:
[[email protected] ~]$ /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -t 120 -2 -c check_test_status -a 10.10.10.10 test
check ssh connection to server
(its a part of the script ro check if ssh is working).
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Different results from CLI and XI GUI

Post by npolovenko »

@elade, Can you try wrapping NRPE arguments in quotes?
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -t 120 -2 -c check_test_status -a "10.10.10.10" "test"
Please upload the check_test_status.py script in this thread.

Finally, please run this script on the nrpe server as the Nagios user:
su - nagios
/usr/local/nagios/libexec/check_test_status.py 10.10.10.10 test
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Re: Different results from CLI and XI GUI

Post by elade »

@elade, Can you try wrapping NRPE arguments in quotes?
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -t 120 -2 -c check_test_status -a "10.10.10.10" "test"
Did it still the same
Finally, please run this script on the nrpe server as the Nagios user:
su - nagios
/usr/local/nagios/libexec/check_test_status.py 10.10.10.10 test
working under user nagios

the script

Code: Select all

#!/usr/bin/python

import sys
import subprocess
import os
import re

def run_command_safe(command):
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    out = p.communicate()
    return p.returncode, out[0]

def main():
    if len(sys.argv) != 3:
        print "Critical: Wrong number of arguments"
        sys.exit(2)

    ip = sys.argv[1]
    username = sys.argv[2]

    cmd_grep = 'show status'
    cmd = "ssh -o ConnectTimeout=10 "+username+"@"+ip+" '"+cmd_grep+"' 2>/dev/null"
    code,out = run_command_safe(cmd)
    if not out:
        print "check ssh connection to test"
        sys.exit(1)

    status = re.findall('Summary Status \W+[\w+]+',str(out))
    status = re.sub('[^A-Za-z0-9-_/:]+',' ',str(status))
    if 'Error' in str(out) or 'Ready' in str(out):
        print status
        sys.exit(2)
    elif 'Warning' in str(out) or 'Maintenace' in str(out) or 'Offline' in str(out):
        print status
        sys.exit(1)
    else:
        print "OK: no errors"
        sys.exit(0)


if __name__ == "__main__":
    main()
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Different results from CLI and XI GUI

Post by npolovenko »

@elade, Seems like its failing on this line:
ssh -o ConnectTimeout=10 "+username+"@"+ip+" '"+cmd_grep+"' 2>/dev/null
If you manually run this command under nagios user does it prompt you for a password?

If so you need to set up access using SSH keys without a password.
https://www.ssh.com/ssh/keygen/
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Re: Different results from CLI and XI GUI

Post by elade »

@npolovenko The ssh command is working OK in CLI from localhost machin.
I get the result from the remote machine in both users (root and nagios).
CLI> show status
Summary Status [Normal]
CLI>
OK: no errors
The ssh key was upload to the remote machine so I can do ssh without password.
f you manually run this command under nagios user does it prompt you for a password?
No.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Different results from CLI and XI GUI

Post by npolovenko »

@elade, Your script didn't work on my server.
[root@centos7x64 libexec]# ./test.sh 192.168.3.3 root
check ssh connection to test
[root@centos7x64 libexec]# ssh [email protected]
Last login: Sun Jan 27 18:24:35 2019 from centos7x64
[root@centos7x64 ~]# ssh -o ConnectTimeout=10 [email protected] 'cmd_grep' 2>/dev/null
You have new mail in /var/spool/mail/root
[root@centos7x64 ~]#
I'm not a code expert but seems like the script is failing to create a new subprocess with the shell.

Can you add the following entry to the /etc/sudoers file on the nrpe server and let me know if it fixes the issue?
Defaults:nagios !requiretty
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Re: Different results from CLI and XI GUI

Post by elade »

Hi,

You can close the topic please I fixed the problems.
Locked