#!/usr/bin/env python3
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# +------------------------------------------------------------------+
#
# This file is an addon for Check_MK.
# The official homepage for this check is at http://bitbucket.org/darkfader
#
# 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.



# Fans

#.1.3.6.1.4.1.18928.1.2.2.1.9.1.1.1 = INTEGER: 1
#.1.3.6.1.4.1.18928.1.2.2.1.9.1.2.1 = STRING: "CPU Fan"
#.1.3.6.1.4.1.18928.1.2.2.1.9.1.3.1 = INTEGER: 0

# snmp_info  : oid(".1.3.6.1.4.1.18928.1.2.2.1.9.1"), [ "1", "2", "3" ]

def inventory_areca_hba_fans(info):
    inventory = []
    for line in info[0]:
        # If the controller reports a spinning fan
        if len(line) == 3 and saveint(line[2]) != 0:
            # it would be called "CPU Fan" we grab only "CPU" from that.
            fan = line[1].split()[0]
            inventory.append((fan, None)) 
    return inventory


def check_areca_hba_fans(item, _no_params, info):
    return (3, "UNKNOWN - Check is not implemented, Patches welcome")


check_info["areca_hba_fans"]  = {
    "check_function"      : check_areca_hba_fans,
    "inventory_function"  : inventory_areca_hba_fans,
    "has_perfdata"        : False,
    "service_description" : "Fan %s",
    # Find Areca SAS MIB
    "snmp_scan_function"  : lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.18928.1"),
    "snmp_info"           : [(".1.3.6.1.4.1.18928.1.2.2.1.9.1", [ "1", "2", "3" ])],
}

