Пример #1
0
 def test_w_expected(self, filter, syntax, expected):
     result = TestResult('Validating filter: %s' % filter)
     (res, msg, perf) = Core.get().simple_query('CheckEventLog', [
         'file=Application', 'debug=true',
         'warn=ne:%d' % expected,
         'crit=ne:%d' % expected,
         'filter=%s' % filter,
         'syntax=%s' % syntax
     ])
     result.assert_equals(res, status.OK,
                          "Validate status OK for %s" % filter)
     (res, msg, perf) = Core.get().simple_query('CheckEventLog', [
         'file=Application', 'debug=true',
         'warn=eq:%d' % expected,
         'crit=ne:%d' % expected,
         'filter=%s' % filter,
         'syntax=%s' % syntax
     ])
     result.assert_equals(res, status.WARNING,
                          "Validate status OK for %s" % filter)
     (res, msg, perf) = Core.get().simple_query('CheckEventLog', [
         'file=Application', 'debug=true',
         'warn=eq:%d' % expected,
         'crit=eq:%d' % expected,
         'filter=%s' % filter,
         'syntax=%s' % syntax
     ])
     result.assert_equals(res, status.CRITICAL,
                          "Validate status CRIT for %s" % filter)
     return result
Пример #2
0
	def test_w_expected(self, filter, syntax, expected):
		result = TestResult('Validating filter: %s'%filter)
		(res, msg, perf) = Core.get().simple_query('CheckEventLog', ['file=Application', 'debug=true', 'warn=ne:%d'%expected, 'crit=ne:%d'%expected, 'filter=%s'%filter, 'syntax=%s'%syntax])
		result.assert_equals(res, status.OK, "Validate status OK for %s"%filter)
		(res, msg, perf) = Core.get().simple_query('CheckEventLog', ['file=Application', 'debug=true', 'warn=eq:%d'%expected, 'crit=ne:%d'%expected, 'filter=%s'%filter, 'syntax=%s'%syntax])
		result.assert_equals(res, status.WARNING, "Validate status OK for %s"%filter)
		(res, msg, perf) = Core.get().simple_query('CheckEventLog', ['file=Application', 'debug=true', 'warn=eq:%d'%expected, 'crit=eq:%d'%expected, 'filter=%s'%filter, 'syntax=%s'%syntax])
		result.assert_equals(res, status.CRITICAL, "Validate status CRIT for %s"%filter)
		return result
Пример #3
0
	def run_test(self):
		result = TestResult('Checking CheckEventLog')
		cache = TestResult('Checking CheckEventLog CACHE')
		
		(res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE', ['warn=eq:1', 'crit=eq:2'])
		cache.assert_equals(res, status.OK, "Validate cache is empty")
		cache.assert_equals(msg, 'Eventlog check ok', "Validate cache is ok: %s"%msg)
		
		
		a_list = ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
		result.add_message(self.test_create('Application Error', 1000, 'error', 0, 0, 0, a_list), 'Testing to create a log message')
		sleep(500)
		result.assert_equals(self.last_message, 'error Application Error: ', 'Verify that message is sent through')
		result.assert_equals(self.message_count, 1, 'Verify that onlyt one message is sent through')

		result.add_message(self.test_create('Application Error', 1000, 'info', 2, 1, 5, a_list), 'Testing to create a log message')
		sleep(500)
		result.assert_equals(self.last_message, 'info Application Error: ', 'Verify that message is sent through')
		result.assert_equals(self.message_count, 1, 'Verify that onlyt one message is sent through')

		(res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE', ['warn=eq:1', 'crit=eq:2'])
		cache.assert_equals(res, status.CRITICAL, "Validate cache has items")
		cache.assert_equals(msg, 'error Application Error: , info Application Error: , eventlog: 2 = critical', "Validate cache is ok: %s"%msg)
		cache.assert_equals(perf, "'eventlog'=2;1;2", "Validate cache is ok: %s"%msg)
		(res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE', ['warn=eq:1', 'crit=eq:2'])
		cache.assert_equals(res, status.OK, "Validate cache is empty (again)")
		cache.assert_equals(msg, 'Eventlog check ok', "Validate cache is ok: %s"%msg)
		
		result.add(cache)
		
		r = TestResult('Checking filters')
		r.add(self.test_w_expected('id = 1000 and generated gt 1m', '%generated%', 0))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m', '%generated%', 2))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m and id = 1000', '%generated%: %id%, %category%', 2))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m and category = 1', '%category%', 1))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m and category = 0', '%category%', 1))
		r.add(self.test_w_expected("id = 1000 and generated gt -1m and level = 'error'", '%level%', 1))
		r.add(self.test_w_expected("id = 1000 and generated gt -1m and level = 'info'", '%level%', 1))
		result.add(r)
		
		r = TestResult('Checking syntax')
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%source% - %type% - %category%', 'Application Error - error - 0'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%source% - %type% - %category%', 'Application Error - info - 1'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%facility% - %qualifier% - %customer%', '0 - 0 - 0'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%facility% - %qualifier% - %customer%', '5 - 5 - 0'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%rawid% - %severity% - %log%', '1000 - success - Application'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%rawid% - %severity% - %log%', '2147812328 - warning - Application'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%id% - %strings%', '1000 - a, a, a, a, a, a, a, a, a, a, a, a, a, '))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%id% - %strings%', '1000 - a, a, a, a, a, a, a, a, a, a, a, a, a, '))
		result.add(r)

		return result
