Exemplo n.º 1
0
	def run_test(self, cases=None):
		result = TestResult()
		cryptos = ["none", "xor", "des", "3des", "cast128", "xtea", "blowfish", "twofish", "rc2", "aes", "aes256", "aes192", "aes128", "serpent", "gost", "3way"]
		for c in cryptos:
			run_l = None
			run_this = False
			if cases:
				tmp_l = None
				for case in cases:
					if '-' in case:
						(run_c, tmp_l) = case.split('-', 2)
					else:
						run_c = case
					if c == run_c:
						run_l = int(tmp_l) if tmp_l else None
						run_this = True
				if not run_this:
					result.add_message(True, 'Ignoring: %s-*'%c)
					continue
			for l in [128, 512, 1024, 4096]:
				if not run_l or run_l == l:
					result.add(self.test_one_crypto(c, l))
				else:
					result.add_message(True, 'Ignoring: %s-%s'%(c, l))
			#result.add(self.test_one_crypto(c))
		
		return result
Exemplo n.º 2
0
	def run_test(self):
		result = TestResult()
		result.add(self.do_one_test(ssl=True))
		result.add(self.do_one_test(ssl=False))
		result.add(self.do_one_test(ssl=True, length=4096))
		result.add(self.do_one_test(ssl=True, length=65536))
		result.add(self.do_one_test(ssl=True, length=1048576))
		return result
Exemplo n.º 3
0
	def run_test(self):
		result = TestResult()
		cryptos = ["none", "xor", "des", "3des", "cast128", "xtea", "blowfish", "twofish", "rc2", "aes", "aes256", "aes192", "aes128", "serpent", "gost", "3way"]
		for c in cryptos:
			for l in [128, 512, 1024, 4096]:
				result.add(self.test_one_crypto(c, l))
			#result.add(self.test_one_crypto(c))
		
		return result
Exemplo n.º 4
0
	def do_one_test(self, ssl=True, length=1024):
		conf = self.conf
		conf.set_int('/settings/NRPE/test_nrpe_server', 'payload length', length)
		conf.set_bool('/settings/NRPE/test_nrpe_server', 'use ssl', ssl)
		conf.set_bool('/settings/NRPE/test_nrpe_server', 'allow arguments', True)
		# TODO: conf.set_string('/settings/NRPE/test_nrpe_server', 'certificate', ssl)
		self.core.reload('test_nrpe_server')

		conf.set_string('/settings/NRPE/test_nrpe_client/targets/default', 'address', 'nrpe://127.0.0.1:35666')
		conf.set_bool('/settings/NRPE/test_nrpe_client/targets/default', 'use ssl', not ssl)
		conf.set_int('/settings/NRPE/test_nrpe_client/targets/default', 'payload length', length*3)

		conf.set_string('/settings/NRPE/test_nrpe_client/targets/invalid', 'address', 'nrpe://127.0.0.1:25666')
		conf.set_bool('/settings/NRPE/test_nrpe_client/targets/invalid', 'use ssl', not ssl)
		conf.set_int('/settings/NRPE/test_nrpe_client/targets/invalid', 'payload length', length*2)

		conf.set_string('/settings/NRPE/test_nrpe_client/targets/valid', 'address', 'nrpe://127.0.0.1:15666')
		conf.set_bool('/settings/NRPE/test_nrpe_client/targets/valid', 'use ssl', ssl)
		conf.set_int('/settings/NRPE/test_nrpe_client/targets/valid', 'payload length', length)
		self.core.reload('test_nrpe_client')
		
		result = TestResult('ssl=%s, length=%s'%(ssl, length))
		result.add_message(isOpen('127.0.0.1', 15666), 'Checking that port is open (server is up)')
		result.add(self.test_one(ssl, length, state = status.UNKNOWN, tag = 'unknown'))
		result.add(self.test_one(ssl, length, state = status.OK, tag = 'ok'))
		result.add(self.test_one(ssl, length, state = status.WARNING, tag = 'warn'))
		result.add(self.test_one(ssl, length, state = status.CRITICAL, tag = 'crit'))
		return result
Exemplo n.º 5
0
	def run_test(self):
		result = TestResult('Testing W32 file systems')
		result.add(self.check_cli_ns())
		result.add(self.check_cli_ls(None, 'Win32_Processor', 'LogFileEventConsumer'))
		result.add(self.check_cli_ls('root\subscription', 'LogFileEventConsumer', 'Win32_Processor'))
		result.add(self.check_cli_query('SELECT DeviceId, AddressWidth, Caption, Name FROM Win32_Processor', lambda x:x>1, lambda x:'CPU0' in x))
		return result
