def build(self, entity, options={}): alarm = options.pop('alarm', None) opt = merge_two_dicts(self.options, options) if alarm is None: alarm = self.alerts_collection.find_one({'d': entity['_id']}) links = {} if 'base_url' in opt: try: link = self.custom_format(opt['base_url'], entity, alarm) self.logger.debug(link) category = 'Liens' label = 'URL' if 'category' in opt: category = opt['category'] if 'label' in opt: label = opt['label'] links[category] = [{'label' : label, 'link' : link}] return links except ValueError: return {} except Exception as err: self.logger.exception('Unhandled error {} : {}'.format(type(err), err)) return {} return {}
def gen_fake_alarm(self, update={}, moment=None): """ Generate a fake alarm/value. """ if moment is None: moment = int(time.mktime(datetime.now().timetuple())) alarm_id = '/fake/alarm/id' alarm = self.manager.make_alarm( alarm_id, { 'connector': 'fake-connector', 'connector_name': 'fake-connector-name', 'component': 'c', 'output': 'out', 'timestamp': moment }) value = alarm[self.manager.alerts_storage.VALUE] value[AlarmField.state.value] = {'t': moment, 'val': Check.MINOR} value[AlarmField.steps.value] = [{ '_t': 'stateinc', 't': moment, 'a': 'fake-author', 'm': 'fake-message', 'val': Check.MINOR }] dictio = merge_two_dicts(alarm, update) return dictio, value
def build(self, entity, options={}): opt = merge_two_dicts(self.options, options) alarm = self.alerts_collection.find_one({'d': entity['_id']}) if 'base_url' in opt: link = self.custom_format(opt['base_url'], entity, alarm) self.logger.debug(link) return {self.category: [link]} return {}
def gen_alarm_filter(self, update={}, storage=None): """ Generate a standard alarm filter. """ base = { AlarmFilter.LIMIT: 180.0, AlarmFilter.FILTER: '', AlarmFilter.CONDITION: {}, AlarmFilter.TASKS: ['alerts.systemaction.state_increase'], } dictio = merge_two_dicts(base, update) return AlarmFilter(dictio, logger=self.logger, storage=storage)
def build(self, entity, options={}): opt = merge_two_dicts(self.options, options) if 'base_url' in opt: return {self.category: [opt['base_url'].format(**entity)]} return {}