Пример #4
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
Пример #5
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)
Пример #6
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
Пример #7
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)
Пример #8
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)
Пример #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()
Пример #10
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
Пример #11
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
Пример #12
0
def submit_metrics(list, request):
    global plugin_id
    found = False
    for k, v in list.iteritems():
        if k.startswith('system.network') and k.endswith('NetConnectionID'):
            if found_nic(k[15:-16], v):
                found = True
    if found:
        core = Core.get(plugin_id)
        core.reload('Scheduler')
Пример #13
0
 def test_syntax(self, filter, syntax, expected):
     result = TestResult('Validating syntax: %s' % syntax)
     (res, msg, perf) = Core.get().simple_query('CheckEventLog', [
         'file=Application', 'warn=ne:1',
         'filter=%s' % filter,
         'syntax=%s' % syntax, 'descriptions'
     ])
     result.assert_equals(msg, expected,
                          "Validate message rendering syntax: %s" % msg)
     return result
Пример #14
0
def enable_modules(module=None):
    ret = False
    conf = Settings.get(plugin_id)
    core = Core.get(plugin_id)
    for mod in conf.get_section('/settings/remote-modules/modules'):
        if module and not mod == module:
            continue
        url = conf.get_string('/settings/remote-modules/modules', mod, '')
        file = get_module_name(url)
        log("Loading module %s" % file)
        core.load_module(file, "")
    return ret
Пример #15
0
	def test_create(self, source, id, level, severity, category, facility, arguments):
		args = ['--source', source, 
					'--id', id,				# Any number (corresponds with message identifier)								-- Identifies message
					'--level', level,		# error(1), warning(2), success(0), info(4), auditSuccess(8), auditFailure(10)	-- Loglevel severity (ie log level)
					'--severity', severity,	# success(0), informational(1), warning(2), error(3) 							-- Developer severity (ie classification)
					'--category', category,	#
					'--facility', facility	#
					]
		for f in arguments:
			args.append('--argument')
			args.append(f)
		(ret, msg) = Core.get().simple_exec('any', 'insert-eventlog', args)
		return ret == 0
Пример #16
0
def __main__(args):
    global plugin_id
    # List all namespaces recursivly
    core = Core.get(plugin_id)
    (ret, ns_msgs) = core.simple_exec('CheckWMI', 'wmi', ['--list-all-ns'])
    if len(ns_msgs) == 0:
        log_error("Failed to execute WMI command is CheckWMI enabled?")
    else:
        for ns in ns_msgs[0].splitlines():
            # List all classes in each namespace
            (ret, cls_msgs) = core.simple_exec('any', 'wmi', ['--list-classes', '--simple', '--namespace', ns])
            for cls in cls_msgs[0].splitlines():
                log( '%s : %s'%(ns, cls))
