Beispiel #1
0
def init(pid, plugin_alias, script_alias):
    global world_status, plugin_id
    plugin_id = pid

    conf = Settings.get(plugin_id)
    conf.register_path('/settings/cool script', "Sample script config", "This is a sample script which demonstrates how to interact with NSClient++")
    conf.register_key('/settings/cool script', 'world', 'string', "A key", "Never ever change this key: or the world will break", "safe")

    world_status = conf.get_string('/settings/cool script', 'world', 'true')
    if world_status != 'safe':
        log('My god: its full of stars: %s'%world_status)
    
    log('Adding a simple function/cmd line')
    reg = Registry.get(plugin_id)
    reg.simple_cmdline('help', get_help)

    reg.simple_function('check_world', check_world, 'Check if the world is safe')
    reg.simple_function('break_world', break_world, 'Break the world')
    reg.simple_function('fix_world', fix_world, 'Fix the world')
    reg.simple_function('save_world', save_world, 'Save the world')
    
    reg.simple_function('show_metrics', fun_show_metrics, 'Enable displaying metrics or not')

    reg.submit_metrics(submit_metrics)
    reg.fetch_metrics(fetch_metrics)
Beispiel #2
0
	def setup(self, plugin_id, prefix):
		self.reg = Registry.get(plugin_id)
		self.reg.simple_function(self.command, StressTest.random_check_handler, 'This is a simple noop command')
		self.reg.simple_subscription(self.python_channel, StressTest.on_stress_handler)
		conf = Settings.get()
		conf.set_string(self.sched_base_path, 'threads', '%d'%use_threads)
		core.reload(self.sched_alias)
Beispiel #3
0
    def init(self, plugin_id, prefix):
        self.key = '_%stest_command' % prefix
        self.reg = Registry.get(plugin_id)
        self.core = Core.get(plugin_id)
        self.conf = Settings.get(plugin_id)

        None
Beispiel #4
0
 def setup(self, plugin_id, prefix):
     self.reg = Registry.get(plugin_id)
     self.temp_path = self.core.expand_path('${temp}')
     log('Temp: %s' % self.temp_path)
     self.work_path = os.path.join(self.temp_path, '%s' % uuid.uuid4())
     log('Work: %s' % self.work_path)
     os.mkdir(self.work_path)
Beispiel #5
0
 def setup(self, plugin_id, prefix):
     self.key = '_%stest_command' % prefix
     self.reg = Registry.get(plugin_id)
     self.reg.simple_subscription('pytest_evlog_01',
                                  EventLogTest.simple_inbox_handler_01)
     self.reg.simple_subscription('pytest_evlog_02',
                                  EventLogTest.simple_inbox_handler_02)
Beispiel #6
0
 def setup(self, plugin_id, prefix):
     self.reg = Registry.get(plugin_id)
     self.temp_path = self.core.expand_path("${temp}")
     log("Temp: %s" % self.temp_path)
     self.work_path = os.path.join(self.temp_path, "%s.txt" % uuid.uuid4())
     log("Work: %s" % self.work_path)
     create_test_data(self.work_path)
Beispiel #7
0
	def init(self, plugin_id, prefix):
		self.key = '_%stest_command'%prefix
		self.reg = Registry.get(plugin_id)
		self.core = Core.get(plugin_id)
		self.conf = Settings.get(plugin_id)

		None
Beispiel #8
0
	def setup(self, plugin_id, prefix):
		self.reg = Registry.get(plugin_id)
		self.temp_path = self.core.expand_path('${temp}')
		log('Temp: %s'%self.temp_path)
		self.work_path = os.path.join(self.temp_path, '%s.txt'%uuid.uuid4())
		log('Work: %s'%self.work_path)
		create_test_data(self.work_path)
Beispiel #9
0
def init(pid, plugin_alias, script_alias):
    global plugin_id, icinga_url, icinga_auth, path
    plugin_id = pid

    core = Core.get(plugin_id)
    path = core.expand_path("${module-path}")

    conf = Settings.get(plugin_id)
    conf.register_path(
        '/settings/remote-modules', "Remote module",
        "Keys for the remote-modules module which handles downloading remote modules on demand"
    )
    conf.register_path(
        '/settings/remote-modules/modules', "Remote modules",
        "A list of remote modules to fetch the key is not used.")

    reg = Registry.get(plugin_id)
    reg.simple_function('remote_module_update', update,
                        'Update all or one remote module')

    for mod in conf.get_section('/settings/remote-modules/modules'):
        url = conf.get_string('/settings/remote-modules/modules', mod, '')
        log("Adding module %s as %s" % (mod, url))
        conf.register_key('/settings/remote-modules/modules', mod, 'string',
                          "A remote module to fetch",
                          "A remote module to fetch", "")
    if not update_modules():
        log_error("Failed to update modules")
    else:
        enable_modules()
