def test_get_filter_s(self): alarm, value = self.gen_fake_alarm() self.manager.update_current_alarm(alarm, value) lifter = self.gen_alarm_filter( {AlarmFilter.FILTER: '{"v.connector":{"$eq":"wrong-connector"}}'}, storage=self.filter_storage) lifter.save() lifter = self.gen_alarm_filter( {AlarmFilter.FILTER: '{"v.connector":{"$eq":"fake-connector"}}'}, storage=self.filter_storage) lifter.save() # get_filters() alarm_filters = AlarmFilters(storage=self.filter_storage, alarm_storage=self.alerts_storage, logger=logging.getLogger('alerts')) result = alarm_filters.get_filters() _id = result[0][0]._id self.assertTrue(isinstance(result, list)) self.assertEqual(len(result), 1) # get_filter() result = alarm_filters.get_filter(_id) self.assertEqual(result[0][AlarmFilter.UID], _id)
def test_get_filter_s(self): alarm, value = self.gen_fake_alarm() self.manager.update_current_alarm(alarm, value) lifter = self.gen_alarm_filter({ AlarmFilter.FILTER: '{"v.connector":{"$eq":"wrong-connector"}}' }, storage=self.filter_storage) lifter.save() lifter = self.gen_alarm_filter({ AlarmFilter.FILTER: '{"v.connector":{"$eq":"fake-connector"}}' }, storage=self.filter_storage) lifter.save() # get_filters() alarm_filters = AlarmFilters(storage=self.filter_storage, alarm_storage=self.alerts_storage, logger=logging.getLogger('alerts')) result = alarm_filters.get_filters() _id = result[0][0]._id self.assertTrue(isinstance(result, list)) self.assertEqual(len(result), 1) # get_filter() result = alarm_filters.get_filter(_id) self.assertEqual(result[0][AlarmFilter.UID], _id)
def test_crud(self): alarm_filters = AlarmFilters(storage=self.filter_storage, alarm_storage=self.alerts_storage, logger=logging.getLogger('alerts')) result = alarm_filters.get_filters() self.assertEqual(result, []) # Init alarm, value = self.gen_fake_alarm() self.manager.update_current_alarm(alarm, value) element = { AlarmFilter.LIMIT: 30.0, AlarmFilter.CONDITION: {}, AlarmFilter.TASKS: ['alerts.useraction.comment'], AlarmFilter.FILTER: { "d": alarm[self.alerts_storage.DATA_ID] } } # CREATE result = alarm_filters.create_filter(element) result.save() self.assertEqual(result[AlarmFilter.CONDITION], {}) element['_id'] = result._id # GET result = alarm_filters.get_filters() self.assertEqual(result[0][0].element, element) another_cond = '{"key": {"$eq": "another"}}' update = {AlarmFilter.CONDITION: another_cond} result = alarm_filters.update_filter('/not/an/alarm', values=update) self.assertTrue(result is None) # UPDATE result = alarm_filters.update_filter(element['_id'], values=update) self.assertEqual( result[AlarmFilter.CONDITION]['key']['$eq'], 'another') update = {AlarmFilter.LIMIT: 666, AlarmFilter.REPEAT: 3} result = alarm_filters.update_filter(element['_id'], values=update) self.assertEqual(result[AlarmFilter.LIMIT], timedelta(seconds=666)) self.assertEqual(result[AlarmFilter.REPEAT], 3) # GET result = alarm_filters.get_filters() self.assertEqual( result[0][0][AlarmFilter.CONDITION]['key']['$eq'], 'another') # DELETE result = alarm_filters.delete_filter(element['_id']) self.assertEqual(result['ok'], 1.0) # GET result = alarm_filters.get_filters() self.assertEqual(result, [])
def test_get_filters_empty_filter(self): alarm, value = self.gen_fake_alarm() self.manager.update_current_alarm(alarm, value) lifter = self.gen_alarm_filter({AlarmFilter.FILTER: ''}, storage=self.filter_storage) lifter.save() alarm_filters = AlarmFilters(storage=self.filter_storage, alarm_storage=self.alerts_storage, logger=logging.getLogger('alerts')) result = alarm_filters.get_filters() self.assertTrue(isinstance(result, list)) self.assertTrue(len(result) >= 1)
def test_get_filters_empty_filter(self): alarm, value = self.gen_fake_alarm() self.manager.update_current_alarm(alarm, value) lifter = self.gen_alarm_filter({ AlarmFilter.FILTER: '' }, storage=self.filter_storage) lifter.save() alarm_filters = AlarmFilters(storage=self.filter_storage, alarm_storage=self.alerts_storage, logger=logging.getLogger('alerts')) result = alarm_filters.get_filters() self.assertTrue(isinstance(result, list)) self.assertTrue(len(result) >= 1)
def alarm_filters(self): """ Automatic filters and actions for alarms. """ return AlarmFilters(storage=self.filter_storage, alarm_storage=self.alerts_storage, logger=self.logger)
def test_crud(self): alarm_filters = AlarmFilters(storage=self.filter_storage, alarm_storage=self.alerts_storage, logger=logging.getLogger('alerts')) result = alarm_filters.get_filters() self.assertEqual(result, []) # Init alarm, value = self.gen_fake_alarm() self.manager.update_current_alarm(alarm, value) element = { AlarmFilter.LIMIT: 30.0, AlarmFilter.CONDITION: {}, AlarmFilter.TASKS: ['alerts.useraction.comment'], AlarmFilter.FILTER: { "d": alarm[self.alerts_storage.DATA_ID] } } # CREATE result = alarm_filters.create_filter(element) result.save() self.assertEqual(result[AlarmFilter.CONDITION], {}) element['_id'] = result._id # GET result = alarm_filters.get_filters() self.assertEqual(result[0][0].element, element) another_cond = '{"key": {"$eq": "another"}}' update = {AlarmFilter.CONDITION: another_cond} result = alarm_filters.update_filter('/not/an/alarm', values=update) self.assertTrue(result is None) # UPDATE result = alarm_filters.update_filter(element['_id'], values=update) self.assertEqual(result[AlarmFilter.CONDITION]['key']['$eq'], 'another') update = {AlarmFilter.LIMIT: 666, AlarmFilter.REPEAT: 3} result = alarm_filters.update_filter(element['_id'], values=update) self.assertEqual(result[AlarmFilter.LIMIT], timedelta(seconds=666)) self.assertEqual(result[AlarmFilter.REPEAT], 3) # GET result = alarm_filters.get_filters() self.assertEqual(result[0][0][AlarmFilter.CONDITION]['key']['$eq'], 'another') # DELETE result = alarm_filters.delete_filter(element['_id']) self.assertEqual(result['ok'], 1.0) # GET result = alarm_filters.get_filters() self.assertEqual(result, [])