Пример #17
0
def __main__(args):
    global plugin_id
    # List all namespaces recursivly
    core = Core.get(plugin_id)
    (ret, ns_msgs) = core.simple_exec('CheckWMI', 'wmi', ['--list-all-ns'])
    if len(ns_msgs) == 0:
        log_error("Failed to execute WMI command is CheckWMI enabled?")
    else:
        for ns in ns_msgs[0].splitlines():
            # List all classes in each namespace
            (ret, cls_msgs) = core.simple_exec(
                'any', 'wmi',
                ['--list-classes', '--simple', '--namespace', ns])
            for cls in cls_msgs[0].splitlines():
                log('%s : %s' % (ns, cls))
Пример #18
0
	def test_create(self, source, id, level, severity, category, facility, arguments):
		self.last_message = None
		self.message_count = 0
		args = ['--source', source, 
					'--id', id,
					'--level', level,
					'--severity', severity,
					'--category', category,
					'--facility', facility
					]
		for f in arguments:
			args.append('--argument')
			args.append(f)
		(ret, msg) = Core.get().simple_exec('any', 'insert-eventlog', args)
		return ret == 0
Пример #19
0
def init(plugin_id, plugin_alias, script_alias):

    conf = Settings.get(plugin_id)
    if conf.get_string('/settings/icamp', 'configured', 'false') == 'false':
        conf.set_string('/settings/icamp', 'configured', 'true')

        conf.set_string('/modules', 'GraphiteClient', 'enabled')
        conf.set_string('/modules', 'Scheduler', 'enabled')
        conf.set_string('/modules', 'CheckSystem', 'enabled')
        conf.set_string('/modules', 'ElasticClient', 'enabled')
        conf.set_string('/modules', 'CheckEventlog', 'enabled')

        conf.set_string('/settings/graphite/client/targets/default', 'host',
                        '127.0.0.1')

        conf.set_string('/settings/scheduler/schedules/default', 'interval',
                        '5s')
        conf.set_string('/settings/scheduler/schedules/default', 'channel',
                        'graphite')
        conf.set_string('/settings/scheduler/schedules', 'cpu', 'check_cpu')

        conf.set_string('/settings/elastic/client', 'address',
                        'http://127.0.0.1:9200/_bulk')
        conf.set_string('/settings/elastic/client', 'events',
                        'eventlog:errors,system.process:notepad')

        conf.set_string('/settings/eventlog/real-time', 'enabled', 'true')
        conf.set_string('/settings/eventlog/real-time/filters/errors', 'log',
                        'application')
        conf.set_string('/settings/eventlog/real-time/filters/errors',
                        'destination', 'events')
        conf.set_string('/settings/eventlog/real-time/filters/errors',
                        'filter', "level='error'")

        conf.set_string('/settings/system/windows/real-time/process/notepad',
                        'process', "notepad.exe")
        conf.set_string('/settings/system/windows/real-time/process/notepad',
                        'filter', "new = 1")
        conf.set_string('/settings/system/windows/real-time/process/notepad',
                        'destination', "events")
        conf.save()

        core = Core.get(plugin_id)
        core.reload('service')
Пример #20
0
	def test_simple(self, command, code, message, perf, tag):
		result = TestResult()
		core = Core.get()
		self.reset_last()
		(ret, msg) = core.simple_submit(self.channel, '%s'%command, code, '%s'%message, '%s'%perf)
		result.add_message(ret, 'Testing channels: %s'%tag, msg)
		r1 = TestResult()
		r1.assert_equals(self.last_status, code, 'Return code')
		r1.assert_equals(self.last_message, message, 'Message')
		r1.assert_equals(self.last_perf, perf, 'Performance data')
		result.add(r1)
		
		self.set_last('', '', code, message, perf)
		(retcode, retmessage, retperf) = core.simple_query(self.channel, [])
		result.add_message(True, 'Testing queries: %s'%tag)
		r2 = TestResult()
		r2.assert_equals(self.last_status, code, 'Return code')
		r2.assert_equals(self.last_message, message, 'Message')
		r2.assert_equals(self.last_perf, perf, 'Performance data')
		result.add(r2)
		return result