Exemplo n.º 6
0
    def do_one_test(self, ssl=True, length=1024):
        conf = self.conf
        conf.set_int("/settings/NRPE/test_nrpe_server", "payload length", length)
        conf.set_bool("/settings/NRPE/test_nrpe_server", "use ssl", ssl)
        conf.set_bool("/settings/NRPE/test_nrpe_server", "allow arguments", True)
        # TODO: conf.set_string('/settings/NRPE/test_nrpe_server', 'certificate', ssl)
        self.core.reload("test_nrpe_server")

        conf.set_string("/settings/NRPE/test_nrpe_client/targets/default", "address", "nrpe://127.0.0.1:35666")
        conf.set_bool("/settings/NRPE/test_nrpe_client/targets/default", "use ssl", not ssl)
        conf.set_int("/settings/NRPE/test_nrpe_client/targets/default", "payload length", length * 3)

        conf.set_string("/settings/NRPE/test_nrpe_client/targets/invalid", "address", "nrpe://127.0.0.1:25666")
        conf.set_bool("/settings/NRPE/test_nrpe_client/targets/invalid", "use ssl", not ssl)
        conf.set_int("/settings/NRPE/test_nrpe_client/targets/invalid", "payload length", length * 2)

        conf.set_string("/settings/NRPE/test_nrpe_client/targets/valid", "address", "nrpe://127.0.0.1:15666")
        conf.set_bool("/settings/NRPE/test_nrpe_client/targets/valid", "use ssl", ssl)
        conf.set_int("/settings/NRPE/test_nrpe_client/targets/valid", "payload length", length)
        self.core.reload("test_nrpe_client")

        result = TestResult("ssl=%s, length=%s" % (ssl, length))
        result.add_message(isOpen("127.0.0.1", 15666), "Checking that port is open (server is up)")
        result.add(self.test_one(ssl, length, state=status.UNKNOWN, tag="unknown"))
        result.add(self.test_one(ssl, length, state=status.OK, tag="ok"))
        result.add(self.test_one(ssl, length, state=status.WARNING, tag="warn"))
        result.add(self.test_one(ssl, length, state=status.CRITICAL, tag="crit"))
        return result
Exemplo n.º 7
0
	def test_one_crypto(self, crypto, length=512):
		log('Testing: %s %d'%(crypto, length))
		conf = self.conf
		conf.set_string('/settings/NSCA/test_nsca_server', 'encryption', '%s'%crypto)
		conf.set_string('/settings/NSCA/test_nsca_server', 'password', 'pwd-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_server', 'payload length', length)
		self.core.reload('test_nsca_server')
		
		conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'address', 'nsca://127.0.0.1:35667')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'encryption', '%s'%crypto)
		conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'password', 'default-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_client/targets/default', 'payload length', length*3)

		conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'address', 'nsca://127.0.0.1:25667')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'encryption', 'none')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'password', 'invalid-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_client/targets/invalid', 'payload length', length*2)

		conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'address', 'nsca://127.0.0.1:15667')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'encryption', '%s'%crypto)
		conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'password', 'pwd-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_client/targets/valid', 'payload length', length)
		self.core.reload('test_nsca_client')

		
		
		result = TestResult('Testing: %s/%d'%(crypto, length))
		result.add_message(isOpen('localhost', 15667), 'Checking that port is open')
		for target in ['valid', 'test_rp', 'invalid']:
			result.add(self.test_one_crypto_full(crypto, status.UNKNOWN, 'unknown', target, length))
			result.add(self.test_one_crypto_full(crypto, status.OK, 'ok', target, length))
			result.add(self.test_one_crypto_full(crypto, status.WARNING, 'warn', target, length))
			result.add(self.test_one_crypto_full(crypto, status.CRITICAL, 'crit', target, length))
		return result
Exemplo n.º 8
0
 def test_one(self, ssl=True, length=1024, state=status.UNKNOWN, tag="TODO"):
     result = TestResult("Testing NRPE: %s/%s/%s with various targets" % (ssl, length, tag))
     for t in ["valid", "test_rp", "invalid"]:
         result.add(
             self.submit_payload(
                 "%s/%s/%s" % (ssl, length, tag),
                 ssl,
                 length,
                 "%ssrc%s" % (tag, tag),
                 state,
                 "%smsg%s" % (tag, tag),
                 "",
                 t,
             )
         )
     return result
Exemplo n.º 9
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
Exemplo n.º 10
0
	def run_test_counters(self):
		result = TestResult('Checking CheckCounter')
		(result_code, result_message) = self.core.simple_exec('any', 'pdh', ['--list', '--all'])
		count = 0
		data = []
		for m in result_message:
			data = m.splitlines()
			count = len(data)
		result.add_message(count > 0, 'Managed to retrieve counters: %d'%count)
		if len(data) == 0:
			result.add_message(False, 'Failed to find counters: %s'%result_message)
		counters = []
		
		
		(subres, name1) = self.check_and_lookup_index(4)
		result.add(subres)
		(subres, name2) = self.check_and_lookup_index(26)
		result.add(subres)
		
		result.add(self.check_counter('\\4\\26', ['ShowAll', 'MaxWarn=10']))
		result.add(self.check_counter('\\4\\26', ['index', 'ShowAll', 'MaxWarn=10']))
		result.add(self.check_counter('\\%s\\%s'%(name1, name2), ['ShowAll', 'MaxWarn=10']))
		return result
