#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# tails. You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

# Example output from agent:
# <<<hyperv_vmstatus>>>
# Integration_Services Ok
# Replica_Health None


def parse_hyperv_vmstatus(info):
    return {line[0]: ' '.join(line[1:]) for line in info}


def check_hyperv_vmstatus(_no_item, _no_params, parsed):
    int_state = parsed.get("Integration_Services")
    # According to microsoft 'Protocol_Mismatch' is OK:
    #   The secondary status [...] includes an error string that sounds alarming
    #   but that you can safely ignore. [...] This behavior is by design.
    state = 0 if int_state in ('Ok', 'Protocol_Mismatch') else 2
    return state, "Integration Service State: %s" % int_state


check_info["hyperv_vmstatus"] = {
    "parse_function": parse_hyperv_vmstatus,
    "check_function": check_hyperv_vmstatus,
    "inventory_function": discover_single,
    "service_description": "HyperV Status",
}