Пример #21
0
 def test_create(self, source, id, level, severity, category, facility,
                 arguments):
     args = [
         '--source',
         source,
         '--id',
         id,  # Any number (corresponds with message identifier)								-- Identifies message
         '--level',
         level,  # error(1), warning(2), success(0), info(4), auditSuccess(8), auditFailure(10)	-- Loglevel severity (ie log level)
         '--severity',
         severity,  # success(0), informational(1), warning(2), error(3) 							-- Developer severity (ie classification)
         '--category',
         category,  #
         '--facility',
         facility  #
     ]
     for f in arguments:
         args.append('--argument')
         args.append(f)
     (ret, msg) = Core.get().simple_exec('any', 'insert-eventlog', args)
     return ret == 0
Пример #22
0
	def test_simple(self, command, code, message, perf, tag):
		result = TestResult()
		core = Core.get()
		self.reset_last()
		(ret, msg) = core.simple_submit(self.channel, '%s'%command, code, '%s'%message, '%s'%perf)
		result.add_message(ret, 'Testing channels: %s'%tag, msg)
		r1 = TestResult()
		r1.assert_equals(self.last_status, code, 'Return code')
		r1.assert_equals(self.last_message, message, 'Message')
		r1.assert_equals(self.last_perf, perf, 'Performance data')
		result.add(r1)
		
		self.set_last('', '', code, message, perf)
		(retcode, retmessage, retperf) = core.simple_query(self.channel, [])
		result.add_message(True, 'Testing queries: %s'%tag)
		r2 = TestResult()
		r2.assert_equals(self.last_status, code, 'Return code')
		r2.assert_equals(self.last_message, message, 'Message')
		r2.assert_equals(self.last_perf, perf, 'Performance data')
		result.add(r2)
		return result
