Posts for the month of August 2011

New nightly 0.4.0 build as well some som information on distributed monitoring

First off Linux seems to be doing great most features just works and thus far I am pretty impressed with the "portability". I have written a page on how to build on Linux if you want to try it out for your self build/04x/linux.

The new nightly has a lot of new features as well an updated installer with I hope works better. If you have upgraded previously from 0.3.9 I would recommend downgrading/upgrading again as you will most likely have a broken setup. (or you can just upgrade again removing any boot.ini / nsclient.ini fille you may have).

Main highlight is the PythonModule? which now supports many advanced features of NSClient++ (see the included script) as well as some new remote WMI stuff. As I have said before (I hope) one of the main new features of 0.4.x is the distribution so I have started to implement that now and one step there is the new remote WMI checking thingy.

The new remote checking features works like this. First you configure a remote host:

[/settings/targets]
my_test_xp_vm=

[/settings/targets/my_test_xp_vm]
hostname=192.168.0.123
username=\\foobar
password=foobar
protocol=none

Then the idea is that you can run checks on "this host" which will transparently be transported to the other host. Now since NRPE does not support this (natively) we have to fake this using an argument like so:

CheckWMI target=my_test_xp MaxCrit=3 MinWarn=1 "Query:load=Select * from win32_Processor"

But the idea is that in the future you can just do:

nscp_client --target my_test_xp --command CheckWMI  ... 

And this will happen magically using the internal routing (regardless of how nsclient++ needs to do it).

For instance the idea is that the following should be "magically":

<master node> -{NRPE}-> <main emea node> -{SSH}-> <nordics node> -{NSCP}-> <local agent> -{WMI}-> <target>

But this is pretty far down the line so dont expect anything next few days :P

Michael Medin

Linux love!

Yaaay...

