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

emc_isilon_info = [(".1.3.6.1.4.1.12124.1.1", [1,   # clusterName
                                               2,   # clusterHealth
                                               5,   # configuredNodes
                                               6]), # onlineNodes
                   (".1.3.6.1.4.1.12124.2.1", [1,   # nodeName
                                               2]), # nodeHealth
                  ]

def emc_isilon_scan(oid):
    return oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.12124.1")

#   .--ClusterHealth------------------------------------------------------.

def inventory_emc_isilon_clusterhealth(info):
    return [(None, None)]

def check_emc_isilon_clusterhealth(item, _no_params, info):
    status=int(info[0][0][1])
    statusmap = ("ok", "attn", "down", "invalid")
    if status >= len(statusmap):
        return 3, "ClusterHealth reports unidentified status %s" % status
    else:
        if status == 0:
            rc = 0
        else:
            rc = 2
        return rc, "ClusterHealth reports status %s" % statusmap[status]

check_info["emc_isilon.clusterhealth"] = {
    "check_function"        : check_emc_isilon_clusterhealth,
    "inventory_function"    : inventory_emc_isilon_clusterhealth,
    "service_description"   : "Cluster Health",
    "has_perfdata"          : False,
    "snmp_info"             : emc_isilon_info,
    "snmp_scan_function"    : emc_isilon_scan
}

#.
#   .--NodeHealth------------------------------------------------------.

def inventory_emc_isilon_nodehealth(info):
    return [(None, None)]

def check_emc_isilon_nodehealth(item, _no_params, info):
    status=int(info[1][0][1])
    statusmap = ("ok", "attn", "down", "invalid")
    nodename=info[1][0][0]
    if status >= len(statusmap):
        return 3, "nodeHealth reports unidentified status %s" % status
    else:
        if status == 0:
            rc = 0
        else:
            rc = 2
        return rc, "nodeHealth for %s reports status %s" % (nodename, statusmap[status])

check_info["emc_isilon.nodehealth"] = {
    "check_function"        : check_emc_isilon_nodehealth,
    "inventory_function"    : inventory_emc_isilon_nodehealth,
    "service_description"   : "Node Health",
    "has_perfdata"          : False,
    "snmp_info"             : emc_isilon_info,
    "snmp_scan_function"    : emc_isilon_scan
}

#.
#   .--Nodes------------------------------------------------------.

def inventory_emc_isilon_nodes(info):
    return [(None, None)]

def check_emc_isilon_nodes(item, _no_params, info):
    cluster_name, cluster_health, configured_nodes, online_nodes = info[0][0]
    if configured_nodes == online_nodes:
        rc = 0
    else:
        rc = 2
    return rc, "Configured Nodes: %s / Online Nodes: %s" % (configured_nodes, online_nodes)

check_info["emc_isilon.nodes"] = {
    "check_function"        : check_emc_isilon_nodes,
    "inventory_function"    : inventory_emc_isilon_nodes,
    "service_description"   : "Nodes",
    "has_perfdata"          : False,
    "snmp_info"             : emc_isilon_info,
    "snmp_scan_function"    : emc_isilon_scan
}

#.
#   .--Cluster- and Node Name-------------------------------------------.

def inventory_emc_isilon_names(info):
    return [(None, None)]

def check_emc_isilon_names(item, _no_params, info):
    return 0, "Cluster Name is %s, Node Name is %s" % (info[0][0][0], info[1][0][0])

check_info["emc_isilon.names"] = {
    "check_function"        : check_emc_isilon_names,
    "inventory_function"    : inventory_emc_isilon_names,
    "service_description"   : "Isilon Info",
    "has_perfdata"          : False,
    "snmp_info"             : emc_isilon_info,
    "snmp_scan_function"    : emc_isilon_scan
}

#.
