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

def inventory_stulz_pump(info):
    inventory = []
    for pump_id, pump_status in info[0]:
        pump_id = pump_id.replace('.1', '')
        inventory.append( (pump_id, None) )
    return inventory

def check_stulz_pump(item, _no_params, info):
    for index, (pump_id, pump_status) in enumerate(info[0]):
        pump_id = pump_id.replace('.1', '')
        if pump_id == item:
            pump_rpm = info[1][index][0]
            perfdata = [ ('rpm', pump_rpm+"%", None, None, 0, 100) ]
            if pump_status == '1':
                state = 0
                infotext = "Pump is running at %s%%" % pump_rpm
            elif pump_status == '0':
                state = 2
                infotext = "Pump is not running"
            else:
                state = 3
                infotext = "Pump reports unidentified status " + pump_status
            return state, infotext, perfdata
    return 3, "Pump %s not found" % item

check_info["stulz_pump"] = {
    "check_function"        : check_stulz_pump,
    "inventory_function"    : inventory_stulz_pump,
    "service_description"   : "Pump %s",
    "has_perfdata"          : True,
    "snmp_scan_function"    : lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.29462.10",
    "snmp_info"             : [( ".1.3.6.1.4.1.29462.10.2.1.1.2.1.4.1.1.5802", [ OID_END, 2] ),
                               ( ".1.3.6.1.4.1.29462.10.2.1.1.2.1.4.1.1.5821", [2] ),]
}