Пример #23
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)
Пример #24
0
	def run_test(self):
		result = TestResult('Checking CheckEventLog')
		cache = TestResult('Checking CheckEventLog CACHE')
		
		(res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE', ['warn=eq:1', 'crit=eq:2'])
		cache.assert_equals(res, status.OK, "Validate cache is empty")
		cache.assert_equals(msg, 'Eventlog check ok', "Validate cache is ok: %s"%msg)
		
		
		a_list = ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
		result.add_message(self.test_create('Application Error', 1000, 'error', 	'success', 			0, 0, a_list), 'Testing to create a log message')
		result.add_message(self.test_create('Application Error', 1000, 'warning',  	'informational', 	1, 5, a_list), 'Testing to create a log message')
		result.add_message(self.test_create('Application Error', 1000, 'success',  	'warning', 			2, 5, a_list), 'Testing to create a log message')
		result.add_message(self.test_create('Application Error', 1000, 'info',		'error', 			3, 5, a_list), 'Testing to create a log message')
		for x in range(1,10):
			sleep(100)
			if len(self.messages) == 4:
				break
		log('Recieved %d messages.'%len(self.messages))
		result.assert_equals(len(self.messages), 4, 'Verify that all 4 messages are sent through')
		
		for msg in self.messages:
			if msg.message.startswith('X1'):
				r = TestResult('Validating message X1')
				r.assert_equals(msg.message, 'X1 warning Application Error: ', 'Verify message')
				r.assert_equals(msg.channel, 'pytest_evlog_01', 'Verify channel')
				r.assert_equals(msg.tag, '001', 'Verify tag')
				r.assert_equals(msg.status, status.WARNING, 'Verify status')
				result.add(r)
			elif msg.message.startswith('X2'):
				r = TestResult('Validating message X2')
				r.assert_equals(msg.message, 'X2 success Application Error: ', 'Verify message')
				r.assert_equals(msg.channel, 'pytest_evlog_02', 'Verify channel')
				r.assert_equals(msg.tag, '002', 'Verify tag')
				r.assert_equals(msg.status, status.CRITICAL, 'Verify status')
				result.add(r)
			elif msg.message.startswith('X3'):
				r = TestResult('Validating message X3')
				r.assert_equals(msg.message, 'X3 info Application Error: ', 'Verify message')
				r.assert_equals(msg.channel, 'pytest_evlog_01', 'Verify channel')
				r.assert_equals(msg.tag, '001', 'Verify tag')
				r.assert_equals(msg.status, status.UNKNOWN, 'Verify status')
				result.add(r)
			elif msg.message.startswith('X4'):
				r = TestResult('Validating message X4')
				r.assert_equals(msg.message, 'X4 error Application Error: ', 'Verify message')
				r.assert_equals(msg.channel, 'pytest_evlog_01', 'Verify channel')
				r.assert_equals(msg.tag, '001', 'Verify tag')
				r.assert_equals(msg.status, status.OK, 'Verify status')
				result.add(r)
		
		(res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE', ['warn=eq:1', 'crit=eq:4'])
		cache.assert_equals(res, status.CRITICAL, "Validate cache has items: %s"%msg)
		cache.assert_equals(msg, 'X4 error Application Error: , X1 warning Application Error: , X2 success Application Error: , X3 info Application Error: , eventlog: 4 = critical', "Validate cache message")
		cache.assert_equals(perf, "'eventlog'=4;1;4", "Validate cache performance")
		(res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE', ['warn=eq:1', 'crit=eq:2'])
		cache.assert_equals(res, status.OK, "Validate cache is empty (again)")
		cache.assert_equals(msg, 'Eventlog check ok', "Validate cache is ok: %s"%msg)
		
		result.add(cache)
		
		r = TestResult('Checking filters')
		r.add(self.test_w_expected('id = 1000 and generated gt 1m', '%generated%', 0))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m', '%generated%', 4))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m and id = 1000', '%generated%: %id%, %category%', 4))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m and category = 1', '%category%', 1))
		r.add(self.test_w_expected('id = 1000 and generated gt -1m and category = 0', '%category%', 1))
		r.add(self.test_w_expected("id = 1000 and generated gt -1m and level = 'error'", '%level%', 1))
		r.add(self.test_w_expected("id = 1000 and generated gt -1m and level = 'info'", '%level%', 1))
		result.add(r)
		
		r = TestResult('Checking syntax')
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%source% - %type% - %category%', 'Application Error - error - 0'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%source% - %type% - %category%', 'Application Error - warning - 1'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 2', '%source% - %type% - %category%', 'Application Error - success - 2'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 3', '%source% - %type% - %category%', 'Application Error - info - 3'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%facility% - %qualifier% - %customer%', '0 - 0 - 0'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%facility% - %qualifier% - %customer%', '5 - 5 - 0'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%rawid% - %severity% - %log%', '1000 - success - Application'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%rawid% - %severity% - %log%', '1074070504 - informational - Application'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 2', '%rawid% - %severity% - %log%', '2147812328 - warning - Application'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 3', '%rawid% - %severity% - %log%', '3221554152 - error - Application'))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 0', '%id% - %strings%', '1000 - a, a, a, a, a, a, a, a, a, a, a, a, a, '))
		r.add(self.test_syntax('id = 1000 and generated gt -2m and category = 1', '%id% - %strings%', '1000 - a, a, a, a, a, a, a, a, a, a, a, a, a, '))
		result.add(r)

		return result
Пример #25
0
	def test_syntax(self, filter, syntax, expected):
		result = TestResult('Validating syntax: %s'%syntax)
		(res, msg, perf) = Core.get().simple_query('CheckEventLog', ['file=Application', 'warn=ne:1', 'filter=%s'%filter, 'syntax=%s'%syntax, 'descriptions'])
		result.assert_equals(msg, expected, "Validate message rendering syntax: %s"%msg)
		return result
