Ejemplo n.º 1
0
    def load(self, conf, args=None):
        """
        Discover and load all the rules as defined in the conf and args.
        :param dict conf: Configuration dict
        :param dict args: Arguments dict
        :return: List of rules
        :rtype: list
        """
        names = []
        use_rule = None if args is None else args.rule

        # Load each rule configuration file
        rules = []
        rule_files = self.get_names(conf, use_rule)
        for rule_file in rule_files:
            try:
                rule = self.load_configuration(rule_file, conf, args)
                # A rule failed to load, don't try to process it
                if not rule:
                    elastalert_logger.error('Invalid rule file skipped: %s' %
                                            rule_file)
                    continue
                if rule['name'] in names:
                    raise EAException('Duplicate rule named %s' %
                                      (rule['name']))
            except EAException as e:
                raise EAException('Error loading file %s: %s' % (rule_file, e))

            rules.append(rule)
            names.append(rule['name'])

        return rules
Ejemplo n.º 2
0
    def profile(self):
        profile_path = self.rules.get('profile')
        if profile_path is None:
            return {}
        now = time.time()

        try:
            if not (self._update_ts <= now <
                    self._update_ts + UPDATE_INTERVAL):
                # Check if updated
                ts = os.path.getmtime(profile_path)
                self._update_ts = now
            else:
                # Skip
                ts = self._profile_ts

            if ts > self._profile_ts or ts > now or now > self._profile_ts + FORCE_UPDATE_INTERVAL:
                elastalert_logger.info('Reloading profile %s', profile_path)
                with open(profile_path, 'r') as profile_file:
                    profile = json.load(profile_file)
                    self._profile = {
                        k: timedelta(seconds=profile[k])
                        for k in profile
                    }
                    self._profile_ts = now
        except (OSError, IOError, ValueError) as e:
            elastalert_logger.error('Cannot load profile %s: %s', profile_path,
                                    e)
        return self._profile
Ejemplo n.º 3
0
 def set_priority(self):
     try:
         if self.priority is not None and self.client is not None:
             self.jira_args['priority'] = {
                 'id': self.priority_ids[self.priority]
             }
     except KeyError:
         elastalert_logger.error(
             "Priority %s not found. Valid priorities are %s" %
             (self.priority, list(self.priority_ids.keys())))