Beispiel #10
0
def init(pid, plugin_alias, script_alias):
    global server_name, plugin_id, icinga_url, icinga_auth
    plugin_id = pid
    server_name = socket.gethostname()

    reg = Registry.get(plugin_id)
    core = Core.get(plugin_id)
    reg.event('name', on_event)
    reg.submit_metrics(submit_metrics)
    
    conf = Settings.get(plugin_id)
    conf.register_key('/settings/icinga', 'url', 'string', "The URL of the icinga API port", "The icinga base for the api: https://icinga.com:5665", "")
    conf.register_key('/settings/icinga', 'user', 'string', "The user id of the icinga API", "The icinga API user: root", "")
    conf.register_key('/settings/icinga', 'password', 'string', "The user id of the icinga API", "The icinga API password: hopefully not icinga", "")
    
    icinga_url = conf.get_string('/settings/icinga', 'url', '')
    usr = conf.get_string('/settings/icinga', 'user', '')
    pwd = conf.get_string('/settings/icinga', 'password', '')
    icinga_auth = requests.auth.HTTPBasicAuth(usr, pwd)
    
    (res, os_version, perf) = core.simple_query('check_os_version', ["top-syntax=${list}"])
    add_host(server_name, socket.gethostbyname(server_name), os_version)
    add_nrpe_service(server_name, 'check_cpu', 'check_cpu', 'CPU Load')
    add_nrpe_service(server_name, 'check_memory', 'check_memory', 'CPU Load')

    for k in ['check_cpu', 'check_memory']:
        conf.set_string('/settings/scheduler/schedules/%s'%k, 'command', k)
        conf.set_string('/settings/scheduler/schedules/%s'%k, 'channel', 'icinga_passive')
        conf.set_string('/settings/scheduler/schedules/%s'%k, 'interval', '30s')
    core.load_module('Scheduler', '')

    reg.simple_subscription('icinga_passive', icinga_passive)
Beispiel #11
0
	def setup(self, plugin_id, prefix):
		self.reg = Registry.get(plugin_id)
		self.temp_path = core.expand_path('${temp}')
		log('Temp: %s'%self.temp_path)
		self.work_path = os.path.join(self.temp_path, '%s'%uuid.uuid4())
		log('Work: %s'%self.work_path)
		os.mkdir(self.work_path)
Beispiel #12
0
 def __init__(self, plugin_id, plugin_alias, script_alias):
     self.plugin_id = plugin_id
     self.plugin_alias = plugin_alias
     self.script_alias = script_alias
     self.conf = Settings.get(self.plugin_id)
     self.registry = Registry.get(self.plugin_id)
     self.core = Core.get(self.plugin_id)
Beispiel #13
0
	def __init__(self, plugin_id, plugin_alias, script_alias):
		self.plugin_id = plugin_id
		self.plugin_alias = plugin_alias
		self.script_alias = script_alias
		self.conf = Settings.get(self.plugin_id)
		self.registry = Registry.get(self.plugin_id)
		self.core = Core.get(self.plugin_id)
Beispiel #14
0
def init(pid, plugin_alias, script_alias):
    global world_status, plugin_id
    plugin_id = pid

    conf = Settings.get(plugin_id)
    conf.register_path(
        '/settings/cool script', "Sample script config",
        "This is a sample script which demonstrates how to interact with NSClient++"
    )
    conf.register_key('/settings/cool script', 'world', 'string', "A key",
                      "Never ever change this key: or the world will break",
                      "safe")

    world_status = conf.get_string('/settings/cool script', 'world', 'true')
    if world_status != 'safe':
        log('My god: its full of stars: %s' % world_status)

    log('Adding a simple function/cmd line')
    reg = Registry.get(plugin_id)
    reg.simple_cmdline('help', get_help)

    reg.simple_function('check_world', check_world,
                        'Check if the world is safe')
    reg.simple_function('break_world', break_world, 'Break the world')
    reg.simple_function('fix_world', fix_world, 'Fix the world')
    reg.simple_function('save_world', save_world, 'Save the world')

    reg.simple_function('show_metrics', fun_show_metrics,
                        'Enable displaying metrics or not')

    reg.submit_metrics(submit_metrics)
    reg.fetch_metrics(fetch_metrics)
