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

def inventory_dell_om_processors(info):
    return [(x[0], None) for x in info if x[1] != '4' and x[0] != '' ]

def check_dell_om_processors(item, _no_params, info):
    #Probetypes found in check_openmanage3.pl
    cpu_states = {
         1 : 'Other',         # other than following values
         2 : 'Unknown',       # unknown
         3 : 'Enabled',       # enabled
         4 : 'User Disabled', # disabled by user via BIOS setup
         5 : 'BIOS Disabled', # disabled by BIOS (POST error)
         6 : 'Idle',          # idle
    }

    cpu_readings = {
	 0    : 'Unkown',
         1    : 'Internal Error',      # Internal Error
         2    : 'Thermal Trip',        # Thermal Trip
         32   : 'Configuration Error', # Configuration Error
         128  : 'Present',             # Processor Present
         256  : 'Disabled',            # Processor Disabled
         512  : 'Terminator Present',  # Terminator Present
         1024 : 'Throttled',           # Processor Throttled
    }

    for index, status, manuf, status2, reading in info:
        if index == item:
            state = 0
            if not status:
                status = status2
	    status = saveint(status)
	    reading = saveint(reading)
            msg = "Cpu (%s) State: %s, CPU Reading: %s" % \
            (manuf, cpu_states.get(status, 'ukn (%s)' % status ), cpu_readings[int(reading)])
            if status != 3:
                state = 2
            if reading in [ 1, 32 ]:
                state = 2
            return state, msg

    return 2, "Processor not found"

check_info["dell_om_processors"] = {
    "check_function"        : check_dell_om_processors,
    "inventory_function"    : inventory_dell_om_processors,
    "service_description"   : "Processor %s",
    "has_perfdata"          : False,
    # There is no other way to find out that openmanage is present.
    "snmp_scan_function"    : scan_dell_om,
    "snmp_info"             : ( ".1.3.6.1.4.1.674.10892.1.1100", [
                                      "30.1.2", # Index
                                      "30.1.5", # Device Status
                                      "30.1.8", # Manufacturerer Name
                                      "30.1.9", # DeviceStatus State
                                      "32.1.6", # Deive Status reading
                              ]),
    "includes"              : [ "dell_om.include" ],
}

