#!/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: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.hp_msa import *  # pylint: disable=wildcard-import,unused-wildcard-import

# <<<hp_msa_system>>>
# system 1 system-name IMSAKO2B1
# system 1 system-contact cia@cgm.com
# system 1 system-location Rack B1
# system 1 system-information Uninitialized Info
# system 1 midplane-serial-number 00C0FF1E82BB
# system 1 vendor-name HP
# system 1 product-id MSA 2040 SAN
# system 1 product-brand MSA Storage
# system 1 scsi-vendor-id HP
# system 1 scsi-product-id MSA 2040 SAN
# system 1 enclosure-count 1
# system 1 health OK
# system 1 health-numeric 0
# system 1 health-reason
# system 1 other-MC-status Operational
# system 1 other-MC-status-numeric 4754
# system 1 pfuStatus Idle
# system 1 supported-locales English (English), Spanish (español), French (français), German (Deutsch), Italian (italiano), Japanese (日本語), Dutch (Nederlands), Chinese-Simplified (简体中文), Chinese-Traditional (繁體中文), Korean (한국어)
# system 1 current-node-wwn 208000c0ff1e82bb
# system 1 fde-security-status Unsecured
# system 1 fde-security-status-numeric 1
# system 1 platform-type Gallium
# system 1 platform-type-numeric 3
# system 1 platform-brand HP Cardinals
# system 1 platform-brand-numeric 15
# redundancy 2 redundancy-mode Active-Active ULP
# redundancy 2 redundancy-mode-numeric 8
# redundancy 2 redundancy-status Redundant
# redundancy 2 redundancy-status-numeric 2
# redundancy 2 controller-a-status Operational
# redundancy 2 controller-a-status-numeric 0
# redundancy 2 controller-a-serial-number 7CE501N158
# redundancy 2 controller-b-status Operational
# redundancy 2 controller-b-status-numeric 0
# redundancy 2 controller-b-serial-number 7CE501M190
# redundancy 2 other-MC-status Operational
# redundancy 2 other-MC-status-numeric 4754


def parse_hp_msa_system(info):
    parsed = {}
    for line in info:
        if line[2] == "system-name":
            system_name = " ".join(line[3:])
            parsed[system_name] = {"item_type": line[0]}
        elif line[2] == "health":
            parsed[system_name]["health"] = " ".join(line[3:])
        elif line[2] == "health-reason":
            parsed[system_name]["health-reason"] = " ".join(line[3:])

    return parsed


check_info["hp_msa_system"] = {
    "parse_function": parse_hp_msa_system,
    "inventory_function": inventory_hp_msa_health,
    "check_function": check_hp_msa_health,
    "service_description": "System Health %s",
}
