Record the given RuleIndex on `self._tasks`.
771212
def _register_rules(self, rule_index):
    """"""
    registered = set()
    for output_type, rules in rule_index.rules.items():
      for rule in rules:
        key = (output_type, rule)
        if key in registered:
          continue
        registered.add(key)

        if type(rule) is TaskRule:
          self._register_task(output_type, rule, rule_index.union_rules)
        else:
          raise ValueError('Unexpected Rule type: {}'.format(rule))
972369
def list_tasks(collector, tasks, **kwargs):
    """"""
    print("Available tasks to choose from are:")
    print("Use the --task option to choose one")
    print("")
    keygetter = lambda item: item[1].label
    tasks = sorted(tasks.items(), key=keygetter)
    for label, items in itertools.groupby(tasks, keygetter):
        print("--- {0}".format(label))
        print("----{0}".format("-" * len(label)))
        sorted_tasks = sorted(list(items), key=lambda item: len(item[0]))
        max_length = max(len(name) for name, _ in sorted_tasks)
        for key, task in sorted_tasks:
            desc = dedent(task.description or "").strip().split('\n')[0]
            print("\t{0}{1} :-: {2}".format(" " * (max_length-len(key)), key, desc))
        print("")
742479
def on_rulebook(self, *args):
        """"""
        if self.rulebook is None:
            return
        self.rulebook.connect(self._trigger_redata, weak=False)
        self.redata()
807659
void addTaskToChain(Task[] tasks, Task task, int index) {
        task.setNext(tasks[index]);
        tasks[index] = task;
    }
261674
def index_run(record_path, keep_json, check_duplicate):
    
    from .config import ConfigStore
    from .indexer import Indexer
    cfstore = ConfigStore()
    indexer = Indexer(cfstore, check_duplicate, keep_json, record_path)
    indexer.index_all()
657244
def after_each_callback(eng, callback_func, obj):
        """"""
        obj.callback_pos = eng.state.callback_pos
        obj.extra_data["_last_task_name"] = callback_func.__name__
        task_history = get_task_history(callback_func)
        if "_task_history" not in obj.extra_data:
            obj.extra_data["_task_history"] = [task_history]
        else:
            obj.extra_data["_task_history"].append(task_history)
1031065
def monitor(i):
    """"""
    count = 0
    for x in i:
        count+=1
        if count % 10000 == 0:
            logger.info("%d records so far, current record is %s",
                count, x["idx"])
        yield x
796649
def on_records(self, records):
        
        handler = self.handlers.get("on_records")
        if callable(handler):
            handler(records)
815126
def index(self, *args, **kwargs):
        """"""
        self.check_session()
        result = self.session.index(*args, **kwargs)
        if self.autosession:
            self.commit()
        return result
952342
def WriteForemanRule(self, rule, cursor=None):
    """"""
    query = ("INSERT INTO foreman_rules "
             "  (hunt_id, expiration_time, rule) "
             "VALUES (%s, FROM_UNIXTIME(%s), %s) "
             "ON DUPLICATE KEY UPDATE "
             "  expiration_time=FROM_UNIXTIME(%s), rule=%s")

    exp_str = mysql_utils.RDFDatetimeToTimestamp(rule.expiration_time),
    rule_str = rule.SerializeToString()
    cursor.execute(query, [rule.hunt_id, exp_str, rule_str, exp_str, rule_str])
379855
def run(delayed, concurrency, version_type=None, queue=None,
        raise_on_error=True):
    """"""
    if delayed:
        celery_kwargs = {
            'kwargs': {
                'version_type': version_type,
                'es_bulk_kwargs': {'raise_on_error': raise_on_error},
            }
        }
        click.secho(
            'Starting {0} tasks for indexing records...'.format(concurrency),
            fg='green')
        if queue is not None:
            celery_kwargs.update({'queue': queue})
        for c in range(0, concurrency):
            process_bulk_queue.apply_async(**celery_kwargs)
    else:
        click.secho('Indexing records...', fg='green')
        RecordIndexer(version_type=version_type).process_bulk_queue(
            es_bulk_kwargs={'raise_on_error': raise_on_error})
1191468
def count(self, task):
        
        return len([c for c in task.corrections if c["event"]["@class"] == self.event_class])
714446
def Record(self, value):
    """"""
    self.sum += value
    self.count += 1

    pos = bisect.bisect(self.bins, value) - 1
    if pos < 0:
      pos = 0
    elif pos == len(self.bins):
      pos = len(self.bins) - 1

    self.heights[pos] += 1
74959
def done(self, index):
        
        if self.model.exists(index):
            self.model.edit(index, done=True)
1082178
def _subtask_result(self, idx, value):
        """"""
        self._results[idx] = value
        if len(self._results) == self._num_tasks:
            self.set_result([
                self._results[i]
                for i in range(self._num_tasks)
            ])
13744
def check(self, records):
        """"""
        for value, target in records:
            LOGGER.info("%s [%s]: %s", self.name, target, value)
            if value is None:
                self.notify(self.no_data, value, target)
                continue
            for rule in self.rules:
                if self.evaluate_rule(rule, value, target):
                    self.notify(rule['level'], value, target, rule=rule)
                    break
            else:
                self.notify('normal', value, target, rule=rule)

            self.history[target].append(value)
192418
def task_event_list(task_id, limit, filter_errors, filter_non_errors):
    
    client = get_client()

    # cannot filter by both errors and non errors
    if filter_errors and filter_non_errors:
        raise click.UsageError("Cannot filter by both errors and non errors")

    elif filter_errors:
        filter_string = "is_error:1"

    elif filter_non_errors:
        filter_string = "is_error:0"

    else:
        filter_string = ""

    event_iterator = client.task_event_list(
        task_id, num_results=limit, filter=filter_string
    )

    def squashed_json_details(x):
        is_json = False
        try:
            loaded = json.loads(x["details"])
            is_json = True
        except ValueError:
            loaded = x["details"]

        if is_json:
            return json.dumps(loaded, separators=(",", ":"), sort_keys=True)
        else:
            return loaded.replace("\n", "\\n")

    formatted_print(
        event_iterator,
        fields=(
            ("Time", "time"),
            ("Code", "code"),
            ("Is Error", "is_error"),
            ("Details", squashed_json_details),
        ),
        json_converter=iterable_response_to_dict,
    )