#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2016             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.14823.2.2.1.5.2.1.4.1.3.0.36.108.192.2.186 ALA-AP 2.1.1 --> WLSX-WLAN-MIB::wlanAPName.'.$l...'
# .1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.4.0.36.108.192.2.186 ALA-Office --> WLSX-WLAN-MIB::wlanAPGroupName.'.$l...'
# .1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.5.0.36.108.192.2.186 .1.3.6.1.4.1.14823.1.2.34 --> WLSX-WLAN-MIB::wlanAPModel.'.$l...'
# .1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.6.0.36.108.192.2.186 AL0000642 --> WLSX-WLAN-MIB::wlanAPSerialNumber.'.$l...'
# .1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.32.0.36.108.192.2.186 --> WLSX-WLAN-MIB::wlanAPSysLocation.'.$l...'


def inv_aruba_wlc_aps(info):
    map_ap_products = {
        "1"  : "a50", "2"  : "a52", "3"  : "a60", "4"  : "a61", "5"  : "a70",
        "6"  : "walljackAp61", "7"  : "a2E",  "8"  : "ap1200",  "9"  : "ap80s", "10" : "ap80m",
        "11" : "wg102", "12" : "ap40",  "13" : "ap41", "14" : "ap65", "15" : "NesotMW1700",
        "16" : "ortronics Wi Jack Duo", "17" : "ortronics Duo",  "18" : "ap80MB", "19" : "ap80SB", "20" : "ap85",
        "21" : "ap124", "22" : "ap125",  "23" : "ap120", "24" : "ap121", "25" : "ap1250",
        "26" : "ap120abg", "27" : "ap121abg",  "28" : "ap124abg", "29" : "ap125abg", "30" : "rap5wn",
        "31" : "rap5", "32" : "rap2wg",  "33" : "reserved-4", "34" : "ap105", "35" : "ap65wb",
        "36" : "ap651", "37" : "reserved-6",  "38" : "ap60p", "39" : "reserved-7", "40" : "ap92",
        "41" : "ap93", "42" : "ap68",  "43" : "ap68p", "44" : "ap175p", "45" : "ap175ac",
        "46" : "ap175dc", "47" : "ap134",  "48" : "ap135", "49" : "reserved-8", "50" : "ap93h",
        "51" : "rap3wn", "52" : "rap3wnp",  "53" : "ap104", "54" : "rap155", "55" : "rap155p",
        "56" : "rap108", "57" : "rap109",  "58" : "ap224", "59" : "ap225", "60" : "ap114",
        "61" : "ap115", "62" : "rap109L",  "63" : "ap274", "64" : "ap275", "65" : "ap214a",
        "66" : "ap215a", "67" : "ap204",  "68" : "ap205", "69" : "ap103", "70" : "ap103H",
        "72" : "ap227",  "73" : "ap214", "74" : "ap215", "75" : "ap228",
        "76" : "ap205H", "9999" : "undefined",
    }
    node = inv_tree("networking.wlan.controller.accesspoints:")
    for ap_name, ap_gr_name, ap_model, ap_serial_nr, ap_sys_loc in info:
        node.append({
            "name"         : ap_name,
            "group"        : ap_gr_name,
            "model"        : map_ap_products.get(ap_model.split(".")[-1], "unknown"),
            "serial"       : ap_serial_nr,
            "sys_location" : ap_sys_loc,
        })
    return node


inv_info['aruba_wlc_aps'] = {
    'inv_function'        : inv_aruba_wlc_aps,
    "snmp_info"           : ( ".1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1",[
                                  "3",    # wlanAPName
                                  "4",    # wlanAPGroupName
                                  "5",    # wlanAPModel
                                  "6",    # wlanAPSerialNumber
                                  "32",   # wlanAPSysLocation
                            ]),
    "snmp_scan_function"  : lambda oid: oid('.1.3.6.1.2.1.1.2.0').startswith(".1.3.6.1.4.1.14823.1.1"),
}
