def decode_rule(self, rule): name = rule['rule']['name'] key = rule['rule']['key'] alert_by = rule['alerts'] action = Webhook(rule['rule']['action']['url']) conditions = [] for c in rule['rule']['conditions']: trigger = Trigger(c['trigger']['name'], c['trigger']['arguments']) filters = [] for f in c['filter']['and']: _filter = Filter(f['operation'], f['type'], f['arguments']) filters.append(_filter) condition = Condition(filters, trigger) conditions.append(condition) selection = { 'devices': decode_selection(rule['search']['filters']['devices'], selection_type='devices'), 'sensors': decode_selection(rule['search']['filters']['sensors'], selection_type='sensors'), } return Rule(name, alert_by=alert_by, key=key, conditions=conditions, action=action, selection=selection)
def _resource_types(ez_content_options): resource_types = [] for resource_type in ez_content_options: # For now we are going to ignore negating these cases if not EZParseHelper.is_ez_negated(resource_type) \ and Trigger.is_valid_resource_type(resource_type): resource_types.append(resource_type) return resource_types
def _trigger_from_ez(ez_rule): trigger = Trigger() trigger.url_filter = EZTranslator._regex_url_filter( ez_rule.url_filter, ez_rule.type) trigger.resource_type = EZTranslator._resource_types( ez_rule.content_options) trigger.load_type = EZTranslator._load_types(ez_rule.load_types) trigger.if_domain = EZTranslator._if_domains(ez_rule.domains) trigger.unless_domain = EZTranslator._unless_domains(ez_rule.domains) return trigger
def _trigger_from_ez(ez_rule): trigger = Trigger() trigger.url_filter = EZTranslator._regex_url_filter(ez_rule.url_filter, ez_rule.type) trigger.resource_type = EZTranslator._resource_types(ez_rule.content_options) trigger.load_type = EZTranslator._load_types(ez_rule.load_types) trigger.if_domain = EZTranslator._if_domains(ez_rule.domains) trigger.unless_domain = EZTranslator._unless_domains(ez_rule.domains) return trigger