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

# <<<emcvnx_writecache>>>
# SPA Write Cache State               Enabled
# SPB Write Cache State               Enabled


def inventory_emcvnx_writecache(info):
    inventory = []
    for line in info:
        if " ".join(line) == "Error: getcache command failed":
            return []
        inventory.append((line[0], None))
    return inventory


def check_emcvnx_writecache(item, params, info):
    map_state = {
        "Enabled": (0, "enabled"),
        "Disabled": (2, "disabled"),
    }
    for line in info:
        if line[0] == item:
            state, state_readable = map_state.get(line[-1], (3, "unknown"))
            return state, "State: %s" % state_readable


check_info["emcvnx_writecache"] = {
    "inventory_function": inventory_emcvnx_writecache,
    "check_function": check_emcvnx_writecache,
    "service_description": "Write Cache State %s",
}
