def main(): args = parse_args() plugins = parse_plugins(args.plugins) for p in plugins: dr.load_components(p, continue_on_error=False) results = defaultdict(list) for comp, delegate in dr.DELEGATES.items(): if isinstance(delegate, rule): results[dr.get_base_module_name(comp)].append(comp) results = dict( (key, comps) for key, comps in results.items() if len(comps) > 1) if results: print("Potential key conflicts:") print() for key in sorted(results): print("{key}:".format(key=key)) for comp in sorted(results[key], key=dr.get_name): name = comp.__name__ path = inspect.getabsfile(comp) print(" {name} in {path}".format(name=name, path=path)) print()
def load_default_components(): default_packages = [ "insights.specs.default", "insights.specs.insights_archive", "insights.specs.sos_archive", "insights.specs.jdr_archive", "insights.parsers", "insights.combiners", ] for p in default_packages: dr.load_components(p, continue_on_error=False)
def insights_call(data_str): decoded_str = base64.b64decode(data_str) data_dict = json.loads(decoded_str) try: if "INSIGHTS_RULES" in os.environ: rules_list = os.environ["INSIGHTS_RULES"].split(":") for rule_path in rules_list: if len(rule_path) == 0: continue if rule_path.endswith("/"): rule_path = rule_path[:-1] if rule_path not in sys.path: sys.path.append(rule_path) dr.load_components(os.path.basename(rule_path)) except Exception as e: return str(e) try: dr.load_components("insights.specs.default") broker = dr.Broker() broker[Specs.hostname] = context_wrap(data_dict["hostname"]) broker[Specs.uname] = context_wrap(data_dict["uname"]) broker[Specs.dmesg] = context_wrap(data_dict["dmesg"]) broker[Specs.messages] = context_wrap(data_dict["dmesg"]) broker[Specs.sysctl] = context_wrap(data_dict["sysctl"]) broker[Specs.meminfo] = context_wrap(data_dict["meminfo"]) broker[Specs.ps_aux] = context_wrap(data_dict["ps_aux"]) broker[Specs.ps_auxcww] = context_wrap(data_dict["ps_auxcww"]) broker[Specs.ps_auxww] = context_wrap(data_dict["ps_auxww"]) broker[Specs.ps_ef] = context_wrap(data_dict["ps_ef"]) output = six.StringIO() with Formatter(broker, stream=output): dr.run(broker=broker) output.seek(0) data = output.read() return data except Exception as e: return str(e)
def main(): args = _parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.ERROR) cov = None if not args.no_coverage: from coverage import Coverage cov = Coverage(cover_pylib=False) cov.start() if not args.no_defaults: load_default_plugins() dr.load_components("insights.parsers", "insights.combiners") load_packages(parse_plugins(args.plugins)) _handle_config(args.config) start_session(args.paths, args.cd, __coverage=cov, kernel=args.kernel) if cov: cov.stop() cov.erase()
Call Trace: [<ffffffff812a4641>] ? radix_tree_gang_lookup_slot+0x81/0xf0 [<ffffffff81130c0b>] ? find_get_pages+0x3b/0x150 [<ffffffff81147432>] ? pagevec_lookup+0x22/0x30 [<ffffffff81148f44>] ? invalidate_mapping_pages+0x84/0x1e0 [<ffffffff811cc2ee>] ? drop_caches_sysctl_handler+0x12e/0x1d0 [<ffffffff81213e9c>] ? proc_sys_call_handler+0x9c/0xd0 [<ffffffff81213ee4>] ? proc_sys_write+0x14/0x20 [<ffffffff8119cb5a>] ? vfs_write+0xba/0x1a0 [<ffffffff8119e056>] ? fget_light_pos+0x16/0x50 [<ffffffff8119d691>] ? sys_write+0x51/0xb0 [<ffffffffa03eea23>] ? symev_write+0x53/0xa0 [symev_rh_ES_6_2_6_32_431_el6_x86_64] [<ffffffff8155e351>] ? system_call_fastpath+0x2f/0x34 """.strip() dr.load_components("rules") dr.load_components("insights.specs.default") # Below 3 components are not working as it's based on python2 #dr.load_components("telemetry") #dr.load_components("diag_insights_rules") #dr.load_components("prodsec") dr.load_components("support-rules") broker = dr.Broker() broker[Specs.hostname] = context_wrap("www.example.com") #broker[Specs.kernel] = context_wrap("2.6.32-696.23.1.el6.x86_64") broker[Specs.uname] = context_wrap( "Linux a03a5df6f247 2.6.32-696.23.1.el6.x86_64 #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 GNU/Linux" ) broker[Specs.dmesg] = context_wrap(MSGINFO) with Formatter(broker): dr.run(broker=broker)
def load_packages(pkgs): for p in pkgs: dr.load_components(p, continue_on_error=False)
from insights.core import filters if len(sys.argv) < 3: print("Provide uploader.json location and packages to load") sys.exit(1) json_path = sys.argv[1] if not os.path.exists(json_path): print("Provided uploader.json path does not exist.") sys.exit(1) with open(json_path) as fp: uploader_json = json.load(fp, object_pairs_hook=OrderedDict) dr.load_components("insights.specs.default") dr.load_components("insights.parsers") dr.load_components("insights.combiners") for package in sys.argv[2:]: dr.load_components(package) filters.dump() specs = sorted(vars(Specs)) filters = {} for spec in specs: s = getattr(Specs, spec) if type(s) == RegistryPoint: f = get_filters(s) if f: filters[spec] = sorted(f)
#!/usr/bin/env python3.6 from insights import dr from insights.formats.text import HumanReadableFormat as Formatter # from insights.formats._json import JsonFormat as Formatter dr.load_components("rules") broker = dr.Broker() with Formatter(broker): dr.run(broker=broker)
def load_plugins(raw): if raw: for p in parse_plugins(raw): dr.load_components(p, continue_on_error=False)
def preload_components(comps): if comps: for c in comps.split(","): dr.load_components(c.strip(), continue_on_error=False)
def load_default_plugins(): for f in ["default", "insights_archive", "sos_archive", "jdr_archive"]: dr.load_components("insights.specs.%s" % f, continue_on_error=False)
facts = dict( insights_id=valid_uuid_or_None(_safe_parse(insights_id)), machine_id=valid_uuid_or_None(_safe_parse(machine_id)), bios_uuid=valid_uuid_or_None(_safe_parse(bios_uuid)), subscription_manager_id=valid_uuid_or_None(submanid.data if submanid else None), ip_addresses=ips.data if ips else [], mac_addresses=valid_mac_addresses(mac_addresses) if mac_addresses else [], fqdn=_safe_parse(fqdn), ) return make_metadata(**_filter_falsy(facts)) def get_canonical_facts(path=None): set_enabled(canonical_facts, True) set_enabled(SubscriptionManagerID, True) set_enabled(IPs, True) br = run(canonical_facts, root=path) d = br[canonical_facts] del d["type"] return d if __name__ == "__main__": import json from insights import dr dr.load_components("insights.specs.default", "insights.specs.insights_archive") print(json.dumps(get_canonical_facts()))
This function is registered globally with insights core to watch fact_set components as they're evaluated. """ if component in broker: system_id = None value = broker[component] if Specs.machine_id in broker: system_id = broker[Specs.machine_id].content[0] if isinstance(value, list): for v in value: v.system_id = system_id session.add_all(value) else: value.system_id = system_id session.add(value) session.commit() # register the saver above to watch fact_sets dr.add_observer(saver, fact_set) dr.add_finished_loading_callback(loading_finished) # run our components if __name__ == "__main__": dr.load_components("insights_facts.plugins") comps = dr.COMPONENTS_BY_TYPE[fact_set] run(comps, print_summary=True)