Пример #26
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)
Пример #27
0
from NSCP import Settings, Registry, Core, log, status, log_error, sleep
from NSCP import Settings, Registry, Core, log, status, log_error, sleep
from test_helper import BasicTest, TestResult, Callable, setup_singleton, install_testcases, init_testcases, shutdown_testcases
from types import *
import random
import subprocess
import uuid
import os
import sys, stat, datetime, time
core = Core.get()


class Win32WMITest(BasicTest):
    def desc(self):
        return 'Testcase for w32 check_file module'

    def title(self):
        return 'Win32File tests'

    def setup(self, plugin_id, prefix):
        self.reg = Registry.get(plugin_id)

    def teardown(self):
        None

    def get_count(self, perf):
        if not perf:
            return -1
        (title, data) = perf.split('=')
        if not data:
            return -1
Пример #28
0
is_windows = False
if os.name == 'nt':
	is_windows = True

check_per_second = 10
#time_to_run = 'infinate'
time_to_run = 60*10
use_threads = 10

route_via_nsca = True
route_via_python = False

prefix = 'stress'

core = Core.get()

class StressTest(BasicTest):

	check_count = 0
	results_count = 0
	
	sched_alias = 'test_sched_%s'%prefix
	nsca_server_alias = 'test_nsca_s_%s'%prefix
	nsca_client_alias = 'test_nsca_c_%s'%prefix
	python_channel = 'test_stress_%s_py'%prefix
	nsca_channel = 'test_stress_%s_nsca'%prefix
	command = 'test_stress_%s'%prefix
	port = 15568
	sched_base_path = '/settings/%s'%sched_alias
	