mickem@kubuntu-VirtualBox:/mnt/nscp/build/linux$ ./nscp --test
l   /mnt/nscp/trunk/service/NSClient++.cpp:553  Attempting to start
d ttings_manager/settings_manager_impl.cpp:156  No entries found looking in (adding default): /mnt/nscp/build/linux/boot.ini
d ttings_manager/settings_manager_impl.cpp:165  Boot order: old://${exe-path}/nsc.ini, ini://${shared-path}/nsclient.ini
d ttings_manager/settings_manager_impl.cpp:168  Activating: ini://${shared-path}/nsclient.ini
d ttings_manager/settings_manager_impl.cpp:68   Creating instance for: ini://${shared-path}//nsclient.ini
d /trunk/include/settings/settings_ini.hpp:254  Reading INI settings from: /mnt/nscp/build/linux/nsclient.ini
d /trunk/include/settings/settings_ini.hpp:228  Loading: /mnt/nscp/build/linux/nsclient.ini from ini://${shared-path}/nsclient.ini
l   /mnt/nscp/trunk/service/NSClient++.cpp:558  Booted settings subsystem...
e   /mnt/nscp/trunk/service/NSClient++.cpp:641  Warning Not compiled with google breakpad support!
d   /mnt/nscp/trunk/service/NSClient++.cpp:410  Found: PythonScript as 
d   /mnt/nscp/trunk/service/NSClient++.cpp:702  Processing plugin: libPythonScript.so as 
d   /mnt/nscp/trunk/service/NSClient++.cpp:986  addPlugin(/mnt/nscp/build/linux/modules/libPythonScript.so as )
d   /mnt/nscp/trunk/service/NSClient++.cpp:962  Loading plugin: PythonScript...
d nk/modules/PythonScript/PythonScript.cpp:187  Looking for: q
d nk/modules/PythonScript/PythonScript.cpp:187  Looking for: /mnt/nscp/build/linux/scripts/python/q
d nk/modules/PythonScript/PythonScript.cpp:187  Looking for: /mnt/nscp/build/linux/scripts/q
d nk/modules/PythonScript/PythonScript.cpp:187  Looking for: /mnt/nscp/build/linux/python/q
d nk/modules/PythonScript/PythonScript.cpp:187  Looking for: /mnt/nscp/build/linux/q
e nk/modules/PythonScript/PythonScript.cpp:191  Script not found: q
d nk/modules/PythonScript/PythonScript.cpp:187  Looking for: test.py
d nk/modules/PythonScript/PythonScript.cpp:187  Looking for: /mnt/nscp/build/linux/scripts/python/test.py
d nk/modules/PythonScript/PythonScript.cpp:205  Adding script: py (/mnt/nscp/build/linux/scripts/python/test.py)
e /modules/PythonScript/script_wrapper.cpp:12   Hello World
e /modules/PythonScript/script_wrapper.cpp:12   Got it: 
e /modules/PythonScript/script_wrapper.cpp:12   Testing to register a function
l /modules/PythonScript/script_wrapper.cpp:27   Added simple command: py_test to list of: py_test
l /modules/PythonScript/script_wrapper.cpp:27   Added simple command: py_normal to list of: py_normal, py_test
l /modules/PythonScript/script_wrapper.cpp:27   Added simple command: py_nop to list of: py_nop, py_normal, py_test
l /modules/PythonScript/script_wrapper.cpp:27   Added simple command: py_nom to list of: py_nom, py_nop, py_normal, py_test
l /modules/PythonScript/script_wrapper.cpp:27   Added simple command: py_nor to list of: py_nom, py_nop, py_nor, py_normal, py_test
e /modules/PythonScript/script_wrapper.cpp:12   Testing to register settings keys
e /modules/PythonScript/script_wrapper.cpp:12   Testing to get key (nonexistant): 4
e /modules/PythonScript/script_wrapper.cpp:12   Testing to get it (after setting it): 4
e /modules/PythonScript/script_wrapper.cpp:12   Saving configuration...
d   /mnt/nscp/trunk/service/NSClient++.cpp:727  NSClient++ - 0,4,0,83 2011-08-07 Started!
l mnt/nscp/trunk/service/simple_client.hpp:26   Enter command to inject or exit to terminate...
py_test
d   /mnt/nscp/trunk/service/NSClient++.cpp:1106 Injecting: py_test...
e /modules/PythonScript/script_wrapper.cpp:12   inside test
d   /mnt/nscp/trunk/service/NSClient++.cpp:1106 Injecting: py_normal...
e /modules/PythonScript/script_wrapper.cpp:12   inside normal
d   /mnt/nscp/trunk/service/NSClient++.cpp:1136 Result py_normal: OK
d   /mnt/nscp/trunk/service/NSClient++.cpp:1106 Injecting: py_normal...
e /modules/PythonScript/script_wrapper.cpp:12   inside normal
e /modules/PythonScript/script_wrapper.cpp:12    | Got argument: hello
d   /mnt/nscp/trunk/service/NSClient++.cpp:1136 Result py_normal: OK
d   /mnt/nscp/trunk/service/NSClient++.cpp:1106 Injecting: py_normal...
e /modules/PythonScript/script_wrapper.cpp:12   inside normal
e /modules/PythonScript/script_wrapper.cpp:12    | Got argument: hello
e /modules/PythonScript/script_wrapper.cpp:12    | Got argument: world
d   /mnt/nscp/trunk/service/NSClient++.cpp:1136 Result py_normal: OK
d   /mnt/nscp/trunk/service/NSClient++.cpp:1136 Result py_test: OK
l mnt/nscp/trunk/service/simple_client.hpp:12   OK:Tests ok
exit
l mnt/nscp/trunk/service/simple_client.hpp:12   Exiting...
d   /mnt/nscp/trunk/service/NSClient++.cpp:763  Attempting to stop
d   /mnt/nscp/trunk/service/NSClient++.cpp:766  Stopping: NON Message Handling Plugins
d   /mnt/nscp/trunk/service/NSClient++.cpp:916  Unloading plugin: PythonScript...
e /modules/PythonScript/script_wrapper.cpp:12   Unloading script...
d   /mnt/nscp/trunk/service/NSClient++.cpp:794  Stopping: Settings instance
d   /mnt/nscp/trunk/service/NSClient++.cpp:818  Stopping: Message handling Plugins
d   /mnt/nscp/trunk/service/NSClient++.cpp:916  Unloading plugin: PythonScript...
l   /mnt/nscp/trunk/service/NSClient++.cpp:826  Stopped succcessfully
mickem@kubuntu-VirtualBox:/mnt/nscp/build/linux$ uname -a
Linux kubuntu-VirtualBox 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:24 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
mickem@kubuntu-VirtualBox:/mnt/nscp/build/linux$ 

