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

non-ASCII/Unicode character in service name is tripping up the api/services requests #1221

Open
poseidon042 opened this issue Oct 30, 2024 · 12 comments

Comments

@poseidon042
Copy link

NCPA 3.1.1 on Windows Server 2019

  • Using the web GUI and looking at api/services results in three-dots and no service content loading
  • In Nagios, the following status is returned for all service running checks for this server: "UNKNOWN: An error occurred connecting to API. (HTTP error: '500 INTERNAL SERVER ERROR')"
  • the offending service seems to have a non-ASCII character in both the Service Name and the Display Name
  • logs from the ncpa_listener log file are below ("example.com" replaces the real server name)

image

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "flask\app.py", line 1473, in wsgi_app
File "flask\app.py", line 882, in full_dispatch_request
File "flask\app.py", line 880, in full_dispatch_request
File "flask\app.py", line 865, in dispatch_request
File "listener\server.py", line 317, in token_auth_decoration
File "listener\server.py", line 1507, in api
File "listener\services.py", line 354, in run_check
File "listener\services.py", line 18, in wrapper
File "listener\services.py", line 112, in get_services_via_psutil
File "psutil_pswindows.py", line 628, in status
File "psutil_pswindows.py", line 558, in _query_status
File "contextlib.py", line 158, in exit
File "psutil_pswindows.py", line 583, in _wrap_exceptions
psutil.NoSuchProcess: service 'SNAP Live²' does not exist (name='SNAP Live²')
2024-10-30 15:26:53,115 listener INFO before_request() - request.url: https://snaps:5693/api/disk/logical/C:|/used_percent/?token=********&warning=80&critical=90&check=1
2024-10-30 15:27:11,553 listener INFO before_request() - request.url: https://snaps:5693/api/cpu/count/?token=********&check=1
2024-10-30 15:27:32,803 listener INFO before_request() - request.url: https://snaps:5693/api/system/version/?token=********&check=1
2024-10-30 15:27:33,897 listener INFO Did not receive normal values. Unable to find meaningful check.
2024-10-30 15:27:49,834 listener INFO before_request() - request.url: https://example.com:5693/gui/
2024-10-30 15:27:54,084 listener INFO before_request() - request.url: https://example.com:5693/gui/checks
2024-10-30 15:27:58,194 listener INFO before_request() - request.url: https://example.com:5693/gui/api
2024-10-30 15:27:58,412 listener INFO before_request() - request.url: https://example.com:5693/api
2024-10-30 15:28:01,397 listener INFO before_request() - request.url: https://example.com:5693/api/services
2024-10-30 15:28:01,491 listener.server ERROR Exception on /api/services [GET]
Traceback (most recent call last):
File "psutil_pswindows.py", line 570, in _wrap_exceptions
File "psutil_pswindows.py", line 559, in _query_status
OSError: [WinError 1060] The specified service does not exist as an installed service: '(originated from OpenService)'

@ne-bbahn
Copy link
Contributor

NCPA was built to support any UTF-8 characters (a superset of ASCII), so NCPA will likely break if non-UTF-8 characters are used for checks. That said, the ² character is within UTF-8, so it shouldn't be breaking things unless there is an encoding issue. I will investigate when I get the opportunity.

@domme0711
Copy link

I have a similar problem with a windows server running some stupid software with umlauts in its servicename.
The result of check_ncpa.py requesting the "services" module is:
UNKNOWN: An error occurred connecting to API. (HTTP error: '500 INTERNAL SERVER ERROR')

NCPA-Version 3.1.0

@MrPippin66
Copy link

MrPippin66 commented Nov 19, 2024

Out of curiosity, what output do you get for following in PowerShell for an affected system?

$OutputEncoding = [System.Text.Encoding]::UTF8
get-service "service name for the given service"

@poseidon042
Copy link
Author

image
image

@MrPippin66
Copy link

I'm thinking this is likely a problem with 'psutil' module.

The code path is straightfoward in NCPA with no UTF string translations occurring.

for service in psutil.win_service_iter(): name = service.name() if service.status() == 'running': services[name] = 'running' else: services[name] = 'stopped'

We essentially get a PSUTIL winservice class, and the error is getting the service status from that object without any variables being changed within NCPA, itself.

