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

raritan_pdu_plugs_default = '"on"' # only to be downwards compatible and can be removed any decade now.


def inventory_raritan_pdu_plugs(info):
    inventory = []
    for outlet_label, outlet_name, outlet_state in info:
        inventory.append((outlet_label, int(outlet_state)) )
    return inventory


def check_raritan_pdu_plugs(item, params, info):
    required_state = params

    for outlet_label, outlet_name, outlet_state in info:
        if outlet_label == item:
            state, state_info = raritan_map_state[outlet_state]

            if type(required_state) == int:
                if int(outlet_state) != required_state:
                    state = 2
            elif state_info != required_state:
                state = 2

            if outlet_name != "":
                outlet_name += ", "

            return state, "%sStatus: %s" % (outlet_name, state_info)


check_info['raritan_pdu_plugs'] = {
  "inventory_function"  : inventory_raritan_pdu_plugs,
  "check_function"      : check_raritan_pdu_plugs,
  "service_description" : "Plug %s",
  "group"               : "plugs",
  "has_perfdata"        : False,
  "snmp_info"           : ( ".1.3.6.1.4.1.13742.6", [
                                "3.5.3.1.2", # Outlet-Label (Index) (PDU identifier of the outlet)
                                "3.5.3.1.3", # OutletName (eigene vergebene Bezeichnung für den Ausgang)
                                "4.1.2.1.3", # Outlet state at present (sh.o. outlet_state_info im check)
                          ]),
  "snmp_scan_function"  : lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.13742.6") and \
                                      oid(".1.3.6.1.4.1.13742.6.3.2.1.1.3.1").startswith("PX2-2"),
  "includes"            : [ "raritan.include" ],
}