A few issues here and there but at least the python script module is working on Linux :P Tomorrow I am gonna see if I can get NRPE and such up as well... Then I guess it is time to get some third party feedback

UPDATE: NRPE is also working actually:

mickem@kubuntu-VirtualBox:/mnt/nscp/build/linux$ /usr/lib/nagios/plugins/check_nrpe -H localhost -c py_test
Tests ok

Soo... maybe I shall writeup a guide on how to build it?

Michael Medin

  • Posted: 2011-08-10 14:54 (Updated: 2011-08-10 16:04)
  • Categories: 0.4.0 linux
  • Comments (0)

Nagios World Conferance

I will be speaking at Nagios world conference letting you all know whats new in the 0.3.9 version as well as latest news from the 0.4.0 version as well as the usual introduction to windows monitoring. I will also in addition to this give a short workshop on how to write scripts for monitoring windows machines including the all new Python options in 0.4.0.

For details on the Nagios World conference please visit: http://go.nagios.com/conference

Michael Medin

Nightly build with python script module

The first nightly build witch includes the PythonScript module is out. The module has support for most things but still lacks some of the new features of 0.4.x such as channels but that will be added in the near future. I am linking this with python 2.7 which needs to be installed for it to work but I am unsure which versions of python are supported but hopefully a few more (but not I guess 3.0 as it is a "new" version). This is pretty new for me so please let me know anything that does not work in regards to linking and platforms and such. Also note that the x64 versions requires x64 version of python.

Scripts are loaded in the following order:

  1. absolute path
  2. ./scripts/python
  3. ./scripts

So it makes sense to put all python script inside the python folder. The sample script (found inside scripts/python) which looks like this (subject to change):

from NSCP import Settings, Functions, Core, log, status

core = Core.get()

def test(arguments):
	log('inside test')
	for a in arguments:
		log('Got argument: %s'%a)
	(retcode, msg, perf) = core.simple_query("normal", [])
	if msg != "ok got: ":
		return (status.CRITICAL, "Test failed")
	(retcode, msg, perf) = core.simple_query("normal", ["hello"])
	if msg != "ok got: hello":
		return (status.CRITICAL, "Test failed")
	(retcode, msg, perf) = core.simple_query("normal", ["hello", "world"])
	if perf != "'args'=2":
		return (status.CRITICAL, "Test failed: -%s-"%perf)
	return (status.OK, 'Tests ok')

def normal(arguments):
	log('inside normal')
	for a in arguments:
		log(' | Got argument: %s'%a)
	if arguments:
		return (status.OK, 'ok got: %s'%arguments[0], "args=%d; "%len(arguments))
	return (status.OK, 'ok got: ', "args=%d; "%len(arguments))
	
def no_perf(arguments):
	log('inside no_perf')
	for a in arguments:
		log('Got argument: %s'%a)
	return (status.WARNING, 'I am ok')

def no_msg(arguments):
	log('inside no_perf')
	for a in arguments:
		log('Got argument: %s'%a)
	return (1)

def no_ret(arguments):
	log('inside no_perf')
	for a in arguments:
		log('Got argument: %s'%a)
	