Пример #29
0
    def run_test(self):
        result = TestResult('Checking CheckEventLog')
        cache = TestResult('Checking CheckEventLog CACHE')

        (res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE',
                                                   ['warn=eq:1', 'crit=eq:2'])
        cache.assert_equals(res, status.OK, "Validate cache is empty")
        cache.assert_equals(msg, 'Eventlog check ok',
                            "Validate cache is ok: %s" % msg)

        a_list = [
            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'
        ]
        result.add_message(
            self.test_create('Application Error', 1000, 'error', 'success', 0,
                             0, a_list), 'Testing to create a log message')
        result.add_message(
            self.test_create('Application Error', 1000, 'warning',
                             'informational', 1, 5, a_list),
            'Testing to create a log message')
        result.add_message(
            self.test_create('Application Error', 1000, 'success', 'warning',
                             2, 5, a_list), 'Testing to create a log message')
        result.add_message(
            self.test_create('Application Error', 1000, 'info', 'error', 3, 5,
                             a_list), 'Testing to create a log message')
        for x in range(1, 10):
            sleep(100)
            if len(self.messages) == 4:
                break
        log('Recieved %d messages.' % len(self.messages))
        result.assert_equals(len(self.messages), 4,
                             'Verify that all 4 messages are sent through')

        for msg in self.messages:
            if msg.message.startswith('X1'):
                r = TestResult('Validating message X1')
                r.assert_equals(msg.message, 'X1 warning Application Error: ',
                                'Verify message')
                r.assert_equals(msg.channel, 'pytest_evlog_01',
                                'Verify channel')
                r.assert_equals(msg.tag, '001', 'Verify tag')
                r.assert_equals(msg.status, status.WARNING, 'Verify status')
                result.add(r)
            elif msg.message.startswith('X2'):
                r = TestResult('Validating message X2')
                r.assert_equals(msg.message, 'X2 success Application Error: ',
                                'Verify message')
                r.assert_equals(msg.channel, 'pytest_evlog_02',
                                'Verify channel')
                r.assert_equals(msg.tag, '002', 'Verify tag')
                r.assert_equals(msg.status, status.CRITICAL, 'Verify status')
                result.add(r)
            elif msg.message.startswith('X3'):
                r = TestResult('Validating message X3')
                r.assert_equals(msg.message, 'X3 info Application Error: ',
                                'Verify message')
                r.assert_equals(msg.channel, 'pytest_evlog_01',
                                'Verify channel')
                r.assert_equals(msg.tag, '001', 'Verify tag')
                r.assert_equals(msg.status, status.UNKNOWN, 'Verify status')
                result.add(r)
            elif msg.message.startswith('X4'):
                r = TestResult('Validating message X4')
                r.assert_equals(msg.message, 'X4 error Application Error: ',
                                'Verify message')
                r.assert_equals(msg.channel, 'pytest_evlog_01',
                                'Verify channel')
                r.assert_equals(msg.tag, '001', 'Verify tag')
                r.assert_equals(msg.status, status.OK, 'Verify status')
                result.add(r)

        (res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE',
                                                   ['warn=eq:1', 'crit=eq:4'])
        cache.assert_equals(res, status.CRITICAL,
                            "Validate cache has items: %s" % msg)
        cache.assert_equals(
            msg,
            'X4 error Application Error: , X1 warning Application Error: , X2 success Application Error: , X3 info Application Error: , eventlog: 4 = critical',
            "Validate cache message")
        cache.assert_equals(perf, "'eventlog'=4;1;4",
                            "Validate cache performance")
        (res, msg, perf) = Core.get().simple_query('CheckEventLogCACHE',
                                                   ['warn=eq:1', 'crit=eq:2'])
        cache.assert_equals(res, status.OK, "Validate cache is empty (again)")
        cache.assert_equals(msg, 'Eventlog check ok',
                            "Validate cache is ok: %s" % msg)

        result.add(cache)

        r = TestResult('Checking filters')
        r.add(
            self.test_w_expected('id = 1000 and generated gt 1m',
                                 '%generated%', 0))
        r.add(
            self.test_w_expected('id = 1000 and generated gt -1m',
                                 '%generated%', 4))
        r.add(
            self.test_w_expected(
                'id = 1000 and generated gt -1m and id = 1000',
                '%generated%: %id%, %category%', 4))
        r.add(
            self.test_w_expected(
                'id = 1000 and generated gt -1m and category = 1',
                '%category%', 1))
        r.add(
            self.test_w_expected(
                'id = 1000 and generated gt -1m and category = 0',
                '%category%', 1))
        r.add(
            self.test_w_expected(
                "id = 1000 and generated gt -1m and level = 'error'",
                '%level%', 1))
        r.add(
            self.test_w_expected(
                "id = 1000 and generated gt -1m and level = 'info'", '%level%',
                1))
        result.add(r)

        r = TestResult('Checking syntax')
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 0',
                             '%source% - %type% - %category%',
                             'Application Error - error - 0'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 1',
                             '%source% - %type% - %category%',
                             'Application Error - warning - 1'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 2',
                             '%source% - %type% - %category%',
                             'Application Error - success - 2'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 3',
                             '%source% - %type% - %category%',
                             'Application Error - info - 3'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 0',
                             '%facility% - %qualifier% - %customer%',
                             '0 - 0 - 0'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 1',
                             '%facility% - %qualifier% - %customer%',
                             '5 - 5 - 0'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 0',
                             '%rawid% - %severity% - %log%',
                             '1000 - success - Application'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 1',
                             '%rawid% - %severity% - %log%',
                             '1074070504 - informational - Application'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 2',
                             '%rawid% - %severity% - %log%',
                             '2147812328 - warning - Application'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 3',
                             '%rawid% - %severity% - %log%',
                             '3221554152 - error - Application'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 0',
                             '%id% - %strings%',
                             '1000 - a, a, a, a, a, a, a, a, a, a, a, a, a, '))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 1',
                             '%id% - %strings%',
                             '1000 - a, a, a, a, a, a, a, a, a, a, a, a, a, '))
        result.add(r)

        return result