Run a check command inside a python script


#1

Hi,

I want to call a check command inside a python script. I first thought to call the REST api using the requests package but I think it would be better to use NSCP.core but I’m not sure how to do that.

When I use:

   core = Core.get(plugin_id)
	cpu_result = core.simple_query('check_cpu',arguments)
	print cpu_result

But it gives me the following error:

C:\Program Files\NSClient++>nscp py execute --script=test_python_cyrille
UENKNOWN    Unknown command(s): check_cpu
 core Unknown command(s): checkcpu available commands: commands {}, plugins {, 0}
                    c:\source\master\service\NSClient++.cpp:814

I didn’t find a lot of information on how to use the nscp package in python.

Thanks


#2

OK, I needed to load the necessary modules first:

def init(pid, plugin_alias, script_alias):
	global plugin_id, core
	plugin_id = pid
	#load necessary modules
	core = Core.get(plugin_id)
	core.load_module('CheckSystem','') 
	core.load_module('CheckDisk','') 
	check_cpu([])

Now I’m wondering if It is possible to get the result of the check command as JSON