#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2017             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.9148.3.3.1.4.1.1.3.1 MAIN FAN1 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusDescr.1
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.3.2 MAIN FAN2 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusDescr.2
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.3.3 MAIN FAN3 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusDescr.3
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.3.4 MAIN FAN4 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusDescr.4
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.4.1 100 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusValue.1
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.4.2 100 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusValue.2
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.4.3 100 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusValue.3
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.4.4 100 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusValue.4
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.5.1 1 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanState.1
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.5.2 1 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanState.2
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.5.3 1 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanState.3
# .1.3.6.1.4.1.9148.3.3.1.4.1.1.5.4 1 --> ACMEPACKET-ENVMON-MIB::apEnvMonFanState.4


def inventory_acme_fan(info):
    return [ (descr, {}) for descr, value_str, state in info
             if state != "7" ]


def check_acme_fan(item, params, info):
    for descr, value_str, state in info:
        if item == descr:
            dev_state, dev_state_readable = acme_environment_states[state]
            return dev_state, "Status: %s, Speed: %s%%" % \
                   (dev_state_readable, value_str)


check_info['acme_fan'] = {
    'inventory_function'    : inventory_acme_fan,
    'check_function'        : check_acme_fan,
    'service_description'   : 'Fan %s',
    'snmp_info'             : ('.1.3.6.1.4.1.9148.3.3.1.4.1.1', [
                                "3",    # ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusDescr
                                "4",    # ACMEPACKET-ENVMON-MIB::apEnvMonFanStatusValue
                                "5",    # ACMEPACKET-ENVMON-MIB::apEnvMonFanState
                              ]),
    'snmp_scan_function'    : scan_acme,
    'includes'              : ['acme.include'],
    'group'                 : 'hw_fans_perc',
}
