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


# .1.3.6.1.4.1.14179.2.1.1.1.2.1 FOO
# .1.3.6.1.4.1.14179.2.1.1.1.2.2 BAR
# .1.3.6.1.4.1.14179.2.1.1.1.2.3 Hans
# .1.3.6.1.4.1.14179.2.1.1.1.2.4 PETER
# .1.3.6.1.4.1.14179.2.1.1.1.2.16 Huhu
# .1.3.6.1.4.1.14179.2.1.1.1.42.1 foo
# .1.3.6.1.4.1.14179.2.1.1.1.42.2 bar
# .1.3.6.1.4.1.14179.2.1.1.1.42.3 hans
# .1.3.6.1.4.1.14179.2.1.1.1.42.4 gastzugang
# .1.3.6.1.4.1.14179.2.1.1.1.42.16 gastzugang
# .1.3.6.1.4.1.14179.2.1.1.1.38.1 6
# .1.3.6.1.4.1.14179.2.1.1.1.38.2 12
# .1.3.6.1.4.1.14179.2.1.1.1.38.3 0
# .1.3.6.1.4.1.14179.2.1.1.1.38.4 6
# .1.3.6.1.4.1.14179.2.1.1.1.38.16 6


def parse_cisco_wlc_clients(info):
    parsed = {}
    sum_clients = 0
    for name, interface, num_clients in info:
        sum_clients_name = int(num_clients)
        sum_clients     += sum_clients_name

        if name in parsed:
           sum_clients_name += parsed[name][0]
           interface         = parsed[name][1] + ", " + interface

        parsed[name] = (sum_clients_name, "%s: %s" % (interface, num_clients))

    parsed["Summary"] = (sum_clients, "")
    return parsed


check_info["cisco_wlc_clients"] = {
    "parse_function"        : parse_cisco_wlc_clients,
    "inventory_function"    : inventory_wlc_clients,
    "check_function"        : check_wlc_clients,
    "service_description"   : "Clients %s",
    "group"                 : "wlc_clients",
    "has_perfdata"          : True,
    "snmp_scan_function"    : lambda oid: oid('.1.3.6.1.2.1.1.2.0') in [
                                    ".1.3.6.1.4.1.9.1.1069",
                                    ".1.3.6.1.4.1.9.1.1645",
                                    ".1.3.6.1.4.1.9.1.1631",
                                    ".1.3.6.1.4.1.14179.1.1.4.3",
                                    ".1.3.6.1.4.1.9.1.1279",
                                    ".1.3.6.1.4.1.9.1.1293",
                              ],
    "snmp_info"             : ( ".1.3.6.1.4.1.14179.2.1.1.1",  [
                                    "2",
                                    "42",
                                    "38",
                              ]),
    "includes"              : [ "wlc_clients.include" ],
}

