source: nscp/scripts/python/test.py @ 39c73cd

0.4.00.4.10.4.2
Last change on this file since 39c73cd was 39c73cd, checked in by Michael Medin <michael@…>, 22 months ago

2011-08-13 MickeM

  • Added support for command line execution to PythonScript module
  • Readded support for specifying module on command line with --client mode
  • Fixed some issues with the NRPEClient module


2011-08-12 MickeM

  • Finnished (rough) adding back command line exec (with modern API)
  • Fixed so installer uses correct name for dll:s (now Server not Listsener)
  • Property mode set to 100644
File size: 2.4 KB
Line 
1from NSCP import Settings, Functions, Core, log, status
2
3core = Core.get()
4
5
6def get_help(arguments):
7        return (status.OK, 'help: Get help')
8
9prefix = 'py_'
10def test(arguments):
11        log('inside test')
12        for a in arguments:
13                log('Got argument: %s'%a)
14        (retcode, msg, perf) = core.simple_query("%snormal"%prefix, [])
15        if msg != "ok got: ":
16                return (status.CRITICAL, "Test failed")
17        (retcode, msg, perf) = core.simple_query("%snormal"%prefix, ["hello"])
18        if msg != "ok got: hello":
19                return (status.CRITICAL, "Test failed")
20        (retcode, msg, perf) = core.simple_query("%snormal"%prefix, ["hello", "world"])
21        if perf != "'args'=2":
22                return (status.CRITICAL, "Test failed: -%s-"%perf)
23        return (status.OK, 'Tests ok')
24
25def normal(arguments):
26        log('inside normal')
27        for a in arguments:
28                log(' | Got argument: %s'%a)
29        if arguments:
30                return (status.OK, 'ok got: %s'%arguments[0], "args=%d; "%len(arguments))
31        return (status.OK, 'ok got: ', "args=%d; "%len(arguments))
32       
33def no_perf(arguments):
34        log('inside no_perf')
35        for a in arguments:
36                log('Got argument: %s'%a)
37        return (status.WARNING, 'I am ok')
38
39def no_msg(arguments):
40        log('inside no_perf')
41        for a in arguments:
42                log('Got argument: %s'%a)
43        return (1)
44
45def no_ret(arguments):
46        log('inside no_perf')
47        for a in arguments:
48                log('Got argument: %s'%a)
49       
50def init(alias):
51        if alias:
52                prefix = '%s_'%alias
53
54        log('Hello World')
55
56        conf = Settings.get()
57        val = conf.get_string('/modules', 'PythonScript', 'foo')
58
59        log('Got it: %s'%val)
60       
61        log('Testing to register a function')
62        fun = Functions.get()
63        fun.register_simple('%stest'%prefix, test, 'This is a sample command')
64        fun.register_simple('%snormal'%prefix, normal, 'This is a sample command')
65        fun.register_simple('%snop'%prefix, no_perf, 'No performance data')
66        fun.register_simple('%snom'%prefix, no_msg, 'No performance data')
67        fun.register_simple('%snor'%prefix, no_ret, 'No performance data')
68
69        fun.simple_cmdline('help', get_help)
70
71        log('Testing to register settings keys')
72        conf.register_path('hello', 'PYTHON SETTINGS', 'This is stuff for python')
73        conf.register_key('hello', 'python', 'int', 'KEY', 'This is a key', '42')
74
75        log('Testing to get key (nonexistant): %d' % conf.get_int('hello', 'python', -1))
76        conf.set_int('hello', 'python', 4)
77        log('Testing to get it (after setting it): %d' % conf.get_int('hello', 'python', -1))
78
79        log('Saving configuration...')
80        conf.save()
81
82def shutdown():
83        log('Unloading script...')
Note: See TracBrowser for help on using the repository browser.