def init(alias):
	prefix = 'py_'
	if alias:
		prefix = '%s_'%alias

	log('Hello World')

	conf = Settings.get()
	val = conf.get_string('/modules', 'PythonScript', 'foo')

	log('Got it: %s'%val)
	
	log('Testing to register a function')
	fun = Functions.get()
	fun.register_simple('%stest'%prefix, test, 'This is a sample command')
	fun.register_simple('%snormal'%prefix, normal, 'This is a sample command')
	fun.register_simple('%snop'%prefix, no_perf, 'No performance data')
	fun.register_simple('%snom'%prefix, no_msg, 'No performance data')
	fun.register_simple('%snor'%prefix, no_ret, 'No performance data')

	log('Testing to register settings keys')
	conf.register_path('hello', 'PYTHON SETTINGS', 'This is stuff for python')
	conf.register_key('hello', 'python', 'int', 'KEY', 'This is a key', '42')

	log('Testing to get key (nonexistant): %d' % conf.get_int('hello', 'python', -1))
	conf.set_int('hello', 'python', 4)
	log('Testing to get it (after setting it): %d' % conf.get_int('hello', 'python', -1))

	log('Saving configuration...')
	conf.save()

def shutdown():
	log('Unloading script...')

Necessary configuration to load the sample script:

[/modules]
; PythonScript - PythonScript...
PythonScript=

; A list of scripts available to run from the PythonScript module.
[/settings/python/scripts]
py2=test.py

So as you can see it supports settings (getting/setting/writing) as well as "running other commands" and exposing commands. The main benefit to using python scripts over "normal python scripts" are that they better integrate with other aspects of NSCP.

Michael Medin

  • Posted: 2011-08-08 06:55
  • Categories: (none)
  • Comments (0)

Python scripting!

Hello just a quick status update.

I have been working on the python scripting module last few days and it is starting to come together now so with a bit of luck it will be out in alfa early next week..

Currently my test script looks like this:

from NSCP import Settings, Functions, log
log('Hello World')

conf = Settings.get()
val = conf.get_string('/modules', 'PythonScript', 'foo')

log('Got it: %s'%val)

def test(foox):
	log('inside proc: %s'%foox)

log('Testing to register a function')
fun = Functions.get()
fun.register_simple('py', test, 'This is a sample command')

log('Testing to register settings keys')
conf.register_path('hello', 'PYTHON SETTINGS', 'THis is stuff for python')
conf.register_key('hello', 'python', 'int', 'KEY', 'This is a key', '42')

log('Testing to get key (nonexistant): %d' % conf.get_int('hello', 'python', -1))
conf.set_int('hello', 'python', 4)
log('Testing to get it (after setting it): %d' % conf.get_int('hello', 'python', -1))

log('Saving configuration...')
conf.save()

And the result:

...
d    ..\..\..\trunk\service\NSClient++.cpp:952  Loading plugin: PythonScript...
e nk\modules\PythonScript\PythonScript.cpp:181  Hello World
e nk\modules\PythonScript\PythonScript.cpp:181  Got it: alias
e nk\modules\PythonScript\PythonScript.cpp:181  Testing to register a function
e nk\modules\PythonScript\PythonScript.cpp:181  Testing to register settings keys
e nk\modules\PythonScript\PythonScript.cpp:181  Testing to get key (nonexistant): -1
e nk\modules\PythonScript\PythonScript.cpp:181  Testing to get it (after setting it): 4
e nk\modules\PythonScript\PythonScript.cpp:181  Saving configuration...
d    ..\..\..\trunk\service\NSClient++.cpp:717  NSClient++ - 0,4,0,77 2011-07-06 Started!
l rce\nscp\trunk\service\simple_client.hpp:26   Enter command to inject or exit to terminate...
commands
l rce\nscp\trunk\service\simple_client.hpp:12   Commands:
l rce\nscp\trunk\service\simple_client.hpp:12   | py: This is a sample command
py
d    ..\..\..\trunk\service\NSClient++.cpp:1096 Injecting: py...
e nk\modules\PythonScript\PythonScript.cpp:181  inside proc: py
d    ..\..\..\trunk\service\NSClient++.cpp:1126 Result py: OK
l rce\nscp\trunk\service\simple_client.hpp:12   OK:
...

The resulting settings file looks like this:

...

; THis is stuff for python
[hello]

; KEY - This is a key
python=4
...

So it is looking pretty nice I think. Next thing is to create proper function bindings so you can actually create monitoring scripts using python.

Michael Medin