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 test_bare_files(tmpdir): d = tmpdir / "bare" d.mkdir() p = d / 'sample.log' p.write(SAMPLE_LOG) data = [l.strip() for l in SAMPLE_LOG.splitlines()] testargs = [ "insights-run", "-t", "-m", "-b", 'insights.tests.spec_tests.TSpecs.sample_multioutput_file={fname}'. format(fname=os.path.join(tmpdir.strpath, 'bare', 'sample.log')), "-p", "insights.tests.spec_tests" ] with patch.object(sys, 'argv', testargs): broker = run(print_summary=True) assert broker is not None assert report_multioutput in broker assert broker[report_multioutput] == make_fail('MO_SPEC', data=data, number=1) testargs = [ "insights-run", "-t", "-m", "-b", 'insights.tests.spec_tests.TSpecs.sample_nonexistent={fname}'.format( fname=os.path.join(tmpdir.strpath, 'bare', 'sample.log')), "-p", "insights.tests.spec_tests" ] with patch.object(sys, 'argv', testargs): broker = run(print_summary=True) assert broker is not None assert report_nonexistent in broker assert broker[report_nonexistent] == make_fail('NE_SPEC', data=data) testargs = [ "insights-run", "-t", "-m", "-b", 'insights.tests.spec_tests.TSpecs.sample_raw_file={fname}'.format( fname=os.path.join(tmpdir.strpath, 'bare', 'sample.log')), "-p", "insights.tests.spec_tests" ] with patch.object(sys, 'argv', testargs): broker = run(print_summary=True) assert broker is not None assert report_raw in broker with open(os.path.join(tmpdir.strpath, 'bare', 'sample.log'), 'rb') as fh: data_b = fh.read() assert broker[report_raw] == make_fail('RA_SPEC', data=data_b)
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 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 report(): return make_fail("ERROR", foo="bar")
def show_links(): return make_fail("LINKS")
def report(a, b): return make_fail("FAIL2", a=a, b=b, c=a + b)
def report_fail(): return make_fail("FAIL")
def report_raw(rp): return make_fail('RA_SPEC', data=rp.data)
def report_nonexistent(nep): return make_fail('NE_SPEC', data=nep.data)
def report_multioutput(mop): return make_fail('MO_SPEC', data=mop[0].data, number=len(mop))
def report(package): if package: return make_fail(ERROR_KEY, installed_package=package, kcs=KCS)
def report(): return make_fail("SOME_FAIL", foo="bar")
def report(uname): if uname.fixed_by('2.6.32-431.11.2.el6', introduced_in='2.6.32-431.el6'): return make_fail("VULNERABLE_KERNEL", kernel=uname.kernel)
def is_insights_heartbeat(hostname): hostname = hostname.hostname if hostname == HOST: return make_fail(ERROR_KEY)