Beispiel #15
0
 def setup(self, plugin_id, prefix):
     self.channel = '_%stest_channel' % prefix
     self.reg = Registry.get(plugin_id)
     self.reg.simple_subscription('%s_001' % self.channel,
                                  ChannelTest.test_submission_handler_001)
     self.reg.simple_function('%s_001' % self.channel,
                              ChannelTest.test_command_handler_001,
                              'This is a sample command')
Beispiel #16
0
 def __init__(self, plugin_id, plugin_alias, script_alias):
     self.plugin_id = plugin_id
     self.plugin_alias = plugin_alias
     self.script_alias = script_alias
     self.conf = Settings.get(self.plugin_id)
     self.registry = Registry.get(self.plugin_id)
     self.core = Core.get(self.plugin_id)
     self.command_cache = {}
     self.folder = None
Beispiel #17
0
 def setup(self, plugin_id, prefix):
     self.reg = Registry.get(plugin_id)
     self.reg.simple_function(self.command, StressTest.random_check_handler,
                              'This is a simple noop command')
     self.reg.simple_subscription(self.python_channel,
                                  StressTest.on_stress_handler)
     conf = Settings.get()
     conf.set_string(self.sched_base_path, 'threads', '%d' % use_threads)
     core.reload(self.sched_alias)
Beispiel #18
0
 def __init__(self, plugin_id, plugin_alias, script_alias):
     self.plugin_id = plugin_id
     self.plugin_alias = plugin_alias
     self.script_alias = script_alias
     self.conf = Settings.get(self.plugin_id)
     self.registry = Registry.get(self.plugin_id)
     self.core = Core.get(self.plugin_id)
     self.command_cache = {}
     self.folder = None
Beispiel #19
0
	def setup(self, plugin_id, prefix):
		log('Loading Python unit tests')
		self.key = '_%stest_command'%prefix
		self.reg = Registry.get(plugin_id)
		self.reg.simple_function('py_stress_noop', PythonTest.noop_handler, 'This is a simple noop command')
		self.reg.simple_subscription('py_stress_test', PythonTest.stress_handler)
		conf = Settings.get()
		conf.set_string('/settings/test_scheduler', 'threads', '50')
		core.reload('test_scheduler')
Beispiel #20
0
def create_test_manager(plugin_id=0, plugin_alias="", script_alias=""):
    global test_manager
    if not test_manager:
        test_manager = TestManager(plugin_id, plugin_alias, script_alias)

        reg = Registry.get(plugin_id)

        reg.simple_cmdline("help", display_help)
        reg.simple_cmdline("install_python_test", install_tests)
        reg.simple_cmdline("run_python_test", run_tests)

        reg.simple_function("py_unittest", run_tests, "Run python unit test suite")

    return test_manager
Beispiel #21
0
def create_test_manager(plugin_id = 0, plugin_alias = '', script_alias = ''):
	global test_manager
	if not test_manager:
		test_manager = TestManager(plugin_id, plugin_alias, script_alias)
		
		reg = Registry.get(plugin_id)
		
		reg.simple_cmdline('help', display_help)
		reg.simple_cmdline('install_python_test', install_tests)
		reg.simple_cmdline('run_python_test', run_tests)

		reg.simple_function('py_unittest', run_tests, 'Run python unit test suite')
	
	return test_manager
Beispiel #22
0
def create_test_manager(plugin_id = 0, plugin_alias = '', script_alias = ''):
	global test_manager
	if not test_manager:
		test_manager = TestManager(plugin_id, plugin_alias, script_alias)
		
		reg = Registry.get(plugin_id)
		
		reg.simple_cmdline('help', display_help)
		reg.simple_cmdline('install_python_test', install_tests)
		reg.simple_cmdline('run_python_test', run_tests)

		reg.simple_function('py_unittest', run_tests, 'Run python unit test suite')
	
	return test_manager
