#!/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-
# ails.  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:
#<<<winperf_msx_dumpster>>>
#1387196179.28 62694
#2 6 rawcount
#4 130270 rawcount
#6 46917 counter
#8 46911 counter
#10 0 rawcount
#12 57 large_rawcount
#14 2 rawcount
#16 0 average_timer
#18 0 average_base
#20 0 average_timer
#22 0 average_base
#24 0 average_bulk
#26 0 average_base
#28 0 rawcount
#30 0 rawcount


def inventory_winperf_msx_dumpster(info):
    return [ (None, None) ]

def check_winperf_msx_dumpster(_no_item, _no_params, info):
    counters = []

    #find the values
    for line in info:
        if line[0] == '2':
            counters.append(saveint(line[1]))
        if line[0] == '4':
            counters.append(saveint(line[1]))
            break

    if len(counters) == 2:
        count, size = counters
        perf = [
          ( 'size', size ),
          ( 'items', count),
        ]
        return 0, "Size is %s (%d Items)" % ( get_bytes_human_readable(size), count ), perf 

    return 3, "Counter not found"


check_info["winperf_msx_dumpster"] = {
    "check_function"        : check_winperf_msx_dumpster,
    "inventory_function"    : inventory_winperf_msx_dumpster,
    "service_description"   : "MSX Dumpster",
    "has_perfdata"          : True,
}

