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

Update check_ncpa.py to Decode latin-1 #970

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maxwbot
Copy link

@maxwbot maxwbot commented Aug 23, 2023

Some error with ptbr entry. Solved by adding correct Decoding Latin-1.

Some error with ptbr entry. Solved by adding correct Decoding Latin-1.
@sawolf
Copy link
Contributor

sawolf commented Aug 30, 2023

Hi @maxwbot, thanks for the PR!

Can you let us know 1) what endpoint you were trying to use, 2) what environment NCPA is installed in, and 3) what error you were seeing? I'm not very experienced with the NCPA project, but I would be surprised if NCPA was intentionally serving anything other than UTF-8. What would be a lot less surprising is if some endpoint was taking data (especially on Windows, but possibly on other devices) and failing to properly re-encode it. If this is happening, we'd probably want to fix the endpoint, instead of having check_ncpa.py force everything to be re-interpreted as Latin-1 encoding.

@maxwbot
Copy link
Author

maxwbot commented Sep 15, 2023

[root@VM]# /usr/local/nagios/libexec/check_ncpa_pt-br.py -H 192.0.0.X -t 'mytoken' -P 5693 -M 'services' -q 'service=Servi.*o Integra.*o,status=running,match=regex'
OK: Serviço Integração is running
[root@VM]# /usr/local/nagios/libexec/check_ncpa.py -H 192.0.0.X -t 'mytoken' -P 5693 -M 'services' -q 'service=Servi.*o Integra.*o,status=running,match=regex'
UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.

[root@VM]# /usr/local/nagios/libexec/check_ncpa.py -H 192.0.0.X -t 'mytoken' -P 5693 -M 'services' -q 'service=Servi.*o Integra.*o,status=running,match=regex' -vvv
Connecting to: https://192.0.0.X:5693/api/services/?token=XXXX&check=1&service=Servi.%2Ao+Integra.%2Ao&status=running&match=regex
An error occurred:
'utf-8' codec can't decode byte 0xe7 in position 48: invalid continuation byte

Tested in NCPA 3.0.0 and 2.4.1;

@maxwbot
Copy link
Author

maxwbot commented Sep 15, 2023

Error log in ncpa with windows_service_name: "testémção":

2023-09-15 10:46:31,205 listener.server ERROR Exception on /api/services [GET]
Traceback (most recent call last):
  File "psutil\_pswindows.py", line 543, in _wrap_exceptions
  File "psutil\_pswindows.py", line 532, in _query_status
OSError: [WinError 1060] O serviço especificado não existe como serviço instalado: '(originated from OpenService)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "flask\app.py", line 2190, in wsgi_app
  File "flask\app.py", line 1486, in full_dispatch_request
  File "flask\app.py", line 1484, in full_dispatch_request
  File "flask\app.py", line 1469, in dispatch_request
  File "listener\server.py", line 289, in token_auth_decoration
  File "listener\server.py", line 1093, in api
  File "listener\services.py", line 307, in walk
  File "listener\services.py", line 18, in wrapper
  File "listener\services.py", line 112, in get_services_via_psutil
  File "psutil\_pswindows.py", line 599, in status
  File "psutil\_pswindows.py", line 531, in _query_status
  File "contextlib.py", line 155, in __exit__
  File "psutil\_pswindows.py", line 552, in _wrap_exceptions
psutil.NoSuchProcess: service 'testémção' does not exist) (name='testémção')

@maxwbot
Copy link
Author

maxwbot commented Sep 17, 2023

Hi @sawolf ,
Do you have the ncpa 3 beta repository? (NCPA_2 uses the obsolete version of python 2.7.. the new NCPA_3 uses python 3?)

The problem lies in the coding:
for service in psutil.win_service_iter(): name = service.name()

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

Successfully merging this pull request may close these issues.

None yet

2 participants