#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             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
# Columns:
# 1. Direct IOs / sec   (on hardware)
# 2. Buffered IOs / sec (queued)
# 3. Number of currently existing processes (averaged)

# <<<vms_system>>>
# 0.00 0.00 15.00


def inventory_vms_system(info):
    if len(info) > 0:
        return [(None, None)]


def check_vms_system_ios(_no_item, _no_params, info):
    direct_ios, buffered_ios = map(float, info[0][:2])
    return (0, "Direct IOs: %.2f/sec, Buffered IOs: %.2f/sec" % (direct_ios, buffered_ios),
            [("direct", direct_ios), ("buffered", buffered_ios)])


check_info["vms_system.ios"] = {
    "check_function": check_vms_system_ios,
    "inventory_function": inventory_vms_system,
    "service_description": "IOs",
    "has_perfdata": True,
}


def check_vms_system_procs(_no_item, params, info):
    procs = int(float(info[0][2]))
    perfdata = [('procs', procs, None, None, 0)]

    if params:
        warn, crit = params
        perfdata = [('procs', procs, warn, crit, 0)]
        if procs >= crit:
            return (2, "%d processes (critical at %d)" % (procs, crit), perfdata)
        elif procs >= warn:
            return (1, "%d processes (warning at %d)" % (procs, warn), perfdata)

    return (0, "%d processes" % (procs,), perfdata)


check_info["vms_system.procs"] = {
    "check_function": check_vms_system_procs,
    "inventory_function": inventory_vms_system,
    "service_description": "Number of processes",
    "has_perfdata": True,
    "group": "vms_procs",
}
