Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with ports plugin (for URL request) #3008

Closed
G4Zz0L1 opened this issue Nov 10, 2024 · 4 comments
Closed

Issue with ports plugin (for URL request) #3008

G4Zz0L1 opened this issue Nov 10, 2024 · 4 comments

Comments

@G4Zz0L1
Copy link

G4Zz0L1 commented Nov 10, 2024

Hello, I've been experiencing issues with the ports plugin for some time now.

Specifically, I have had a web ping set up for ages to check if one of my hosts is up or not, but in recent versions, I noticed it no longer appears in the list. It used to work with the following configuration:

[ports]
disable=False
# Interval in second between two scans
# Ports scanner plugin configuration
refresh=30
# Set the default timeout (in second) for a scan (can be overwritten in the scan list)
timeout=3
# If port_default_gateway is True, add the default gateway on top of the scan list
port_default_gateway=True
#
# Define the scan list (1 < x < 255)
# port_x_host (name or IP) is mandatory
# port_x_port (TCP port number) is optional (if not set, use ICMP)
# port_x_description is optional (if not set, define to host:port)
# port_x_timeout is optional and overwrite the default timeout value
# port_x_rtt_warning is optional and defines the warning threshold in ms
#
#port_1_host=192.168.0.1
#port_1_port=80
#port_1_description=Home Box
#port_1_timeout=1
#port_2_host=www.free.fr
#port_2_description=My ISP
#port_3_host=www.google.com
#port_3_description=Internet ICMP
#port_3_rtt_warning=1000
#port_4_description=Internet Web
#port_4_host=www.google.com
#port_4_port=80
#port_4_rtt_warning=1000
#
# Define Web (URL) monitoring list (1 < x < 255)
# web_x_url is the URL to monitor (example: http://my.site.com/folder)
# web_x_description is optional (if not set, define to URL)
# web_x_timeout is optional and overwrite the default timeout value
# web_x_rtt_warning is optional and defines the warning respond time in ms (approximately)
#
#web_1_url=https://blog.nicolargo.com
#web_1_description=My Blog
#web_1_rtt_warning=3000
#web_2_url=https://github.com
#web_3_url=http://www.google.fr
#web_3_description=Google Fr
#web_4_url=https://blog.nicolargo.com/nonexist
#web_4_description=Intranet
web_1_host=https://host/ping.php
web_1_description=host

In the docs, I see that the key should be web_1_url, but in that case, I get the following error:

Traceback (most recent call last):
File "/usr/bin/glances", line 8, in <module>
sys.exit(main())
         ^^^^^^
File "/usr/lib/python3.12/site-packages/glances/__init__.py", line 173, in main
start(config=core.get_config(), args=core.get_args())
File "/usr/lib/python3.12/site-packages/glances/__init__.py", line 121, in start
mode.serve_forever()
File "/usr/lib/python3.12/site-packages/glances/standalone.py", line 186, in serve_forever
while self.__serve_once():
      ^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/standalone.py", line 158, in __serve_once
