def test_update_service(self): data = { 'state': 'OK', 'state_type': 'HARD', 'last_chk': 1440976938, 'output': 'TCP OK - 0.033 second response time on 93.93.47.83 port 22', 'long_output': '', 'perf_data': 'time=0.032536s;;;0.000000;3.000000', 'problem_has_been_acknowledged': False, 'service_description': 'check disk', 'host_name': 'server1' } modconf = Module() modconf.module_name = "alignakbackend" module = AlignakBackendBrok(modconf) with HTTMock(server_responses): # get livehosts module.get_refs('livehost') # get liveservices module.get_refs('liveservice') with HTTMock(server_responses): ret = module.update(data, 'service') reference = { 'livehost': 0, 'liveservice': 1, 'loghost': 0, 'logservice': 1 } self.assertEqual(reference, ret)
def test_send_to_backend_liveservice(self): modconf = Module() modconf.module_name = "alignakbackend" module = AlignakBackendBrok(modconf) module.ref_live = { 'service': { '55d113586376e9835e1b2fe8': { '_etag': '694909e730bf5da80f10ee386eea03d73ab9ec80', '_id': '55d46d5e6376e91e9212230e' } } } module.mapping = { 'service': {'srv1check alive': '55d113586376e9835e1b2fe8'} } data = { 'state': 'OK', 'state_type': 'HARD', 'last_check': 1440976938, 'output': 'TCP OK - 0.033 second response time on 93.93.47.83 port 22', 'long_output': '', 'perf_data': 'time=0.032536s;;;0.000000;3.000000', 'acknowledged': False, } with HTTMock(server_responses): response = module.send_to_backend('liveservice', 'srv1check alive', data) self.assertTrue(response) self.assertEqual('86bc21287a2b98708d6e3b5d148ff9b1c7cbefc5', module.ref_live['service']['55d113586376e9835e1b2fe8']['_etag'])
def test_get_endpoint(self): modconf = Module() modconf.module_name = "alignakbackend" modconf.api_url = 'http://www.alignak.local:5000' module = AlignakBackendBrok(modconf) self.assertEqual('http://www.alignak.local:5000', module.url) endp = module.endpoint('liveservice?embedded={"service_description":1}') self.assertEqual('http://www.alignak.local:5000/liveservice?embedded={"service_description":1}', endp)
def test_send_to_backend_loghost(self): modconf = Module() modconf.module_name = "alignakbackend" module = AlignakBackendBrok(modconf) module.mapping = { 'host': {'srv1': '55d113586376e9835e1b2fe6'} } data = { 'state': 'OK', 'state_type': 'HARD', 'last_check': 1440976938, 'output': 'TCP OK - 0.033 second response time on 93.93.47.83 port 22', 'long_output': '', 'perf_data': 'time=0.032536s;;;0.000000;3.000000', 'acknowledged': False, } with HTTMock(server_responses): response = module.send_to_backend('loghost', 'srv1', data) self.assertTrue(response)
def test_get_refs_liveservice(self): """ Get all services :return: None """ modconf = Module() modconf.module_name = "alignakbackend" module = AlignakBackendBrok(modconf) with HTTMock(server_responses): module.get_refs('liveservice') ref = { '55d4f7b26376e946db235fc4': { '_id': '55d4f8746376e946db235fc8', '_etag': 'fbf6c05750113eca669aece45198affb567ac550' }, '55d4f7be6376e946db235fc5': { '_id': '55d4f8876376e946db235fc9', '_etag': '3ed23c329f07c92fabeee465e5c4e59bc5f575f0' }, '55d4f7cc6376e946db235fc6': { '_id': '55d4faa26376e946db235fca', '_etag': 'b7c4a2563f7382ed86dac2dc975759e20be778fc' }, '55d4f7d76376e946db235fc7': { '_id': '55d4fabd6376e946db235fcb', '_etag': '9ab70e496605b755836be976d676be17a4bc6fea' } } self.assertEqual(module.ref_live['service'], ref) mapping_ref = { 'server1check disk': '55d4f7b26376e946db235fc4', 'server2check disk': '55d4f7be6376e946db235fc5', 'server3check disk': '55d4f7cc6376e946db235fc6', 'server4check disk': '55d4f7d76376e946db235fc7' } self.assertEqual(module.mapping['service'], mapping_ref)
def test_manage_brok_service_check_result(self): modconf = Module() modconf.module_name = "alignakbackend" module = AlignakBackendBrok(modconf) data = { 'state': 'OK', 'state_type': 'HARD', 'last_chk': 1440976938, 'output': 'TCP OK - 0.033 second response time on 93.93.47.83 port 22', 'long_output': '', 'perf_data': 'time=0.032536s;;;0.000000;3.000000', 'problem_has_been_acknowledged': False, 'service_description': 'check disk', 'host_name': 'server1' } brok = Brok(_type='service_check_result', data=data) brok.prepare() with HTTMock(server_responses): module.manage_brok(brok) reference = { '55d4f7b26376e946db235fc4': { '_id': '55d4f8746376e946db235fc8', '_etag': 'fff582e398e47bce29e7317f25eb5068aaac3c4b' }, '55d4f7be6376e946db235fc5': { '_id': '55d4f8876376e946db235fc9', '_etag': '3ed23c329f07c92fabeee465e5c4e59bc5f575f0' }, '55d4f7cc6376e946db235fc6': { '_id': '55d4faa26376e946db235fca', '_etag': 'b7c4a2563f7382ed86dac2dc975759e20be778fc' }, '55d4f7d76376e946db235fc7': { '_id': '55d4fabd6376e946db235fcb', '_etag': '9ab70e496605b755836be976d676be17a4bc6fea' } } self.assertEqual(reference, module.ref_live['service'])
def test_manage_brok_host_check_result(self): modconf = Module() modconf.module_name = "alignakbackend" module = AlignakBackendBrok(modconf) data = { 'state': 'OK', 'state_type': 'HARD', 'last_chk': 1440976938, 'output': 'TCP OK - 0.033 second response time on 93.93.47.83 port 22', 'long_output': '', 'perf_data': 'time=0.032536s;;;0.000000;3.000000', 'problem_has_been_acknowledged': False, 'host_name': 'server1' } brok = Brok(_type='host_check_result', data=data) brok.prepare() with HTTMock(server_responses): module.manage_brok(brok) reference = { '55d4a5246376e946db235fbc': { '_etag': 'fff582e398e47bce29e7317f25eb5068aaac3c4a', '_id': '55d4e5626376e946db235fc0' }, '55d4a5276376e946db235fbd': { '_etag': '3524b87876c1d457bdca7492b9bfc503f3f13b1e', '_id': '55d4e57d6376e946db235fc1' }, '55d4a52a6376e946db235fbe': { '_etag': 'a457e78fe0dc28c1b427d9b0696096fee73f4a29', '_id': '55d4e7d36376e946db235fc2' }, '55d4a52d6376e946db235fbf': { '_etag': '2b45425c497d5593bad8ef5413c84e6a0d61cc41', '_id': '55d4e8126376e946db235fc3' } } self.assertEqual(reference, module.ref_live['host'])
def test_get_refs_livehost(self): modconf = Module() modconf.module_name = "alignakbackend" module = AlignakBackendBrok(modconf) with HTTMock(server_responses): module.get_refs('livehost') ref = { '55d4a5246376e946db235fbc': { '_id': '55d4e5626376e946db235fc0', '_etag': '78462b947415c0703d5bb747e8bc1fdb0e088a3b' }, '55d4a5276376e946db235fbd': { '_id': '55d4e57d6376e946db235fc1', '_etag': '3524b87876c1d457bdca7492b9bfc503f3f13b1e' }, '55d4a52a6376e946db235fbe': { '_id': '55d4e7d36376e946db235fc2', '_etag': 'a457e78fe0dc28c1b427d9b0696096fee73f4a29' }, '55d4a52d6376e946db235fbf': { '_id': '55d4e8126376e946db235fc3', '_etag': '2b45425c497d5593bad8ef5413c84e6a0d61cc41' } } self.assertEqual(module.ref_live['host'], ref) mapping_ref = { 'server1': '55d4a5246376e946db235fbc', 'server2': '55d4a5276376e946db235fbd', 'server3': '55d4a52a6376e946db235fbe', 'server4': '55d4a52d6376e946db235fbf' } self.assertEqual(module.mapping['host'], mapping_ref)
# Special Livestatus module opening since the module rename #from alignak.modules.livestatus import module as livestatus_broker livestatus_broker = modulesctx.get_module('livestatus') LiveStatus_broker = livestatus_broker.LiveStatus_broker LiveStatus = livestatus_broker.LiveStatus LiveStatusRegenerator = livestatus_broker.LiveStatusRegenerator LiveStatusQueryCache = livestatus_broker.LiveStatusQueryCache LiveStatusClientThread = livestatus_broker.LiveStatusClientThread Logline = livestatus_broker.Logline LiveStatusLogStoreMongoDB = modulesctx.get_module('logstore-mongodb').LiveStatusLogStoreMongoDB LiveStatusLogStoreSqlite = modulesctx.get_module('logstore-sqlite').LiveStatusLogStoreSqlite livestatus_modconf = Module() livestatus_modconf.module_name = "livestatus" livestatus_modconf.module_type = livestatus_broker.properties['type'] livestatus_modconf.properties = livestatus_broker.properties.copy() class AlignakModulesTest(AlignakTest): def do_load_modules(self): self.modules_manager.load_and_init() self.log.log("I correctly loaded the modules: [%s]" % (','.join([inst.get_name() for inst in self.modules_manager.instances]))) def update_broker(self, dodeepcopy=False): # The brok should be manage in the good order ids = self.sched.brokers['Default-Broker']['broks'].keys() ids.sort()