#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.


def inv_snmp_os(info):
    sys_descr, sys_obj, _sys_uptime, _sys_name = info[0][0]
    descr_short = sys_descr.split()
    descr_long = sys_descr.split(",")
    node = inv_tree("software.os.")

    # Cisco IOS Devices:
    # TODO: Huh??? Funny condition below...
    if "ios" and "cisco" in sys_descr.lower():  # pylint: disable=simplifiable-condition
        node["type"] = descr_long[0]
        if "Version" in descr_short:
            node["version"] = (descr_short[descr_short.index("Version") + 1]).replace(",", "")

    # Fireeye Devices
    if "linux" in sys_descr.lower() and ".1.3.6.1.4.1.25597.1" in sys_obj:
        node["type"] = descr_short[0]
        node["kernel_version"] = descr_short[2]
        node["arch"] = descr_short[-1]


inv_info["snmp_os"] = {
    "inv_function": inv_snmp_os,
}
