Beispiel #1
0
def get_kernel_version_from_grub_conf(workdir,
                                      input="boot/grub/grub.conf.json"):
    """
    :see: ``sos_analyzer.scanner.grub``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    default_boot_idx = None
    for d in data:
        if d.get("option", None) == "default":
            default_boot_idx = int(d.get("value", 0))
            break

    if default_boot_idx is None:
        logging.warn("Could not find the default boot idx in " + input)
        return None

    kernels = [d for d in data if d.get("title", False)]
    try:
        return kernels[default_boot_idx].get("kernel", None)
    except Exception:
        logging.error("Failed to get the default boot kernel")
        return None
Beispiel #2
0
def get_kernel_version_from_grub_conf(workdir,
                                      input="boot/grub/grub.conf.json"):
    """
    :see: ``sos_analyzer.scanner.grub``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    default_boot_idx = None
    for d in data:
        if d.get("option", None) == "default":
            default_boot_idx = int(d.get("value", 0))
            break

    if default_boot_idx is None:
        logging.warn("Could not find the default boot idx in " + input)
        return None

    kernels = [d for d in data if d.get("title", False)]
    try:
        return kernels[default_boot_idx].get("kernel", None)
    except Exception:
        logging.error("Failed to get the default boot kernel")
        return None
Beispiel #3
0
def get_locale(workdir, input="etc/sysconfig/i18n.json"):
    """
    :see: ``sos_analyzer.scanner.etc_sysconfig_i18n``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        for d in data:
            if d.get("option", '') == "LANG":
                return d.get("value")
Beispiel #4
0
def list_normal_filesystems(workdir, input="df.json"):
    """
    :see: ``sos_analyzer.scanner.df``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        for d in data:
            if d.get("used_rate", False):
                yield d
Beispiel #5
0
def get_kernel_version_from_uname(workdir, input="uname.json"):
    """
    :see: ``sos_analyzer.scanner.uname``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        return data[0].get("kernel_release", None)

    return None
Beispiel #6
0
def get_kernel_version_from_uname(workdir, input="uname.json"):
    """
    :see: ``sos_analyzer.scanner.uname``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        return data[0].get("kernel_release", None)

    return None
Beispiel #7
0
def find_lvm_device_filter(workdir, input="etc/lvm/lvm.conf.json"):
    """
    :see: ``sos_analyzer.scanner.etc_lvm_lvm_conf``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        for section in data:
            if section["title"] == "devices":
                return section["values"].get("filter", [])
Beispiel #8
0
def find_lvm_device_filter(workdir, input="etc/lvm/lvm.conf.json"):
    """
    :see: ``sos_analyzer.scanner.etc_lvm_lvm_conf``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        for section in data:
            if section["title"] == "devices":
                return section["values"].get("filter", [])
Beispiel #9
0
def find_hw_error_suspects_g(workdir, pattern, input="var/log/messages.json"):
    """
    :see: ``sos_analyzer.scanner.var_log_messages``
    """
    reg = re.compile(pattern, re.IGNORECASE)
    data = Base.load_scanned_data(workdir, input)
    if data:
        for d in data:
            if reg.match(d.get("message", '')):
                yield d
Beispiel #10
0
def get_cur_runlevel(workdir, default=3,
                     input="sos_commands/startup/runlevel.json"):
    """
    :see: ``sos_analyzer.scanner.runlevel``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        return int(data[0].get("cur_runlevel", default))

    return default
Beispiel #11
0
def is_sysstat_cronjob_enabled(workdir, input="etc/cron.d/sysstat.json"):
    """
    :see: ``sos_analyzer.scanner.etc_crond_sysstat``
    """
    data = Base.load_scanned_data(workdir, input)
    reg = re.compile(r"^/usr/lib.+/sa/sa.+")
    if data:
        return any(reg.match(d.get("command", '')) for d in data)

    return False
Beispiel #12
0
def find_hw_error_suspects_g(workdir, pattern, input="var/log/messages.json"):
    """
    :see: ``sos_analyzer.scanner.var_log_messages``
    """
    reg = re.compile(pattern, re.IGNORECASE)
    data = Base.load_scanned_data(workdir, input)
    if data:
        for d in data:
            if reg.match(d.get("message", '')):
                yield d
Beispiel #13
0
def find_ng_dev_specs(workdir, ng_devs_re=NG_DEVS_RE, input="etc/fstab.json"):
    """
    :see: ``sos_analyzer.scanner.etc_fstab``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        for d in data:
            dev = d["device"]
            m = ng_devs_re.match(dev)
            if m:
                yield d
Beispiel #14
0
def list_modified_g(workdir, input="rpm-Va.json", flags=FLAGS):
    """
    :see: ``sos_analyzer.scanner.rpm_Va``
    """
    data = Base.load_scanned_data(workdir, input)
    if data:
        for d in data:
            ms = [(f, d[f]) for f in flags if d.get(f, '.') != '.']
            if ms:
                d["modified"] = ", ".join(m[0] for m in ms)

                yield d
