#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2015             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.9694.1.6.2.3.0 2070 --> PRAVAIL-MIB::deviceCpuLoadAvg1min.0
# .1.3.6.1.4.1.9694.1.6.2.4.0 2059 --> PRAVAIL-MIB::deviceCpuLoadAvg5min.0
# .1.3.6.1.4.1.9694.1.6.2.5.0 2059 --> PRAVAIL-MIB::deviceCpuLoadAvg15min.0
# .1.3.6.1.4.1.9694.1.6.2.6.0 8 --> PRAVAIL-MIB::deviceDiskUsage.0
# .1.3.6.1.4.1.9694.1.6.2.7.0 49 --> PRAVAIL-MIB::devicePhysicalMemoryUsage.0
# .1.3.6.1.4.1.9694.1.6.2.8.0 0 --> PRAVAIL-MIB::deviceSwapSpaceUsage.0


def parse_pravail(info):
    # peakflow SP and TMS have the same info in different oid ranges
    valid = info[0]
    return {
        "cpu_loads"  : valid[:3],
        "disk"       : valid[3],
        "memory"     : valid[4:6],
        "host_fault" : valid[6]
    }


check_info["arbor_pravail"] = {
    "check_function"          : check_arbor_memory,
    "inventory_function"      : inventory_arbor_memory,
    "parse_function"          : parse_pravail,
    "service_description"     : "Memory",
    "has_perfdata"            : True,
    "group"                   : "memory_arbor",
    'default_levels_variable' : 'arbor_memory_default_levels',
    "snmp_info"               : (".1.3.6.1.4.1.9694.1.6.2", ["3.0", # deviceCpuLoadAvg1min
                                                             "4.0", # deviceCpuLoadAvg5min
                                                             "5.0", # deviceCpuLoadAvg15min
                                                             "6.0", # deviceDiskUsage
                                                             "7.0", # devicePhysicalMemoryUsage
                                                             "8.0", # deviceSwapSpaceUsage
                                                             "1.0", # pravailHostFault
                                                             ]
                               ),
    "snmp_scan_function"      : lambda oid: oid(".1.3.6.1.2.1.1.1.0").startswith("Pravail"),
    "includes"                : ["arbor.include"]
}


check_info["arbor_pravail.cpu_load"] = {
    "check_function"        : check_arbor_cpu_load,
    "inventory_function"    : inventory_arbor_cpu_load,
    "service_description"   : "CPU load",
    "has_perfdata"          : True,
    "group"                 : "cpu_load",
    "includes"              : ["cpu_load.include"],
}


check_info["arbor_pravail.disk_usage"] = {
    "check_function"        : check_arbor_disk_usage,
    "inventory_function"    : inventory_arbor_disk_usage,
    "service_description"   : "Disk Usage %s",
    "has_perfdata"          : True,
    "group"                 : "filesystem",
    "default_levels_variable" : "filesystem_default_levels",
}


check_info["arbor_pravail.host_fault"] = {
    "check_function"        : check_arbor_host_fault,
    "inventory_function"    : inventory_arbor_host_fault,
    "service_description"   : "Host Fault",
}

