#!/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.dell_om import *  # pylint: disable=wildcard-import,unused-wildcard-import

# sample agent output:
#
# <<<omreport_vdisk>>>
# ID                               : 0
# Status                           : Ok
# Name                             : Virtual Disk 0
# State                            : Ready
# Hot Spare Policy violated        : Not Assigned
# Encrypted                        : Not Applicable
# Layout                           : RAID-1
# Size                             : 278.88 GB (299439751168 bytes)
# T10 Protection Information Status : No
# Associated Fluid Cache State     : Not Applicable
# Device Name                      : /dev/sda
# Bus Protocol                     : SAS
# Media                            : HDD
# Read Policy                      : Read Ahead
# Write Policy                     : Write Back
# Cache Policy                     : Not Applicable
# Stripe Element Size              : 64 KB
# Disk Cache Policy                : Unchanged


def inventory_dell_om_vdisks(parsed):
    return [(key, None) for key in parsed]


def check_dell_om_vdisks(item, params, parsed):
    if item in parsed:
        status = status_translate_omreport(parsed[item]["Status"])
        if parsed[item]["State"] != "Ready":
            status = 2

        return status, "Device: %s, Status: %s, State: %s, Layout: %s" % (
            parsed[item]["Device Name"],
            parsed[item]["Status"],
            parsed[item]["State"],
            parsed[item]["Layout"],
        )


check_info["dell_om_vdisks"] = {
    "check_function": check_dell_om_vdisks,
    "inventory_function": inventory_dell_om_vdisks,
    "parse_function": parse_omreport,
    "service_description": "Virtual Disk %s",
}
