def test_brok_acknowledge_expire_extcommand_hunknown(self): """Test with a brok acknowledge_expire come from external command or scheduler if service/ host come up or acknowledge is expired (so not from backend). The host name is unknown (not exist) in the backend :return: None """ actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 0) # send acknowledge_raise brok to our broker module data = { 'ref': '90843789574897', 'sticky': 1, 'persistent': 1, 'author': 'admin', 'comment': 'blablabla1', 'end_time': 0, 'notify': 1 } ack = Acknowledge(data) b = ack.get_expire_brok('srv050') b.prepare() self.brokmodule.get_refs() self.brokmodule.manage_brok(b) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 0)
def test_brok_acknowledge_raise_extcommand_hknown(self): """Test with a brok acknowledge_raise come from external command (so not from backend). The host name is known in the backend :return: None """ actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 0) # send acknowledge_raise brok to our broker module data = { 'ref': '90843789574897', 'sticky': 2, 'persistent': 1, 'author': 'admin', 'comment': 'blablabla1', 'end_time': 0, 'notify': 1 } ack = Acknowledge(data) b = ack.get_raise_brok('srv001') b.prepare() self.brokmodule.get_refs() self.brokmodule.manage_brok(b) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 1) self.assertEqual(actionack['_items'][0]['comment'], 'blablabla1') self.assertEqual(actionack['_items'][0]['notified'], True) self.assertEqual(actionack['_items'][0]['sticky'], False) hosts = self.backend.get_all('host') self.assertEqual(len(hosts['_items']), 2) self.assertEqual(hosts['_items'][1]['name'], 'srv001') self.assertEqual(hosts['_items'][1]['ls_acknowledged'], True)
def test_brok_acknowledge_expire_backend(self): """Test with a brok acknowledge_expire come from backend :return: None """ # update the host with ls_acknowledged = True headers = { 'Content-Type': 'application/json', 'If-Match': self.data_host['_etag'] } self.backend.patch('host/%s' % self.data_host['_id'], {"ls_acknowledged": True}, headers, True) hosts = self.backend.get_all('host') self.assertEqual(len(hosts['_items']), 2) self.assertEqual(hosts['_items'][1]['name'], 'srv001') self.assertEqual(hosts['_items'][1]['ls_acknowledged'], True) data_ack = { 'action': 'delete', 'host': self.data_host['_id'], 'service': None, 'user': self.user_id, 'comment': 'Ack from the backend', 'processed': True } self.backend.post("actionacknowledge", data_ack) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 1) self.assertEqual(actionack['_items'][0]['notified'], False) # send acknowledge_raise brok to our broker module data = { 'ref': '90843789574897', 'sticky': actionack['_items'][0]['sticky'], 'persistent': actionack['_items'][0]['persistent'], 'author': 'admin', 'comment': actionack['_items'][0]['comment'], 'end_time': 0, 'notify': actionack['_items'][0]['notify'] } ack = Acknowledge(data) b = ack.get_expire_brok('srv001') b.prepare() self.brokmodule.get_refs() self.brokmodule.manage_brok(b) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 1) self.assertEqual(actionack['_items'][0]['notified'], True) hosts = self.backend.get_all('host') self.assertEqual(len(hosts['_items']), 2) self.assertEqual(hosts['_items'][1]['name'], 'srv001') self.assertEqual(hosts['_items'][1]['ls_acknowledged'], False)
def test_brok_acknowledge_expire_extcommand_hknown(self): """Test with a brok acknowledge_expire come from external command or scheduler if service/ host come up or acknowledge is expired (so not from backend). The host name is known in the backend :return: None """ # update the host with ls_acknowledged = True headers = { 'Content-Type': 'application/json', 'If-Match': self.data_host['_etag'] } self.backend.patch('host/%s' % self.data_host['_id'], {"ls_acknowledged": True}, headers, True) hosts = self.backend.get_all('host') self.assertEqual(len(hosts['_items']), 2) self.assertEqual(hosts['_items'][1]['name'], 'srv001') self.assertEqual(hosts['_items'][1]['ls_acknowledged'], True) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 0) # send acknowledge_raise brok to our broker module data = { 'ref': '90843789574897', 'sticky': 2, 'persistent': 1, 'author': 'admin', 'comment': 'blablabla1', 'end_time': 0, 'notify': 1 } ack = Acknowledge(data) b = ack.get_expire_brok('srv001') b.prepare() self.brokmodule.get_refs() self.brokmodule.manage_brok(b) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 1) self.assertEqual(actionack['_items'][0]['comment'], 'blablabla1') self.assertEqual(actionack['_items'][0]['notified'], True) self.assertEqual(actionack['_items'][0]['sticky'], False) self.assertEqual(actionack['_items'][0]['action'], 'delete') hosts = self.backend.get_all('host') self.assertEqual(len(hosts['_items']), 2) self.assertEqual(hosts['_items'][1]['name'], 'srv001') self.assertEqual(hosts['_items'][1]['ls_acknowledged'], False)
def test_brok_acknowledge_raise_backend_s(self): """Test with a brok acknowledge_raise come from backend (service) :return: None """ data_ack = { 'action': 'add', 'host': self.data_host['_id'], 'service': self.data_srv_http['_id'], 'user': self.user_id, 'comment': 'Ack from the backend', 'processed': True } self.backend.post("actionacknowledge", data_ack) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 1) self.assertEqual(actionack['_items'][0]['notified'], False) # send acknowledge_raise brok to our broker module data = { 'ref': '90843789574897', 'sticky': actionack['_items'][0]['sticky'], 'persistent': actionack['_items'][0]['persistent'], 'author': 'admin', 'comment': actionack['_items'][0]['comment'], 'end_time': 0, 'notify': actionack['_items'][0]['notify'] } ack = Acknowledge(data) b = ack.get_raise_brok('srv001', 'http toto.com') b.prepare() self.brokmodule.get_refs() self.brokmodule.manage_brok(b) actionack = self.backend.get_all('actionacknowledge') self.assertEqual(len(actionack['_items']), 1) self.assertEqual(actionack['_items'][0]['processed'], True) self.assertEqual(actionack['_items'][0]['notified'], True) services = self.backend.get_all('service') self.assertEqual(len(services['_items']), 2) self.assertEqual(services['_items'][1]['name'], 'http toto.com') self.assertEqual(services['_items'][1]['host'], self.data_host['_id']) self.assertEqual(services['_items'][1]['ls_acknowledged'], True)