Run python script


#1

Hi,

I try to get python script working on nscp 0.4.4. So I did this in my nsclient.ini :

[/modules]
PythonScript=1
[/settings/python/scripts]
py_wmi_obj=scripts\python\sample\list_all_wmi_objects.py

When I start nscp in test mode (nscp.exe test) I can see that the script is loaded

D     python Looking for: scripts\python\sample\list_all_wmi_objects.py
D     python Adding script: py_wmi_obj (scripts\python\sample\list_all_wmi_objects.py)
D     python boot python
D     python Prepare python
D     python init python
D     python Loading python script: scripts\python\sample\list_all_wmi_objects.py
D     python Lib path: C:\Program Files\NSClient++\scripts\python\lib
E     python close failed in file object destructor:
IOError: [Errno 0] Error

(don’t know if the error is serious or not)

but when I type py_wmi_obj in prompt, it said that the command is unknown. I tried to put it in the external script like that

[/settings/external script/script]
wmi_obj=py_wmi_obj

but didn’t work, which look normal to me :-). What is the proper way to launch python script in nsclient++.


#2

I have noticed this lately, not sure if it is related to something I have changed or not it usualy means you have some problem in the script… (Before you usually got a “on line 34 you have error x” but when I have seen that it has usually been calling

conf = Settings.get(plugin_id)
reg = Registry.get(plugin_id)

with out the plugin_id (as it was before)

I will try to improve this error message though…


#3

Hum so you think it is a problem in the script ? I only tried with the sample script, no my own.


#4

Ohh, had forgotten about that one…

A pretty (old) bad sample… a better sample plugin is scripts\python\sample.py

But yes it had exactly the problem i mentioned, pushed a new version but as I said the script has some issues so I would look in the other sample script…


#5

In 0.4.4 on win8 x64 doesn’t work (launching via nscp py --script=<thescript>):

  • test_all.py (IOError [Errno 0] etc…)
  • test_eventlog.py
  • test_external_script.py
  • sample.py

The output is always the same :

IOError: [Errno 0] Error

                    c:\source\nscp\modules\PythonScript\script_wrapper.cpp:165

And by the way, how can I launch a python script from the api or via the scheduler ?

Thanks


#6

Yes,

In 0.5.0 I gixed this:

$ nscp py --script=sample.py
Command not found:
Usage: nscp py [execute|list|install] --help

Adding in execute:

$ nscp py execute --script=sample.py
L     python My god: its full of stars: true
L     python Adding a simple function/cmd line
L     python Unloading script...

#7

I am trying to run python scripts by using the “nscp py execute --script=” method. So far I can get the provided sample.py to work but if I run most of the other scripts I get a error similair to: nscp python execute --script=test_all.py E python Failed to load script: C:\Program Files\NSClient++\scripts\python\test_all.py c:\source\master\modules\PythonScript\PythonScript.cpp:220 E python close failed in file object destructor: IOError: [Errno 0] Error c:\source\master\modules\PythonScript\script_wrapper.cpp:173

Are there any specifics needed in order to get the other python scripts running or what makes the sample.py special? Are there any users of NSClient++ who has managed to get custom Python scripts running or are most defaulting to external Python.exe?

I am using NSCP-0.5.0.62-x64 on Windows by the way.


#8

I do confirm that the sample python script raises an error and I logged an issue with a workaround here: https://github.com/mickem/nscp/issues/368


#9

Running the script seems to work for me:

[email protected] c:\source\build\x64\dev
$ nscp python execute --script=test_all.py
L     python -+---==(TEST INSTALLER)==---------------------------------------------------+-
L     python  | Setup nessecary configuration for running test                           |
L     python  | This includes: Loading the PythonScript module at startup                |
L     python  | To use this please run nsclient++ in "test mode" like so:                |
L     python  | nscp client --boot --query py_unittest                                   |
L     python -+--------------------------------------------------------==(DAS ENDE!)==---+-

#10

Nope- It doesn’t. There is problem with line in sample.py

reg.submit_metrics(submit_metrics)

If you comment it, script works. If not- there is I/O error. Tested with current version on Windows.

It looks like problem with python wrapper.