def report(shas, meta): """ Cluster rule to compare ntp.conf files across a cluster ``shas`` is a Pandas DataFrame for the facts for each host by the fact ``ntp_sha256``. See https://pandas.pydata.org/pandas-docs/stable/api.html#dataframe for information on available attributes and methods. ``meta`` is a dictionary that contains the information from the cluster topology file provided by the ``-i`` switch. The dictionary keys are the sections, and the values are a list of the host information provided in the toplolgy file. Arguments: shas (pandas.DataFrame): Includes facts from ``ntp_sha256`` fact with column "sha" and one row per host in the cluster. meta (dict): Keys are the sections in the topology file and values are a list of the values in the section. """ num_members = meta.num_members uniq = shas.sha.unique() if len(shas) != num_members or len(uniq) != 1: return make_fail("DISTINCT_NTP_CONFS", confs=len(uniq), nodes=num_members) return make_pass("MATCHING_NTP_CONFS", nodes=meta['nodes'], servers=meta['servers'])
def check_bash_bug(rpms): bug_version = InstalledRpm.from_package('bash-4.4.14-1.any') fix_version = InstalledRpm.from_package('bash-4.4.18-1.any') current_version = rpms.get_max('bash') if bug_version <= current_version < fix_version: return make_fail(ERROR_KEY_BASH_BUG_PRESENT, bash=current_version.nvr) else: return make_pass(ERROR_KEY_BASH_BUG_NOT_PRESENT, bash=current_version.nvr)
def report_rhel_others(hp): """ Rule reports a response if there is more than 1 host entry defined in the /etc/hosts file. Arguments: hp (HostParser): Parser object for the custom parser in this module. """ if len(hp.hosts) > 1: return make_fail("TOO_MANY_HOSTS", num=len(hp.hosts)) return make_pass("TOO_MANY_HOSTS", num=len(hp.hosts))
def report_rhel8(hp): """ Rule reports a response if there is more than 1 host entry defined in the /etc/hosts file. Arguments: hp (ParserFedoraHosts): Parser object for the custom parser in this module. This parser will only fire if the content is from a Fedora server """ if len(hp.hosts) > 1: return make_fail("TOO_MANY_HOSTS", num=len(hp.hosts)) return make_pass("TOO_MANY_HOSTS", num=len(hp.hosts))
def check_bash_bug(rpms): bug_version = InstalledRpm.from_package('bash-4.4.14-1.any') fix_version = InstalledRpm.from_package('bash-4.4.18-1.any') current_version = rpms.get_max('bash') if bug_version <= current_version < fix_version: found = "Bash bug found! Version: " return make_fail(ERROR_KEY_BASH_BUG, bash=current_version.nvr, found=found) else: not_found = "Bash bug not found: " return make_pass(ERROR_KEY_BASH_BUG, bash=current_version.nvr, found=not_found)
def report(hn, rhr, cpu, mem, un, ut, dt): return make_pass("SYSTEM_INFO", fqdn=hn.fqdn, product=rhr.product, major=rhr.major, minor=rhr.minor, kernel=un.kernel, up_days=ut.updays, load_avg=ut.loadavg, date=dt.data, cpus=cpu.cpu_count, sockets=cpu.socket_count, mem_total=mem.total / 1024, mem_avail=mem.available / 1024)
def bash_rule(bash, hostnames): """ Cluster rule to process bash and hostname info ``bash`` and ``hostnames`` are Pandas DataFrames for the facts collected for each host in the cluster. See https://pandas.pydata.org/pandas-docs/stable/api.html#dataframe for information on available attributes and methods. Arguments: bash (pandas.DataFrame): Includes facts from ``bash_version`` fact with columns "name" and "version" and one row per host in the cluster. hostnames (pandas.DataFrame): Includes facts from ``get_hostname`` fact with column "hostname" and one row per host in the cluster. """ if isinstance(bash, dict): return make_fail('bash_rule', error_message="Run this rule with a cluster archive") return make_pass('bash_rule', bash=bash, hostname=hostnames)
def test_run_incremental(): broker = dr.Broker() broker["dep1"] = 1 broker["dep2"] = 2 broker["common"] = 3 graph = dr.get_dependency_graph(stage1) graph.update(dr.get_dependency_graph(stage2)) graph.update(dr.get_dependency_graph(stage3)) graph.update(dr.get_dependency_graph(stage4)) brokers = list(dr.run_incremental(graph, broker)) assert len(brokers) == 3 ALWAYS_FIRES_RESULT = make_pass("ALWAYS_FIRES", kernel="this is junk") NEVER_FIRES_RESULT = { 'rule_fqdn': 'insights.plugins.never_fires.report', 'reason': 'MISSING_REQUIREMENTS', 'details': "All: ['insights.plugins.never_fires.thing'] Any: ", 'type': 'skip'} REDHAT_RELEASE = "Red Hat Enterprise Linux Server release 7.3 (Maipo)" UNAME = "Linux test.redhat.com 3.10.0-514.el7.x86_64 #1 SMP Wed Oct 19 11:24:13 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux" def test_run_command(): broker = run([always_fires.report, never_fires.report]) assert broker is not None assert always_fires.report in broker assert never_fires.report in broker
def report2(): return make_pass("SOME_PASS", foo="bar")
def report(nss): doc = json.loads(nss.content) return make_pass("DEMO", namespaces=doc)
def report_pass(): return make_pass("PASS")
def psaux_no_filter(ps_aux): return make_pass("FAKE RESULT")
def psalxwww_parser_filter(ps_alxwww): return make_pass("FAKE RESULT")
def psauxww_ds_filter(ps_auxww): return make_pass("FAKE RESULT")
def report(t): return make_pass("THING")
def report(): if True: return make_pass("ALWAYS_FIRES", kernel="this is junk")