Example #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)
Example #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)
Example #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()
Example #4
0
 def test_remove_pid(self):
     # create the pid file
     eq_(pid.create_pid(self.pid_dir, self.job.rule, str(os.getpid())), True)
     # remove the pid file
     pid.remove_pid(self.pid_dir, self.job.rule)
     # can't remove it again
     assert_raises(OSError, pid.remove_pid, self.pid_dir, self.job.rule)
Example #5
0
 def test_remove_pid(self):
     # create the pid file
     eq_(pid.create_pid(self.pid_dir, self.job.rule, str(os.getpid())),
         True)
     # remove the pid file
     pid.remove_pid(self.pid_dir, self.job.rule)
     # can't remove it again
     assert_raises(OSError, pid.remove_pid, self.pid_dir, self.job.rule)
Example #6
0
 def test_processes(self):
     eq_(pid.processes(self.pid_dir), [])
     eq_(pid.create_pid(self.pid_dir, self.job.rule, str(os.getpid())), True)
     actual = pid.processes(self.pid_dir)
     eq_(len(actual), 1)
     eq_(set(actual[0].keys()), set(["pid", "timestamp", "name"]))
     eq_(actual[0]["name"], "some_rule_name")
     ok_(int(actual[0]["pid"]) > 0)
     eq_(int(actual[0]["pid"]), os.getpid())
Example #7
0
 def test_processes(self):
     eq_(pid.processes(self.pid_dir), [])
     eq_(pid.create_pid(self.pid_dir, self.job.rule, str(os.getpid())),
         True)
     actual = pid.processes(self.pid_dir)
     eq_(len(actual), 1)
     eq_(set(actual[0].keys()), set(['pid', 'timestamp', 'name']))
     eq_(actual[0]['name'], 'some_rule_name')
     ok_(int(actual[0]['pid']) > 0)
     eq_(int(actual[0]['pid']), os.getpid())
Example #8
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 rule.retry:
            if rule.retry_limit > pid.get_retry_count(pid_dir, rule):
                log.error('%s: will be retried in %s hour(s)', rule_name,
                          rule.retry_delay)
                pid.create_next_retry(pid_dir, rule)
                pid.increment_retry_count(pid_dir, rule)
            else:
                log.error('%s: failed max retry limit (%s)', rule_name,
                          rule.retry_limit)
                pid.create_failed(pid_dir, rule)
    else:
        if rule.retry:
            # Failed before, however, ran successfully this time. Clean up fail/retry files
            pid.clean_up(pid_dir, rule)
        pid.create_last_complete(pid_dir, rule)
    finally:
        pid.remove_pid(pid_dir, rule)
        os._exit(0)
Example #9
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')
                self.run_rule(rule)
            time.sleep(1)
        self.die()
Example #10
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 rule.retry:
            if rule.retry_limit > pid.get_retry_count(pid_dir, rule):
                log.error('%s: will be retried in %s hour(s)', rule_name, rule.retry_delay)
                pid.create_next_retry(pid_dir, rule)
                pid.increment_retry_count(pid_dir, rule)
            else:
                log.error('%s: failed max retry limit (%s)', rule_name, rule.retry_limit)
                pid.create_failed(pid_dir, rule)
    else:
        if rule.retry:
            # Failed before, however, ran successfully this time. Clean up fail/retry files
            pid.clean_up(pid_dir, rule)
        pid.create_last_complete(pid_dir, rule)
    finally:
        pid.remove_pid(pid_dir, rule)
        os._exit(0)
Example #11
0
 def test_create_pid_exception(self):
     unknown_path = os.path.join('some', 'unknown', 'path')
     pid_dir = self.settings['pid_dir'] = unknown_path
     pid.create_pid(pid_dir, self.job.rule, str(os.getpid()))
Example #12
0
 def test_create_pid(self):
     # create the pid file
     eq_(pid.create_pid(self.pid_dir, self.job.rule, str(os.getpid())),
         True)
Example #13
0
 def test_create_pid_exception(self):
     unknown_path = os.path.join("some", "unknown", "path")
     pid_dir = self.settings["pid_dir"] = unknown_path
     pid.create_pid(pid_dir, self.job.rule, str(os.getpid()))
Example #14
0
 def test_create_pid(self):
     # create the pid file
     eq_(pid.create_pid(self.pid_dir, self.job.rule, str(os.getpid())), True)