Page 1 of 1

Python scripts

Posted: Wed Jun 26, 2024 11:49 am
by RegIT
Hi to everyone,

I would like to monitor a Windows Server taking advantage of Python scripts. The script are already located in the NCPA's plugins folder.

The services configuration in Nagios is set like the image in attachments.

The "Status information" error is: UNKNOWN: An error occured connecting to API. (HTTP error: '500 INTERNAL SERVER ERROR')

Do you have any tips?

When i do the same exactly thing with powershell i've no problems.

Thank you.

Re: Python scripts

Posted: Thu Jun 27, 2024 9:38 am
by swolf
Hi @RegIT, thanks for reaching out.

I think a 500 error from NCPA is always a bug - can you check ncpa_listener.log on your Windows server to see if there's any additional information we can pass along to the NCPA maintainer?

-Sebastian

Re: Python scripts

Posted: Thu Jun 27, 2024 10:00 am
by RegIT
Here the log

2024-06-27 16:59:08,331 listener.server ERROR Exception on /api/plugins/REGESTA.py/ [GET]
Traceback (most recent call last):
File "listener\nodes.py", line 351, in run_check
File "listener\nodes.py", line 315, in get_values
AttributeError: 'PluginNode' object has no attribute 'method'

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\nodes.py", line 353, in run_check
File "listener\pluginnodes.py", line 122, in execute_plugin
File "gevent\subprocess.py", line 808, in __init__
File "gevent\subprocess.py", line 1295, in _execute_child
FileNotFoundError: [WinError 2] Impossibile trovare il file specificato

Re: Python scripts

Posted: Thu Jun 27, 2024 10:28 am
by ssunga
Are you able to execute a simple python script (print('Hello World') for example) on the Windows Server with NCPA?

If not, are you able to execute it on the windows server manually with python?

There could be issues with your python pathing in your NCPA configuration (this seems like the most likely problem because powershell is working)

Re: Python scripts

Posted: Thu Jun 27, 2024 10:55 am
by RegIT
When i try to execute a script i receive this alert

Re: Python scripts

Posted: Thu Jun 27, 2024 11:48 am
by lgute
Hi @RegIT, thanks for reaching out.

I am going to open a bug on Github, for this issue. It looks like you are running NCPA 3, is that correct?

Our NCPA maintainer is out this week, but will take a look at this when he returns.

Re: Python scripts

Posted: Fri Jun 28, 2024 5:11 am
by RegIT
I've managed this issue changing the ncpa.cfg modifying the string when calling the .py

I've changed from "python3 $plugin_name $plugin_args" to "python $plugin_name $plugin_args".

Now the script works but in the status information i see this:


Any tips?

Re: Python scripts

Posted: Fri Jun 28, 2024 11:28 am
by lgute
Hi @RegIT,

Thank you for the information. I am sure our NCPA maintainer will appreciate it.

If you are interested, the Github issue for the original problem is https://github.com/NagiosEnterprises/ncpa/issues/1179.

Googling a bit I found this somewhat recent post (unfortunately not for Windows) https://discuss.python.org/t/why-is-pyt ... ng/10565/7, that might help. The gist is to reinstall Python.