Nagstamon icon indicating copy to clipboard operation
Nagstamon copied to clipboard

Authentication problem in Actions when "IP resolved by hostname" is selected

Open bobi1024 opened this issue 1 year ago • 4 comments

For some time now I have problem executing all Actions when "IP resolved by hostname" is selected.

I'm using nagstamon 3.10.1 under Debian testing monitoring Nagios server.

I was able to do some debugging and came across this error

DEBUG: 2023-03-02 18:12:08.273706 SH FetchURL: https://example.com/nagios/cgi-bin/extinfo.cgi?type=1&host=example CGI Data: None
ERROR: 2023-03-02 18:12:08.370593 SH Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/Nagstamon/Servers/Generic.py", line 1580, in GetHost
    ip = htobj.findAll(name='div', attrs={'class': 'data'})[-1].text
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range

I've substituted the real data with example due to privacy issues.

The reason for the IndexError: list index out of range is that the

# get host info
        result = self.FetchURL(cgiurl_host, giveback='obj')

in Generic.py is returning HTTP Error 401 in htobj and the result is:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>

I see that in def FetchURL some # unpasswordify CGI data is done which is probably part of the problem.

I've double checked the monitor_cgi_url and the credentials and they are all correct.

Is there something that I can try as a workaround, or how can I get to the point where the authentication brakes?

Have in mind I'm not a python programmer just a simple sysadmin :)

bobi1024 avatar Mar 02 '23 16:03 bobi1024

Hi @bobi1024, sorry for the late reply. The # unpasswordify CGI data part only hides a real password in the logs. You found some very old code there... What is the version of the Nagios server you use? Can you prove the IP address of the host is included in the URL https://example.com/nagios/cgi-bin/extinfo.cgi?type=1&host=example if you try to access it in a browser? Does your local DNS setup match hostname and IP address correctly?

HenriWahl avatar Mar 08 '23 18:03 HenriWahl

What is the version of the Nagios server you use?

Nagios Core 4.0.8

Can you prove the IP address of the host is included in the URL https://example.com/nagios/cgi-bin/extinfo.cgi?type=1&host=example if you try to access it in a browser?

Sorry, I can not provide the IP address, but the problem is with all the hosts in nagios, not just with single host. I have no problem accessing it trough web browser once the BASIC HTTP AUTH session is initiated.

Does your local DNS setup match hostname and IP address correctly?

No. That is the reason I want to connect to servers using directly the IP address, because we have hosts in the monitoring system that does not only do not mach on my local DNS, but does not match in any DNS. That is why I want to use the $$ADDRESS$ variable directly with IP address in nagstamon Actions.

bobi1024 avatar Mar 13 '23 15:03 bobi1024

@bobi1024 sorry :-) I did not not mean provide but prove - what yo you get when you call this URL directly in your browser? Sounds like it will work then?

HenriWahl avatar Mar 15 '23 04:03 HenriWahl

I testet with https://nagioscore.demos.nagios.com/ which has version 4.4.6 and there it worked flawlessly. Your 4.0.8 seems pretty outdated - maybe it would work after an update?

HenriWahl avatar Mar 15 '23 04:03 HenriWahl