Beispiel #1
0
def run_rule_async(rule_name, settings):
    setproctitle("inferno - %s" % rule_name)
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    signal.signal(signal.SIGTERM, signal.SIG_IGN)

    rules = get_rules_by_name(
        rule_name, settings['rules_directory'], immediate=False)
    if rules and len(rules) > 0:
        rule = rules[0]
    else:
        log.error('No rule exists with rule_name: %s' % rule_name)
        raise Exception('No rule exists with rule_name: %s' % rule_name)

    pid_dir = pid.pid_dir(settings)
    log.info("Running %s" % rule.name)
    try:
        pid.create_pid(pid_dir, rule, str(os.getpid()))
        execute_rule(rule, settings)
    except Exception as e:
        log.exception('%s: %s', rule_name, e)
        if not rule.retry:
            pid.create_last_run(pid_dir, rule)
    else:
        pid.create_last_run(pid_dir, rule)
    finally:
        pid.remove_pid(pid_dir, rule)
        os._exit(0)
Beispiel #2
0
def run_rule_async(rule_name, settings):
    setproctitle("inferno - %s" % rule_name)
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    signal.signal(signal.SIGTERM, signal.SIG_IGN)

    rules = get_rules_by_name(rule_name,
                              settings['rules_directory'],
                              immediate=False)
    if rules and len(rules) > 0:
        rule = rules[0]
    else:
        log.error('No rule exists with rule_name: %s' % rule_name)
        raise Exception('No rule exists with rule_name: %s' % rule_name)

    pid_dir = pid.pid_dir(settings)
    log.info("Running %s" % rule.name)
    try:
        pid.create_pid(pid_dir, rule, str(os.getpid()))
        execute_rule(rule, settings)
    except Exception as e:
        log.error('%s: %s', rule_name, e)
        if not rule.retry:
            pid.create_last_run(pid_dir, rule)
    else:
        pid.create_last_run(pid_dir, rule)
    finally:
        pid.remove_pid(pid_dir, rule)
        os._exit(0)
Beispiel #3
0
    def start(self):
        signal.signal(signal.SIGTERM, self.die)

        log.info('Starting Inferno...')
        auto_rules = get_rules(self.settings['rules_directory'])

        pid_dir = pid.pid_dir(self.settings)

        # keep cycling through the automatic rules
        while not self.stopped:
            # cycle through all the automatic rules
            for rule in auto_rules:
                if self.stopped:
                    break
                # skip this rule
                # check if pid file exists
                if not rule.run or self.paused or not pid.should_run(
                        pid_dir, rule):
                    continue

                pid.create_pid(pid_dir, rule, 'N/A')
                pid.create_last_run(pid_dir, rule)
                self.run_rule(rule)
            time.sleep(1)
        self.die()
Beispiel #4
0
    def start(self):
        signal.signal(signal.SIGTERM, self.die)

        log.info('Starting Inferno...')
        auto_rules = get_rules(self.settings['rules_directory'])

        pid_dir = pid.pid_dir(self.settings)

        # keep cycling through the automatic rules
        while not self.stopped:
            # cycle through all the automatic rules
            for rule in auto_rules:
                if self.stopped:
                    break
                # skip this rule
                # check if pid file exists
                if not rule.run or self.paused or not pid.should_run(pid_dir, rule):
                    continue

                pid.create_pid(pid_dir, rule, 'N/A')
                pid.create_last_run(pid_dir, rule)
                self.run_rule(rule)
            time.sleep(1)
        self.die()