#!/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.3.1.1.2.1 0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusType.1
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.2.2 0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusType.2
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.2.3 0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusType.3
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.2.4 0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusType.4
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.2.5 0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusType.5
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.2.6 0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusType.6
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.3.1 CPU TEMP0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusDescr.1
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.3.2 MAIN TEMP0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusDescr.2
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.3.3 MAIN TEMP1 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusDescr.3
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.3.4 PHY TEMP0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusDescr.4
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.3.5 PHY TCM5 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusDescr.5
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.3.6 PHY FPGA TEMP0 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusDescr.6
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.4.1 57 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusValue.1
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.4.2 33 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusValue.2
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.4.3 30 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusValue.3
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.4.4 53 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusValue.4
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.4.5 44 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusValue.5
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.4.6 53 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusValue.6
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.5.1 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureState.1
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.5.2 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureState.2
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.5.3 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureState.3
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.5.4 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureState.4
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.5.5 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureState.5
# .1.3.6.1.4.1.9148.3.3.1.3.1.1.5.6 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureState.6


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


def check_acme_temp(item, params, info):
    for descr, value_str, state in info:
        if item == descr:
            dev_state, dev_state_readable = acme_environment_states[state]
            return check_temperature(float(value_str), params, "acme_temp.%s" % item,
                                     dev_status = dev_state,
                                     dev_status_name = dev_state_readable)


check_info['acme_temp'] = {
    'inventory_function'    : inventory_acme_temp,
    'check_function'        : check_acme_temp,
    'service_description'   : 'Temperature %s',
    'has_perfdata'          : True,
    'snmp_info'             : ('.1.3.6.1.4.1.9148.3.3.1.3.1.1', [
                                "3",    # ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusDescr
                                "4",    # ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusValue
                                "5",    # ACMEPACKET-ENVMON-MIB::apEnvMonTemperatureStatusState
                              ]),
    'snmp_scan_function'    : scan_acme,
    'includes'              : ['temperature.include', 'acme.include'],
    'group'                 : 'temperature',
}