Beispiel #15
0
def is_sysrq_enabled(workdir, input="sos_commands/kernel/sysctl_-a.json"):
    """
    :see: ``sos_analyzer.scanner.sysctl_a``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    for d in data:
        if d["parameter"] == "kernel.sysrq":
            return d.get("value", '0') == '1'

    return False
Beispiel #16
0
def is_sysrq_enabled(workdir, input="sos_commands/kernel/sysctl_-a.json"):
    """
    :see: ``sos_analyzer.scanner.sysctl_a``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    for d in data:
        if d["parameter"] == "kernel.sysrq":
            return d.get("value", '0') == '1'

    return False
Beispiel #17
0
def is_root_login_enabled(workdir, runlevel=3,
                          input="etc/ssh/sshd_config.json"):
    """
    :see: ``sos_analyzer.scanner.etc_ssh_sshd_config``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    for d in data:
        if d.get("config", None) == "PermitRootLogin":
            if d.get("value", None) == "yes":
                return True

    return False
Beispiel #18
0
def is_root_login_enabled(workdir,
                          runlevel=3,
                          input="etc/ssh/sshd_config.json"):
    """
    :see: ``sos_analyzer.scanner.etc_ssh_sshd_config``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    for d in data:
        if d.get("config", None) == "PermitRootLogin":
            if d.get("value", None) == "yes":
                return True

    return False
Beispiel #19
0
def list_installed_kernels(workdir, input="installed-rpms.json"):
    """
    :see: ``sos_analyzer.scanner.installed_rpms``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    def pick_kernels(data):
        for d in data:
            rpm = d.get("rpm", None)
            if not rpm.startswith("kernel-"):
                continue

            m = KERNEL_RE.match(rpm)
            if m:
                yield m.groups()[0]

    # TODO: Check this works (ordered from the later ones).
    return sorted(pick_kernels(data), reverse=True)
Beispiel #20
0
def list_installed_kernels(workdir, input="installed-rpms.json"):
    """
    :see: ``sos_analyzer.scanner.installed_rpms``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    def pick_kernels(data):
        for d in data:
            rpm = d.get("rpm", None)
            if not rpm.startswith("kernel-"):
                continue

            m = KERNEL_RE.match(rpm)
            if m:
                yield m.groups()[0]

    # TODO: Check this works (ordered from the later ones).
    return sorted(pick_kernels(data), reverse=True)
Beispiel #21
0
def find_kdump_partition(workdir, input="etc/kdump.conf.json"):
    """
    FIXME: Implement the logic to check kdump partition is large enough.

    :see: ``sos_analyzer.scanner.etc_kdump_conf``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    path = "/var/crash"  # @see kdump.conf(5)
    partition = None

    for d in data:
        if d.get("path", False):
            path = d["path"]  # noqa: not implemented yet.
        if d.get("partition", False):
            partition = d["partition"]

    if partition:  # e.g. /dev/sda3, LABEL=/boot, UUID=...
        fss = SAF.list_normal_filesystems(workdir)  # noqa: likewise.

        pass
Beispiel #22
0
def find_kdump_partition(workdir, input="etc/kdump.conf.json"):
    """
    FIXME: Implement the logic to check kdump partition is large enough.

    :see: ``sos_analyzer.scanner.etc_kdump_conf``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    path = "/var/crash"  # @see kdump.conf(5)
    partition = None

    for d in data:
        if d.get("path", False):
            path = d["path"]  # noqa: not implemented yet.
        if d.get("partition", False):
            partition = d["partition"]

    if partition:   # e.g. /dev/sda3, LABEL=/boot, UUID=...
        fss = SAF.list_normal_filesystems(workdir)  # noqa: likewise.

        pass
Beispiel #23
0
def list_services_on_cur_runlevel(workdir, runlevel=3, input="chkconfig.json"):
    """
    :see: ``sos_analyzer.scanner.chkconfig``
    """
    data = Base.load_scanned_data(workdir, input)
    if not data:
        return None

    runlevel = get_cur_runlevel(workdir, runlevel)

    enabled_svcs = [s["service"] for s in data
                    if "service" in s and s["status"][runlevel] == "on"]

    disabled_svcs = [s["service"] for s in data
                     if "service" in s and s["status"][runlevel] == "off"]
    fully_disabled_svcs = [s["service"] for s in data if _is_fully_disabled(s)]

    enabled_xinetd_svcs = [s["xinetd_service"] for s in data
                           if s["status"] == "on"]

    return dict(enabled_services=enabled_svcs,
                disabled_services=disabled_svcs,
                fully_disabled_services=fully_disabled_svcs,
                enabled_xinetd_services=enabled_xinetd_svcs)