Beispiel #23
0
def create_test_manager(plugin_id = 0, plugin_alias = '', script_alias = ''):
    global test_manager
    if not test_manager:
        test_manager = TestManager(plugin_id, plugin_alias, script_alias)
        
        reg = Registry.get(plugin_id)
        
        reg.simple_cmdline('help', display_help)
        reg.simple_cmdline('install_python_test', install_tests)
        reg.simple_cmdline('run_python_test', run_tests)

        reg.simple_function('py_unittest', run_tests, 'Run python unit test suite')
        reg.simple_function('py_unittest_show_ok', set_show_ok, 'Set verbouse log')
        reg.simple_function('py_unittest_add_case', add_case, 'Set which cases to run')
    
    return test_manager
Beispiel #24
0
def init(pid, plugin_alias, script_alias):
	global prefix
	global plugin_id
	plugin_id = pid
	if script_alias:
		prefix = '%s_'%script_alias

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

	#log('Got it: %s'%val)
	
	log('Testing to register a function')
	reg = Registry.get(plugin_id)
	
	reg.simple_cmdline('help', get_help)
	reg.simple_cmdline('install_python_test', install_test)

	reg.simple_function('%stest'%prefix, test, 'Run python unittest')
Beispiel #25
0
 def init(self, plugin_id, prefix):
     self.plugin_id = plugin_id
     self.reg = Registry.get(plugin_id)
     self.core = Core.get(plugin_id)
     self.conf = Settings.get(plugin_id)
Beispiel #26
0
	def setup(self, plugin_id, prefix):
		self.key = '_%stest_command'%prefix
		self.reg = Registry.get(plugin_id)
		self.reg.simple_subscription('nsca_test_inbox', NSCAServerTest.simple_inbox_handler)
		self.reg.subscription('nsca_test_inbox', NSCAServerTest.inbox_handler)
Beispiel #27
0
	def setup(self, plugin_id, prefix):
		self.key = '_%stest_command'%prefix
		self.reg = Registry.get(plugin_id)
		self.reg.simple_function('%s_001'%self.key, CommandTest.test_command_handler_001, 'This is a sample command')
Beispiel #28
0
 def setup(self, plugin_id, prefix):
     self.reg = Registry.get(plugin_id)
Beispiel #29
0
 def init(self, plugin_id, prefix):
     self.reg = Registry.get(plugin_id)
     self.core = Core.get(plugin_id)
     self.conf = Settings.get(plugin_id)
Beispiel #30
0
	def setup(self, plugin_id, prefix):
		self.key = '_%stest_command'%prefix
		self.reg = Registry.get(plugin_id)
Beispiel #31
0
	def setup(self, plugin_id, prefix):
		self.channel = '_%stest_channel'%prefix
		self.reg = Registry.get(plugin_id)
		self.reg.simple_subscription(self.channel, ChannelTest.test_submission_handler_001)
		self.reg.simple_function(self.channel, ChannelTest.test_command_handler_001, 'This is a sample command')
Beispiel #32
0
 def setup(self, plugin_id, prefix):
     self.key = '_%stest_command' % prefix
     self.reg = Registry.get(plugin_id)
     self.reg.simple_subscription('nsca_test_inbox',
                                  NSCAServerTest.simple_inbox_handler)
     self.reg.subscription('nsca_test_inbox', NSCAServerTest.inbox_handler)
Beispiel #33
0
	def setup(self, plugin_id, prefix):
		self.key = '_%stest_command'%prefix
		self.reg = Registry.get(plugin_id)
		self.reg.simple_function('check_py_nscp_test_s', NSCPServerTest.simple_handler, 'TODO')
		self.reg.function('check_py_nscp_test', NSCPServerTest.handler, 'TODO')
 def setup(self, plugin_id, prefix):
     self.key = '_%stest_command' % prefix
     self.reg = Registry.get(plugin_id)
Beispiel #35
0
	def setup(self, plugin_id, prefix):
		self.reg = Registry.get(plugin_id)
Beispiel #36
0
 def setup(self, plugin_id, prefix):
     self.key = '_%stest_command' % prefix
     self.reg = Registry.get(plugin_id)
     self.reg.simple_function('check_py_nscp_test_s',
                              NSCPServerTest.simple_handler, 'TODO')
     self.reg.function('check_py_nscp_test', NSCPServerTest.handler, 'TODO')
Beispiel #37
0
	def setup(self, plugin_id, prefix):
		self.key = '_%stest_command'%prefix
		self.reg = Registry.get(plugin_id)
		self.reg.simple_subscription('pytest_evlog', EventLogTest.simple_inbox_handler)