Exemplo n.º 11
0
	def run_test_proc(self):
		master = TestResult('Checking check_process')
		
		result = TestResult('0 notepads running')
		for j in range(0,3):
			result.append(self.test_one_proc_int('notepad.exe', 0, j))
		master.add(result)
		
		pids = []
		for i in range(1,4):
			result = TestResult('%d notepads running'%i)
			log('Starting notepad...')
			handle = subprocess.Popen('notepad.exe', shell=False)
			sleep(500)
			pids.append(handle.pid)
			for j in range(0,3):
				result.append(self.test_one_proc_int('notepad.exe', i, j))
			master.add(result)

		for p in pids:
			subprocess.Popen("taskkill /F /T /PID %i"%p , shell=True)

		return master
Exemplo n.º 12
0
	def do_one_test(self, ssl=True):
		conf = Settings.get()
		conf.set_bool('/settings/nscp/test_nscp_server', 'use ssl', ssl)
		conf.set_bool('/settings/nscp/test_nscp_server', 'allow arguments', True)
		# TODO: conf.set_string('/settings/nscp/test_nscp_server', 'certificate', ssl)
		core.reload('test_nscp_server')

		conf.set_string('/settings/nscp/test_nscp_client/targets/default', 'address', 'nscp://127.0.0.1:35668')
		conf.set_bool('/settings/nscp/test_nscp_client/targets/default', 'use ssl', not ssl)

		conf.set_string('/settings/nscp/test_nscp_client/targets/invalid', 'address', 'nscp://127.0.0.1:25668')
		conf.set_bool('/settings/nscp/test_nscp_client/targets/invalid', 'use ssl', not ssl)

		conf.set_string('/settings/nscp/test_nscp_client/targets/valid', 'address', 'nscp://127.0.0.1:15668')
		conf.set_bool('/settings/nscp/test_nscp_client/targets/valid', 'use ssl', ssl)
		core.reload('test_nscp_client')
		
		result = TestResult()
		#result.add_message(isOpen('127.0.0.1', 15668), 'Checking that port is open (server is up)')
		#result.add(self.test_one(ssl, length, state = status.UNKNOWN, tag = 'unknown'))
		result.add(self.test_one(ssl, state = status.OK, tag = 'ok'))
		#result.add(self.test_one(ssl, length, state = status.WARNING, tag = 'warn'))
		#result.add(self.test_one(ssl, length, state = status.CRITICAL, tag = 'crit'))
		return result
Exemplo n.º 13
0
    def do_one_test(self, ssl=True, length=1024):
        conf = self.conf
        conf.set_int('/settings/NRPE/test_nrpe_server', 'payload length',
                     length)
        conf.set_bool('/settings/NRPE/test_nrpe_server', 'use ssl', ssl)
        conf.set_bool('/settings/NRPE/test_nrpe_server', 'allow arguments',
                      True)
        # TODO: conf.set_string('/settings/NRPE/test_nrpe_server', 'certificate', ssl)
        self.core.reload('test_nrpe_server')

        conf.set_string('/settings/NRPE/test_nrpe_client/targets/default',
                        'address', 'nrpe://127.0.0.1:35666')
        conf.set_bool('/settings/NRPE/test_nrpe_client/targets/default',
                      'use ssl', not ssl)
        conf.set_int('/settings/NRPE/test_nrpe_client/targets/default',
                     'payload length', length * 3)

        conf.set_string('/settings/NRPE/test_nrpe_client/targets/invalid',
                        'address', 'nrpe://127.0.0.1:25666')
        conf.set_bool('/settings/NRPE/test_nrpe_client/targets/invalid',
                      'use ssl', not ssl)
        conf.set_int('/settings/NRPE/test_nrpe_client/targets/invalid',
                     'payload length', length * 2)

        conf.set_string('/settings/NRPE/test_nrpe_client/targets/valid',
                        'address', 'nrpe://127.0.0.1:15666')
        conf.set_bool('/settings/NRPE/test_nrpe_client/targets/valid',
                      'use ssl', ssl)
        conf.set_int('/settings/NRPE/test_nrpe_client/targets/valid',
                     'payload length', length)
        self.core.reload('test_nrpe_client')

        result = TestResult('ssl=%s, length=%s' % (ssl, length))
        result.add_message(isOpen('127.0.0.1', 15666),
                           'Checking that port is open (server is up)')
        result.add(
            self.test_one(ssl, length, state=status.UNKNOWN, tag='unknown'))
        result.add(self.test_one(ssl, length, state=status.OK, tag='ok'))
        result.add(self.test_one(ssl, length, state=status.WARNING,
                                 tag='warn'))
        result.add(
            self.test_one(ssl, length, state=status.CRITICAL, tag='crit'))
        return result