ret = not self.screen.update(self.stats, duration=adapted_refresh)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/outputs/glances_curses.py", line 1099, in update
self.flush(stats, cs_status=cs_status)
File "/usr/lib/python3.12/site-packages/glances/outputs/glances_curses.py", line 1080, in flush
self.display(stats, cs_status=cs_status)
File "/usr/lib/python3.12/site-packages/glances/outputs/glances_curses.py", line 521, in display
__stat_display = self.__get_stat_display(stats, layer=cs_status)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/outputs/glances_curses.py", line 497, in __get_stat_display
ret[p] = stats.get_plugin(p).get_stats_display(args=self.args, max_width=plugin_max_width)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/plugins/plugin/model.py", line 892, in get_stats_display
ret = {'display': display_curse, 'msgdict': self.msg_curse(args, max_width=max_width), 'align': align_curse}
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/plugins/ports/__init__.py", line 229, in msg_curse
ret = reduce(build_str_with_this_max_width, self.stats, init)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/plugins/ports/__init__.py", line 195, in build_str
helper, status = self.get_status_and_helper(p).get(True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/plugins/ports/__init__.py", line 206, in get_status_and_helper
'host' in p: (self.get_ports_alert, self.set_status_if_host(p)),
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/glances/plugins/ports/__init__.py", line 170, in set_status_if_host
if p['host'] is None:
   ~^^^^^^^^
KeyError: 'host'

The default gateway does not seem to have any issues; it appears in the list and works correctly. Other port_x_host entries, if added, also appear and work as expected. However, for the web part, I can't find an accepted configuration, and even when checking the debug logs, they don't seem to appear during the scan phase:

2024-11-10 17:42:51,455 -- DEBUG -- PluginModel glances.plugins.core update return {'phys': 16, 'log': 32} in 0.00093 seconds
2024-11-10 17:42:51,462 -- DEBUG -- PluginModel glances.plugins.gpu update return [{'key': 'gpu_id', 'gpu_id': '...', 'name': '...', 'mem': 6, 'proc': 0, 'temperature': 38, 'fan_speed': None}] in 0.007248 seconds
2024-11-10 17:42:51,462 -- DEBUG -- ports plugin - Create thread for scan list [{'host': '192.168.1.1', 'port': 0, 'description': 'DefaultGateway', 'refresh': 30, 'timeout': 3, 'status': None, 'rtt_warning': None, 'indice': 'port_0'}]
2024-11-10 17:42:51,463 -- DEBUG -- ports: Cannot convert 3 to IP address (gethostbyname() argument 1 must be str, bytes or bytearray, not int)
2024-11-10 17:42:51,463 -- DEBUG -- PluginModel glances.plugins.ports update return [{'host': '192.168.1.1', 'port': 0, 'description': 'DefaultGateway', 'refresh': 30, 'timeout': 3, 'status': None, 'rtt_warning': None, 'indice': 'port_0'}] in 0.000291 seconds
2024-11-10 17:42:51,494 -- DEBUG -- PluginModel glances.plugins.system update return {'os_name': 'Linux', 'hostname': '...', 'platform': '64bit', 'os_version': '6.11.6-arch1-1', 'linux_distro': 'Arch Linux', 'hr_name': 'Arch Linux 64bit / Linux 6.11.6-arch1-1'} in 0.031301 seconds
2024-11-10 17:42:51,497 -- DEBUG -- PluginModel glances.plugins.quicklook update return {'cpu_name': '...',  ....

There seems to be a regression in this file: https://github.com/nicolargo/glances/blob/develop/glances/plugins/ports/__init__.py, possibly related to the commit f8fe7e2, but I haven't been able to debug it properly.

What can I do to help with debugging?

Thanks in advance.

@nicolargo
Copy link
Owner

Hi @G4Zz0L1

Thanks for the issue report.

I will have a look on it asap.

@nicolargo nicolargo added this to the Glances 4.3.0 milestone Nov 11, 2024
@lykinsbd
Copy link

I can confirm I'm seeing the same behavior in 4.2.1:

glances --version
Glances version:        4.2.1
Glances API version:    4
PsUtil version:         5.9.5

Relevant config:

[ports]
disable=False
refresh=30
timeout=3
port_default_gateway=True
#
port_1_host=172.20.10.5
port_1_port=53
port_1_description=PiHole
port_1_timeout=1
port_2_host=google.com
port_2_description=Google
#
web_1_url=https://network-notes.com
web_1_description=Network Notes
web_1_rtt_warning=3000

If I comment out the web checks, it works fine with just the port checks.

@nicolargo nicolargo changed the title Issue with ports plugin Issue with ports plugin (for URL request) Nov 11, 2024
@nicolargo
Copy link
Owner

Patch done on the develop branch.

@G4Zz0L1 can you test it ?

If ok, will be release in next Glances version.

@lykinsbd
Copy link

@nicolargo just pulled develop and tested, the issue is resolved for me. Thanks for the fast turn around! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants