#!/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.

# Note: this check is deprecated. It is superseeded by the new
# Check_MK HW/SW-Inventory.


def inventory_dmi_sysinfo(info):
    if len(info) > 0 and info[0] == ["System", "Information"]:
        return [(None, None)]


def check_dmi_sysinfo(item, param, info):
    if len(info) == 0 or info[0] != ["System", "Information"]:
        return (3, "Invalid information")
    data = {}
    for line in info:
        line = " ".join(line)
        if ":" in line:
            key, value = line.split(":", 1)
            data[key.strip()] = value.strip()

    return (
        0,
        "Manufacturer: %s, Product-Name: %s, Version: %s, S/N: %s"
        % (
            data.get("Manufacturer", "Unknown"),
            data.get("Product Name", "Unknown"),
            data.get("Version", "Unknown"),
            data.get("Serial Number", "Unknown"),
        ),
    )


check_info["dmi_sysinfo"] = {
    "check_function": check_dmi_sysinfo,
    "inventory_function": inventory_dmi_sysinfo,
    "service_description": "DMI Sysinfo",
}