Exemplo n.º 14
0
	def run_test(self):
		result = TestResult()
		result.add(self.test_simple('foobar', status.OK, 'qwerty', '', 'simple ok'))
		result.add(self.test_simple('foobar', status.WARNING, 'foobar', '', 'simple warning'))
		result.add(self.test_simple('foobar', status.CRITICAL, 'test', '', 'simple critical'))
		result.add(self.test_simple('foobar', status.UNKNOWN, '1234567890', '', 'simple unknown'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%", 'simple performance data 001'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10", 'simple performance data 002'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10;23", 'simple performance data 003'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10;23;10;78", 'simple performance data 004'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10;23;10;78 'bar'=1k;2;3", 'simple performance data 005'))
		return result
Exemplo n.º 15
0
	def run_filter_operator_test(self):
		result = TestResult('Filter tests')
		result.add(self.check_files('none', 'Count all lines', 7))
		result.add(self.check_files("column2 = 'A'", 'Count all A', 2))
		result.add(self.check_files("column2 = 'B'", 'Count all B', 3))
		result.add(self.check_files("column2 = 'C'", 'Count all C', 1))
		result.add(self.check_files("column3 = 'Test 1'", 'Count all T1', 4))
		result.add(self.check_files("column3 like 'Test'", 'Count all T', 6))
		result.add(self.check_files("column3 not like '1'", 'Count all T', 2))
		result.add(self.check_files("column1 > 1", 'Count all B', 5))
		result.add(self.check_files("column1 > 3", 'Count all B', 3))
		result.add(self.check_files("column1 > 5", 'Count all B', 1))
		result.add(self.check_files("column1 < 1", 'Count all B', 1))
		result.add(self.check_files("column1 < 3", 'Count all B', 3))
		result.add(self.check_files("column1 < 5", 'Count all B', 5))
		result.add(self.check_files("column1 = 1", 'Count all B', 1))
		result.add(self.check_files("column1 = 3", 'Count all B', 1))
		result.add(self.check_files("column1 = 5", 'Count all B', 1))
		result.add(self.check_files("column1 != 1", 'Count all B', 6))
		result.add(self.check_files("column1 != 3", 'Count all B', 6))
		result.add(self.check_files("column1 != 5", 'Count all B', 6))
		
		return result
Exemplo n.º 16
0
	def run_boundry_test(self):
		result = TestResult('Boundry tests')
		result.add(self.check_bound('none', 'count > 1', 'none', status.WARNING))
		result.add(self.check_bound('none', 'none', 'count > 1', status.CRITICAL))
		result.add(self.check_bound('column1 > 5', 'count > 2', 'count > 5', status.OK))
		result.add(self.check_bound('column1 > 4', 'count > 2', 'count > 5', status.OK))
		result.add(self.check_bound('column1 > 3', 'count > 2', 'count > 5', status.WARNING))
		result.add(self.check_bound('column1 > 2', 'count > 2', 'count > 5', status.WARNING))
		result.add(self.check_bound('column1 > 1', 'count > 2', 'count > 5', status.WARNING))
		result.add(self.check_bound('column1 > 0', 'count > 2', 'count > 5', status.CRITICAL))

		result.add(self.check_bound('column1 > 5', 'column1 = 3', 'none', status.OK))
		result.add(self.check_bound('column1 > 0', 'column1 = 3', 'none', status.WARNING))
		
		return result
Exemplo n.º 17
0
 def run_test(self):
     result = TestResult('Testing W32 systems')
     result.add(self.run_test_proc())
     result.add(self.run_test_counters())
     return result
Exemplo n.º 18
0
    def run_boundry_test(self):
        result = TestResult("Boundry tests")
        result.add(self.check_bound("none", "count > 1", "none", status.WARNING))
        result.add(self.check_bound("none", "none", "count > 1", status.CRITICAL))
        result.add(self.check_bound("column1 > 5", "count > 2", "count > 5", status.OK))
        result.add(self.check_bound("column1 > 4", "count > 2", "count > 5", status.OK))
        result.add(self.check_bound("column1 > 3", "count > 2", "count > 5", status.WARNING))
        result.add(self.check_bound("column1 > 2", "count > 2", "count > 5", status.WARNING))
        result.add(self.check_bound("column1 > 1", "count > 2", "count > 5", status.WARNING))
        result.add(self.check_bound("column1 > 0", "count > 2", "count > 5", status.CRITICAL))

        result.add(self.check_bound("column1 > 5", "column1 = 3", "none", status.OK))
        result.add(self.check_bound("column1 > 0", "column1 = 3", "none", status.WARNING))

        return result
Exemplo n.º 19
0
	def test_one_crypto_full(self, encryption, state, key, target, length):
		result = TestResult('Testing %s/%s'%(encryption, key))
		result.add(self.submit_payload(encryption, target, length, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s/%d/%s'%(state, encryption, length, target)))
		result.add(self.submit_via_exec(encryption, target, length, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s/%d/%s'%(state, encryption, length, target)))
		return result
Exemplo n.º 20
0
    def run_filter_operator_test(self):
        result = TestResult('Filter tests')
        result.add(self.check_files('none', 'Count all lines', 7))
        result.add(self.check_files("column2 = 'A'", 'Count all A', 2))
        result.add(self.check_files("column2 = 'B'", 'Count all B', 3))
        result.add(self.check_files("column2 = 'C'", 'Count all C', 1))
        result.add(self.check_files("column3 = 'Test 1'", 'Count all T1', 4))
        result.add(self.check_files("column3 like 'Test'", 'Count all T', 6))
        result.add(self.check_files("column3 not like '1'", 'Count all T', 3))
        result.add(self.check_files("column1 > 1", 'Count all B', 5))
        result.add(self.check_files("column1 > 3", 'Count all B', 3))
        result.add(self.check_files("column1 > 5", 'Count all B', 1))
        result.add(self.check_files("column1 < 1", 'Count all B', 1))
        result.add(self.check_files("column1 < 3", 'Count all B', 3))
        result.add(self.check_files("column1 < 5", 'Count all B', 5))
        result.add(self.check_files("column1 = 1", 'Count all B', 1))
        result.add(self.check_files("column1 = 3", 'Count all B', 1))
        result.add(self.check_files("column1 = 5", 'Count all B', 1))
        result.add(self.check_files("column1 != 1", 'Count all B', 6))
        result.add(self.check_files("column1 != 3", 'Count all B', 6))
        result.add(self.check_files("column1 != 5", 'Count all B', 6))

        return result
Exemplo n.º 21
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
Exemplo n.º 22
0
    def run_test(self):
        result = TestResult('Checking CheckEventLog')
        cache = TestResult('Checking CheckEventLog CACHE')

        sleep(2000)

        #(res, msg, perf) = self.core.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(
            self.test_create('Application Error', 1000, 'error', 'success', 0,
                             0, a_list))
        result.add(
            self.test_create('Application Error', 1000, 'warning',
                             'informational', 1, 5, a_list))
        result.add(
            self.test_create('Application Error', 1000, 'success', 'warning',
                             2, 5, a_list))
        result.add(
            self.test_create('Application Error', 1000, 'info', 'error', 3, 5,
                             a_list))
        for x in range(1, 10):
            log('Waiting...%d/4.' % len(self.messages))
            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) = self.core.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) = self.core.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 = 'warning'",
                '%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 - information - 2'))
        r.add(
            self.test_syntax('id = 1000 and generated gt -2m and category = 3',
                             '%source% - %type% - %category%',
                             'Application Error - information - 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
Exemplo n.º 23
0
    def run_test(self):
        ret = TestResult('External scripts test suite')
        result = TestResult('Arguments NOT allowed')
        result.add(
            self.do_one_test('tes_script_ok',
                             message='OK: Everything is going to be fine'))
        result.add(
            self.do_one_test('tes_script_test',
                             message='Test arguments are: (  )'))

        result.add(
            self.do_one_test('tes_sa_test', status.OK,
                             'Test arguments are: ("ARG1" "ARG 2" "A R G 3")'))

        result.add(
            self.do_one_test(
                'tes_script_test', status.UNKNOWN,
                'Arguments not allowed see nsclient.log for details',
                ['NOT ALLOWED']))

        ret.add(result)
        self.conf.set_string('/settings/test_external_scripts',
                             'allow arguments', 'true')
        self.core.reload('test_external_scripts')

        result = TestResult('Arguments allowed')

        if os.name == 'nt':
            tests = ['bat', 'ps1']
        else:
            tests = ['sh']
        for t in tests:
            script = 'tes_sca_%s' % t
            subresult = TestResult(t)
            subresult.add(
                self.do_one_test(script, status.OK,
                                 'Test arguments are: (OK "$ARG2$" "$ARG3$")',
                                 ['OK']))
            subresult.add(
                self.do_one_test(
                    script, status.WARNING,
                    'Test arguments are: (WARN "$ARG2$" "$ARG3$")', ['WARN']))
            subresult.add(
                self.do_one_test(
                    script, status.CRITICAL,
                    'Test arguments are: (CRIT "$ARG2$" "$ARG3$")', ['CRIT']))
            subresult.add(
                self.do_one_test(
                    script, status.UNKNOWN,
                    'Test arguments are: (UNKNOWN "$ARG2$" "$ARG3$")',
                    ['UNKNOWN']))
            subresult.add(
                self.do_one_test(
                    script, status.OK,
                    'Test arguments are: (OK "String with space" "A long long option with many spaces")',
                    [
                        'OK', 'String with space',
                        'A long long option with many spaces'
                    ]))
            subresult.add(
                self.do_one_test(script, status.OK, LONG_OUTPUT, ['LONG']))

            subresult.add(
                self.do_one_test(
                    script, status.UNKNOWN,
                    'Request contained illegal characters set /settings/external scripts/allow nasty characters=true!',
                    ['OK', '$$$ \\ \\', '$$$ \\ \\']))

            result.add(subresult)

        subresult = TestResult('Upper and lower case')
        subresult.add(
            self.do_one_test("tes_upper_LOWER", status.OK,
                             'OK: Everything is going to be fine', ['OK']))
        subresult.add(
            self.do_one_test("alias_UPPER_lower", status.OK,
                             'OK: Everything is going to be fine', ['OK']))

        result.add(subresult)

        ret.add(result)

        self.conf.set_string('/settings/test_external_scripts',
                             'allow nasty characters', 'true')
        self.core.reload('test_external_scripts')

        result = TestResult('Nasty Arguments allowed')
        for t in tests:
            script = 'tes_sca_%s' % t
            subresult = TestResult(t)
            if os.name == 'nt':
                subresult.add(
                    self.do_one_test(
                        script, status.OK,
                        'Test arguments are: (OK "$$$ \\ \\" "$$$ \\ \\")',
                        ['OK', '$$$ \\ \\', '$$$ \\ \\'], False))
            else:
                subresult.add(
                    self.do_one_test(script, status.OK,
                                     'Test arguments are: (OK $ \\ " $  ")',
                                     ['OK', '$ \\ \\', '$ \\ \\'], False))
            result.add(subresult)

        ret.add(result)
        return ret
Exemplo n.º 24
0
    def run_filter_operator_test(self):
        result = TestResult("Filter tests")
        result.add(self.check_files("none", "Count all lines", 7))
        result.add(self.check_files("column2 = 'A'", "Count all A", 2))
        result.add(self.check_files("column2 = 'B'", "Count all B", 3))
        result.add(self.check_files("column2 = 'C'", "Count all C", 1))
        result.add(self.check_files("column3 = 'Test 1'", "Count all T1", 4))
        result.add(self.check_files("column3 like 'Test'", "Count all T", 6))
        result.add(self.check_files("column3 not like '1'", "Count all T", 3))
        result.add(self.check_files("column1 > 1", "Count all B", 5))
        result.add(self.check_files("column1 > 3", "Count all B", 3))
        result.add(self.check_files("column1 > 5", "Count all B", 1))
        result.add(self.check_files("column1 < 1", "Count all B", 1))
        result.add(self.check_files("column1 < 3", "Count all B", 3))
        result.add(self.check_files("column1 < 5", "Count all B", 5))
        result.add(self.check_files("column1 = 1", "Count all B", 1))
        result.add(self.check_files("column1 = 3", "Count all B", 1))
        result.add(self.check_files("column1 = 5", "Count all B", 1))
        result.add(self.check_files("column1 != 1", "Count all B", 6))
        result.add(self.check_files("column1 != 3", "Count all B", 6))
        result.add(self.check_files("column1 != 5", "Count all B", 6))

        return result
Exemplo n.º 25
0
	def run_test(self):
		result = TestResult()
		result.add(self.test_simple('foobar', status.OK, 'qwerty', '', 'simple ok'))
		result.add(self.test_simple('foobar', status.WARNING, 'foobar', '', 'simple warning'))
		result.add(self.test_simple('foobar', status.CRITICAL, 'test', '', 'simple critical'))
		result.add(self.test_simple('foobar', status.UNKNOWN, '1234567890', '', 'simple unknown'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%", 'simple performance data 001'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10", 'simple performance data 002'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10;23", 'simple performance data 003'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10;23;10;78", 'simple performance data 004'))
		result.add(self.test_simple('foobar', status.OK, 'qwerty', "'foo'=5%;10;23;10;78 'bar'=1k;2;3", 'simple performance data 005'))
		return result
Exemplo n.º 26
0
	def run_test(self):
		ret = TestResult('External scripts test suite')
		result = TestResult('Arguments NOT allowed')
		result.add(self.do_one_test('tes_script_ok', message='OK: Everything is going to be fine'))
		result.add(self.do_one_test('tes_script_test', message='Test arguments are: (  )'))
		
		result.add(self.do_one_test('tes_sa_test', status.OK, 'Test arguments are: ("ARG1" "ARG 2" "A R G 3")'))

		
		result.add(self.do_one_test('tes_script_test', status.UNKNOWN, 'Arguments not allowed see nsclient.log for details', ['NOT ALLOWED']))
		
		ret.add(result)
		self.conf.set_string('/settings/test_external_scripts', 'allow arguments', 'true')
		self.core.reload('test_external_scripts')

		result = TestResult('Arguments allowed')
		result.add(self.do_one_test('tes_sca_test', status.OK, 'Test arguments are: (OK "$ARG2$" "$ARG3$")', ['OK']))
		result.add(self.do_one_test('tes_sca_test', status.WARNING, 'Test arguments are: (WARN "$ARG2$" "$ARG3$")', ['WARN']))
		result.add(self.do_one_test('tes_sca_test', status.CRITICAL, 'Test arguments are: (CRIT "$ARG2$" "$ARG3$")', ['CRIT']))
		result.add(self.do_one_test('tes_sca_test', status.UNKNOWN, 'Test arguments are: (UNKNOWN "$ARG2$" "$ARG3$")', ['UNKNOWN']))
		result.add(self.do_one_test('tes_sca_test', status.OK, 'Test arguments are: (OK "String with space" "A long long option with many spaces")', ['OK', 'String with space', 'A long long option with many spaces']))
		result.add(self.do_one_test('tes_sca_test', status.OK, LONG_OUTPUT, ['LONG']))
		
		result.add(self.do_one_test('tes_sca_test', status.UNKNOWN, 'Request contained illegal characters set /settings/external scripts/allow nasty characters=true!', ['OK', '$$$ \\ \\', '$$$ \\ \\']))

		ret.add(result)
		self.conf.set_string('/settings/test_external_scripts', 'allow nasty characters', 'true')
		self.core.reload('test_external_scripts')

		result = TestResult('Nasty Arguments allowed')
		if os.name == 'nt':
			result.add(self.do_one_test('tes_sca_test', status.OK, 'Test arguments are: (OK "$$$ \\ \\" "$$$ \\ \\")', ['OK', '$$$ \\ \\', '$$$ \\ \\'], False))
		else:
			result.add(self.do_one_test('tes_sca_test', status.OK, 'Test arguments are: (OK $ \\ " $  ")', ['OK', '$ \\ \\', '$ \\ \\'], False))
		
		ret.add(result)
		return ret
Exemplo n.º 27
0
	def test_one(self, ssl=True, length=1024, state = status.UNKNOWN, tag = 'TODO'):
		result = TestResult('Testing NRPE: %s/%s/%s with various targets'%(ssl, length, tag))
		for t in ['valid', 'test_rp', 'invalid']:
			result.add(self.submit_payload('%s/%s/%s'%(ssl, length, tag), ssl, length, '%ssrc%s'%(tag, tag), state, '%smsg%s'%(tag, tag), '', t))
		return result
Exemplo n.º 28
0
    def run_boundry_test(self):
        result = TestResult('Boundry tests')
        result.add(
            self.check_bound('none', 'count > 1', 'none', status.WARNING))
        result.add(
            self.check_bound('none', 'none', 'count > 1', status.CRITICAL))
        result.add(
            self.check_bound('column1 > 5', 'count > 2', 'count > 5',
                             status.OK))
        result.add(
            self.check_bound('column1 > 4', 'count > 2', 'count > 5',
                             status.OK))
        result.add(
            self.check_bound('column1 > 3', 'count > 2', 'count > 5',
                             status.WARNING))
        result.add(
            self.check_bound('column1 > 2', 'count > 2', 'count > 5',
                             status.WARNING))
        result.add(
            self.check_bound('column1 > 1', 'count > 2', 'count > 5',
                             status.WARNING))
        result.add(
            self.check_bound('column1 > 0', 'count > 2', 'count > 5',
                             status.CRITICAL))

        result.add(
            self.check_bound('column1 > 5', 'column1 = 3', 'none', status.OK))
        result.add(
            self.check_bound('column1 > 0', 'column1 = 3', 'none',
                             status.WARNING))

        return result
Exemplo n.º 29
0
	def run_test(self):
		result = TestResult('Testing W32 file systems')

		# Check size
		result.add(self.check_files('size gt 0b', 'Count all files', 10, []))
		result.add(self.check_files('size gt 4b', 'Count all files', 2, []))
		result.add(self.check_files('size lt 4b', 'Count all files', 11, []))
		result.add(self.check_files('size eq 4b', 'Count all files', 8, []))
		result.add(self.check_files('size ne 4b', 'Count all files', 13, []))
		result.add(self.check_files('size eq 0b', 'Count all folders', 11, []))
		
		# Check flags (recursive, pattern)
		result.add(self.check_files('size eq 0b', 'Count all folders (non recursivly)', 3, ['max-dir-depth=0']))
		result.add(self.check_files('size eq 0b', 'Count all folders (recurse 1)', 6, ['max-dir-depth=1']))
		result.add(self.check_files('size gt 0b', 'Count all files (*.txt)', 9, ['pattern=*.txt']))
		result.add(self.check_files('size gt 0b', 'Count all files (*.txt)', 0, ['pattern=*.foo']))

		# Check dates
		result.add(self.check_files('written ge -5m', 'Count all files (*.txt, >-5m)', 7, ['pattern=*.txt']))
		result.add(self.check_files('written le -5m', 'Count all files (*.txt, <-5m)', 4, ['pattern=*.txt']))
		result.add(self.check_files('written lt -9m', 'Count all files (*.txt, <-9m)', 2, ['pattern=*.txt']))
		result.add(self.check_files('written gt -9m', 'Count all files (*.txt, >-9m)', 7, ['pattern=*.txt']))
		result.add(self.check_files('written lt -1m', 'Count all files (*.txt, <-1m)', 4, ['pattern=*.txt']))
		result.add(self.check_files('written gt -9m and written lt -1m', 'Count all files (*.txt, >-10m<-5m)', 2, ['pattern=*.txt']))
		result.add(self.check_files('written gt 0m', 'Count all files (*.txt, >0m)', 4, ['pattern=*.txt']))

		self.cleanup_files()
		
		return result
Exemplo n.º 30
0
 def run_test(self):
     result = TestResult('Testing W32 task scheduler')
     for (state, code) in [('OK', 0), ('WARN', 1), ('CRIT', 2), ('LONG', 0)]:
         result.add(self.check_ts_query(state, code))
     return result
Exemplo n.º 31
0
	def run_test(self):
		result = TestResult('Testing W32 systems')
		result.add(self.run_test_proc())
		result.add(self.run_test_counters())
		return result
Exemplo n.º 32
0
 def run_test(self):
     result = TestResult('Testing W32 task scheduler')
     for (state, code) in [('OK', 0), ('WARN', 1), ('CRIT', 2), ('LONG', 0)]:
         result.add(self.check_ts_query(state, code))
     return result
Exemplo n.º 33
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
Exemplo n.º 34
0
    def run_test(self):
        result = TestResult('Testing W32 file systems')

        # Check size
        result.add(
            self.check_files('size gt 0b', 'Count all files (not folders)', 10,
                             []))
        result.add(
            self.check_files('size gt 4b', 'Count all files > 4b', 2, []))
        result.add(
            self.check_files('size lt 5b', 'Count all files < 5b', 11, []))
        result.add(
            self.check_files('size eq 4b', 'Count all files = 4b', 8, []))
        result.add(
            self.check_files('size ne 4b', 'Count all files!= 4b', 5, []))
        result.add(
            self.check_files('size lt 4m', 'Count all files < 5m', 13, []))
        result.add(self.check_files('size eq 0b', 'Count all folders', 3, []))

        # Check flags (recursive, pattern)
        result.add(
            self.check_files('size eq 0b',
                             'Count all folders (non recursivly)', 3,
                             ['max-dir-depth=0']))
        result.add(
            self.check_files('size eq 0b', 'Count all folders (recurse 1)', 1,
                             ['max-dir-depth=1']))
        result.add(
            self.check_files('size eq 0b', 'Count all folders (recurse 1)', 2,
                             ['max-dir-depth=2']))
        result.add(
            self.check_files('size eq 0b', 'Count all folders (recurse 1)', 3,
                             ['max-dir-depth=3']))
        result.add(
            self.check_files('size eq 0b', 'Count all folders (recurse 1)', 3,
                             ['max-dir-depth=4']))
        result.add(
            self.check_files('size gt 0b', 'Count all files (*.txt)', 9,
                             ['pattern=*.txt']))
        result.add(
            self.check_files('size gt 0b', 'Count all files (*.txt)', 0,
                             ['pattern=*.foo']))

        # Check dates
        result.add(
            self.check_files('written ge -5m', 'Count all files (*.txt, >-5m)',
                             7, ['pattern=*.txt']))
        result.add(
            self.check_files('written le -5m', 'Count all files (*.txt, <-5m)',
                             4, ['pattern=*.txt']))
        result.add(
            self.check_files('written lt -9m', 'Count all files (*.txt, <-9m)',
                             2, ['pattern=*.txt']))
        result.add(
            self.check_files('written gt -9m', 'Count all files (*.txt, >-9m)',
                             7, ['pattern=*.txt']))
        result.add(
            self.check_files('written lt -1m', 'Count all files (*.txt, <-1m)',
                             4, ['pattern=*.txt']))
        result.add(
            self.check_files('written gt -9m and written lt -1m',
                             'Count all files (*.txt, >-10m<-5m)', 2,
                             ['pattern=*.txt']))
        result.add(
            self.check_files('written gt 0m', 'Count all files (*.txt, >0m)',
                             4, ['pattern=*.txt']))

        result.add(self.check_no_files())
        self.cleanup_files()

        return result
Exemplo n.º 35
0
	def test_one(self, ssl=True, length=1024, state = status.UNKNOWN, tag = 'TODO'):
		result = TestResult('Testing NRPE: %s/%s/%s with various targets'%(ssl, length, tag))
		for t in ['valid', 'test_rp', 'invalid']:
			result.add(self.submit_payload('%s/%s/%s'%(ssl, length, tag), ssl, length, '%ssrc%s'%(tag, tag), state, '%smsg%s'%(tag, tag), '', t))
		return result