#!/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:
#<<<winperf_msx_rpc_clientaccess>>>
#1387273178.72 66210
#2 1 rawcount
#4 8758106 counter
#6 18468322 counter
#8 1 rawcount
#10 1641652247 large_rawcount
#12 1341174309 large_rawcount
#14 1682095824 large_rawcount
#16 3135531663 large_rawcount
#18 287 large_rawcount
#20 92 large_rawcount
#22 202 large_rawcount
#24 10271890 large_rawcount
#26 10269732 large_rawcount
#28 10269728 large_rawcount
#30 4 large_rawcount
#32 2158 large_rawcount
#34 2158 large_rawcount
#36 0 large_rawcount
#38 2233 large_rawcount
#40 460 large_rawcount
#42 223 large_rawcount
winperf_msx_rpc_clientaccess_default = ( 40, 45 )

def inventory_winperf_msx_rpc_clientaccess(info):
    return [ (None, "winperf_msx_rpc_clientaccess_default") ]

def check_winperf_msx_rpc_clientaccess(_no_item, params, info):
    try:
        value = saveint(info[1][1])
        warn, crit = params
        state = 0
        if value >= crit:
            state = 2
        elif value >= warn:
            state = 1
        perf = [('connections', value, warn, crit )]
        return state, "Current: %s Client connections" % ( value ), perf
    except KeyError:
        return 3, "Counter not found"


check_info["winperf_msx_rpc_clientaccess"] = {
    "check_function"        : check_winperf_msx_rpc_clientaccess,
    "inventory_function"    : inventory_winperf_msx_rpc_clientaccess,
    "service_description"   : "MSX RPC Client Access",
    "has_perfdata"          : True,
}

