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


# Max. eigth sensors
# .1.3.6.1.4.1.5528.100.4.2.10.1.4.399845582 Wasserstand_FG1
# .1.3.6.1.4.1.5528.100.4.2.10.1.4.3502248167 Ethernet Link Status
# .1.3.6.1.4.1.5528.100.4.2.10.1.4.3823829717 A-Link Bus Power
# .1.3.6.1.4.1.5528.100.4.2.10.1.3.399845582 0
# .1.3.6.1.4.1.5528.100.4.2.10.1.3.3502248167 0
# .1.3.6.1.4.1.5528.100.4.2.10.1.3.3823829717 0
# .1.3.6.1.4.1.5528.100.4.2.10.1.7.399845582 No Leak
# .1.3.6.1.4.1.5528.100.4.2.10.1.7.3502248167 Up
# .1.3.6.1.4.1.5528.100.4.2.10.1.7.3823829717 OK


# MIB: The sensor reading shown as a string (or empty string
# if it is not plugged into a port).
def inventory_apc_netbotz_other_sensors(info):
    for sensor_label, error_state, state_readable in info:
        if state_readable != "":
            return [ (None, None) ]


def check_apc_netbotz_other_sensors(_no_item, _no_params, info):
    count_ok_sensors = 0
    for sensor_label, error_state, state_readable in info:
        if state_readable != "":
            if state_readable != "OK":
                state_readable = state_readable.lower()

            if error_state == "0":
                count_ok_sensors += 1
            else:
                yield 2, "%s: %s" % (sensor_label, state_readable)

    if count_ok_sensors > 0:
        yield 0, "%d sensors are OK" % count_ok_sensors


check_info['apc_netbotz_other_sensors'] = {
    'inventory_function'        : inventory_apc_netbotz_other_sensors,
    'check_function'            : check_apc_netbotz_other_sensors,
    'service_description'       : 'Numeric sensors summary',
    'snmp_info'                 : (".1.3.6.1.4.1.5528.100.4.2.10.1", [
                                    "4",    # NETBOTZV2-MIB::otherNumericSensorLabel
                                    "3",    # NETBOTZV2-MIB::otherNumericSensorErrorStatus
                                    "7",    # NETBOTZV2-MIB::otherNumericSensorValueStr
                                  ]),
    'snmp_scan_function'        : lambda oid: \
        oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.5528.100.20.10.2014"),
}