if service.status() == 'running':

I checked history of psutil, and don't see any known issues on versions of psutil since 3.1.1 deployment of NCPA.

@poseidon042
Copy link
Author

Thanks ... so how do we move this forwards?
Current situation is that all service checks for an affected server fail (non-service checks via NCPA do work OK).

image

@ne-bbahn
Copy link
Contributor

ne-bbahn commented Jan 24, 2025

#1247

Our version of NCPA agent is 3.1.1. It worked so far with no issues. Recently we have install a new software to the server which created a services which has national character in its name "Č". From that time, any API function regarding service just hangs. In the ncpa_listener.log I can see repeating errros:

`During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "flask\app.py", line 1473, in wsgi_app
File "flask\app.py", line 882, in full_dispatch_request
File "flask\app.py", line 880, in full_dispatch_request
File "flask\app.py", line 865, in dispatch_request
File "listener\server.py", line 317, in token_auth_decoration
File "listener\server.py", line 1507, in api
File "listener\services.py", line 354, in run_check
File "listener\services.py", line 18, in wrapper
File "listener\services.py", line 112, in get_services_via_psutil
File "psutil_pswindows.py", line 628, in status
File "psutil_pswindows.py", line 558, in _query_status
File "contextlib.py", line 158, in exit
File "psutil_pswindows.py", line 583, in _wrap_exceptions
psutil.NoSuchProcess: service 'ČSOB Business Connector' does not exist (name='ČSOB Business Connector')
2025-01-24 13:29:49,843 listener.server ERROR Exception on /api/services [GET]
Traceback (most recent call last):
File "psutil_pswindows.py", line 570, in _wrap_exceptions
File "psutil_pswindows.py", line 559, in _query_status
OSError: [WinError 1060] The specified service does not exist as an installed service: '(originated from OpenService)'`

I believe this is a bug.

Regards
Petr

@ne-bbahn ne-bbahn changed the title non-ASCII character in service name is perhaps tripping up the api/services requests non-ASCII/Unicode character in service name is tripping up the api/services requests Jan 24, 2025
@albertbertus
Copy link

Hi,
I have encountered an issue when trying to configure ncpa.cfg to ignore a Windows service that contains an accent in its name. When adding the option ignore_services = Ágora in the [services] section, the NCPA Listener service fails to start and throws an error like:

psutil.NoSuchProcess: service 'Ágora' does not exist (name='Ágora') OSError: [WinError 1060] The specified service does not exist as an installed service: '(originated from OpenService)'

It seems that NCPA does not handle special characters properly in service names. I tried saving ncpa.cfg in different encodings (UTF-8 without BOM, ANSI), but the issue persists.

Is there a way to ignore Windows services with accented characters in ncpa.cfg?
Any suggestions or workarounds to avoid this error would be greatly appreciated.

Thanks!

@ne-bbahn
Copy link
Contributor

@albertbertus, We are aware of this issue and will try to fix it as soon as possible. Unfortunately, we have been given other priorities for the near-term and are unable to work on it at the moment. If you can convince the PSUtil team to fix this bug, we can update the version we are using to include the fix earlier. Otherwise it'll be a while before we can get a workaround merged in.

@albertbertus
Copy link

Hi @ne-bbahn,
Thanks for the response. I understand there are other priorities at the moment. I'll try to contact the PSUtil team to see if they can address this issue.

@MrPippin66
Copy link

MrPippin66 commented Feb 19, 2025

@ne-bbahn, which version of psutils was used for the 3.1.1 build of NCPA? I assume 6.0.0, but can't validate.

I opened psutil issue. I THINK I may have identified the issue and stated it there.

giampaolo/psutil#2506

@ne-bbahn
Copy link
Contributor

@ne-bbahn, which version of psutils was used for the 3.1.1 build of NCPA? I assume 6.0.0, but can't validate.

I opened psutil issue. I THINK I may have identified the issue and stated it there.

giampaolo/psutil#2506

Based on the files in lib/library.zip, the version included is 6.1.1. Since a version is not specified, the build just pulls in whatever the default version is. This may have been updated since the Nagios NCPA build artifacts were last created as using pip install --upgrade psutil is now giving me 7.0.0.

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

5 participants