def _get_available_models(broker, group=dr.GROUPS.single): """ Given a broker populated with datasources, return everything that could run based on them. """ state = set(broker.instances.keys()) models = {} for comp in dr.run_order(dr.COMPONENTS[group]): if comp in dr.DELEGATES and not plugins.is_datasource(comp): if dr.DELEGATES[comp].get_missing_dependencies(state): continue if plugins.is_type( comp, (plugins.rule, plugins.condition, plugins.incident)): name = "_".join( [dr.get_base_module_name(comp), dr.get_simple_name(comp)]) else: name = dr.get_simple_name(comp) if name in models: prev = models[name] models[dr.get_name(prev).replace(".", "_")] = prev del models[name] name = dr.get_name(comp).replace(".", "_") models[name] = comp state.add(comp) return models
def print_component(comp, verbose=False, specs=False): if (specs or (not specs and not is_type(comp, datasource))): print(dr.get_name(comp)) if not verbose: return space = " " * 4 dbl_space = space * 2 d = dr.get_delegate(comp) print(space + "Type: %s" % dr.get_name(d.type)) if is_type(comp, datasource): dump_ds(comp, space=space) print() if d.requires: print(space + "Requires:") for r in d.requires: print(dbl_space + dr.get_name(r)) else: print(space + "Requires: nothing") if d.at_least_one and d.at_least_one[0]: for one in d.at_least_one: print(space + "At least one of:") for o in one: print(dbl_space + dr.get_name(o)) if d.optional: print(space + "Optional:") for r in d.optional: print(dbl_space + dr.get_name(r)) dependents = dr.get_dependents(comp) if dependents: print(space + "Dependents:") for r in sorted(dependents, key=dr.get_name): print(dbl_space + dr.get_name(r)) print()
def _get_color(self, comp): if comp in self._broker: if plugins.is_type( comp, plugins.rule) and self._broker[comp].get("type") == "skip": return "yellow" return "green" elif comp in self._broker.exceptions: return "brightred" elif comp in self._broker.missing_requirements: return "yellow" else: return ""
def main(client): args = parse_args() rule_func = dr.get_component(args.plugin) if not is_type(rule_func, rule): print(f"{dr.get_name(rule_func)} is not a rule.") return archives = load_archives(args.input) hit_data = run_rule(archives, rule_func) hit_data = client.persist(hit_data) analysis = analyze(hit_data, rule_func) print(json.dumps(analysis))
def print_results(results, types, verbose): for r in results: if not types or is_type(r, types): print_component(r, verbose=verbose)
def _get_deps(rule_func): graph = dr.get_dependency_graph(rule_func) graph.update(dr.get_dependency_graph(RedHatRelease)) deps = [c for c in graph if is_type(c, condition) or is_type(c, incident)] return graph, deps
def print_results(results, types, verbose): print("Could have run:") print() for r in results: if not types or is_type(r, types): print_component(r, verbose=verbose)