#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             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.


def inventory_synology_raid(info):
    for line in info:
        yield line[0], None


def check_synology_raid(item, _no_params, info):
    states = {
        "1": ("OK", 0),
        "2": ("repairing", 1),
        "3": ("migrating", 1),
        "4": ("expanding", 1),
        "5": ("deleting", 1),
        "6": ("creating", 1),
        "7": ("RAID syncing", 0),
        "8": ("RAID parity checking", 0),
        "9": ("RAID assembling", 1),
        "10": ("cancelling", 1),
        "11": ("degraded", 2),
        "12": ("crashed", 2),
        "13": ("scrubbing", 0),
        "14": ("RAID deploying", 0),
        "15": ("RAID undeploying", 0),
        "16": ("RAID mounting cache", 0),
        "17": ("RAID unmounting cache", 0),
        "18": ("RAID continue expanding", 1),
        "19": ("RAID converting", 0),
        "20": ("RAID migrating", 0),
        "21": ("RAID status unknown", 3),
    }
    for raid, state in info:
        if raid == item:
            message = "Status: " + states[state][0]
            return states[state][1], message


check_info["synology_raid"] = {
    "check_function": check_synology_raid,
    "inventory_function": inventory_synology_raid,
    "service_description": "RAID %s",
    "snmp_scan_function": synology_scan_function,
    "snmp_info": (
        ".1.3.6.1.4.1.6574.3.1.1",
        [
            2,  #raidName
            3,  #raidStatus
        ]),
    "includes": ["synology.include"]
}
