コード例 #1
0
    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)
コード例 #2
0
ファイル: test_filter.py プロジェクト: capensis/canopsis
    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)
コード例 #3
0
ファイル: test_filter.py プロジェクト: capensis/canopsis
    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, [])
コード例 #4
0
    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)
コード例 #5
0
ファイル: test_filter.py プロジェクト: capensis/canopsis
    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)
コード例 #6
0
ファイル: manager.py プロジェクト: csu-xiao-an/canopsis
 def alarm_filters(self):
     """
     Automatic filters and actions for alarms.
     """
     return AlarmFilters(storage=self.filter_storage,
                         alarm_storage=self.alerts_storage,
                         logger=self.logger)
コード例 #7
0
    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, [])