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

# 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",
}
