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

# <<<hyperv_checkpoints>>>
# Has_Checkpoints
# f5689086-243b-4dfe-9775-571ef6be8a1b 2063
# c85ae17b-1a6c-4a34-949a-a1b9385ef67a 2040


def inventory_hyperv_checkpoints(info):
    return [ (None, {} )]

def check_hyperv_checkpoints(item, params, info):
    oldest = 0
    for snapshot, age in info[1:]:
        oldest = max(int(age), oldest)
    number_of_checkpoints = len(info[1:])
    if number_of_checkpoints > 0:
        state = 0
        if params.get('age'):
            warn, crit = params['age']
            if crit >= oldest:
                state = 2
            elif warn >= oldest:
                state = 1
            perfdata = [("age", oldest, warn, crit)]
        else:
            perfdata = [("age", oldest)]
        return state, "%s Checkpoints, Oldest is: %s" % \
                        (len(info[1:]), get_age_human_readable(oldest)), perfdata
    else:
        return 0, "No Checkpoints found", [("age", 0)]


check_info["hyperv_checkpoints"] = {
    "check_function"        : check_hyperv_checkpoints,
    "inventory_function"    : inventory_hyperv_checkpoints,
    "service_description"   : "HyperV Checkpoints",
    "group"                 : "vm_snapshots",
    "has_perfdata"          : True,
}

