#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2015             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.



def inventory_ups_modulys_alarms(info):
    if info:
        return [ (None, None) ]


def check_ups_modulys_alarms(_no_item, _no_params, info):
    oiddef = {
        '1'     : (2, 'Disconnect'),
        '2'     : (2, 'Input power failure'),
        '3'     : (2, 'Low batteries'),
        '4'     : (1, 'High load'),
        '5'     : (2, 'Severley high load'),
        '6'     : (2, 'On bypass'),
        '7'     : (2, 'General failure'),
        '8'     : (2, 'Battery ground fault'),
        '9'     : (0, 'UPS test in progress'),
        '10'    : (2, 'UPS test failure'),
        '11'    : (2, 'Fuse failure'),
        '12'    : (2, 'Output overload'),
        '13'    : (2, 'Output overcurrent'),
        '14'    : (2, 'Inverter abnormal'),
        '15'    : (2, 'Rectifier abnormal'),
        '16'    : (2, 'Reserve abnormal'),
        '17'    : (1, 'On reserve'),
        '18'    : (2, 'Overheating'),
        '19'    : (2, 'Output abnormal'),
        '20'    : (2, 'Bypass bad'),
        '21'    : (0, 'In standby mode'),
        '22'    : (2, 'Charger failure'),
        '23'    : (2, 'Fan failure'),
        '24'    : (0, 'In economic mode'),
        '25'    : (1, 'Output turned off'),
        '26'    : (1, 'Smart shutdown in progress'),
        '27'    : (2, 'Emergency power off'),
        '28'    : (1, 'Shutdown'),
        '29'    : (2, 'Output breaker open'),
    }

    for oidend, flag in info:
        result = False
        if flag and int(flag):
            result = True
            yield oiddef[oidend]

    if not result:
        yield 0, "No alarms"


check_info['ups_modulys_alarms'] = {
    'inventory_function'        : inventory_ups_modulys_alarms,
    'check_function'            : check_ups_modulys_alarms,
    'service_description'       : 'UPS Alarms',
    'snmp_info'                 : (".1.3.6.1.4.1.2254.2.4", [
                                            OID_END,
                                            "9",
                                            ]
                                  ),
    'snmp_scan_function'        : lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.2254.2.4",
}
