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

# <<<hp_msa_controller>>>
# controller-statistics 1 durable-id controller_A
# controller-statistics 1 cpu-load 3
# controller-statistics 1 power-on-time 7855017
# controller-statistics 1 write-cache-used 24
# controller-statistics 1 bytes-per-second 6434.3KB
# controller-statistics 1 bytes-per-second-numeric 6434304
# controller-statistics 1 iops 184
# controller-statistics 1 number-of-reads 67423711
# controller-statistics 1 read-cache-hits 86626091
# controller-statistics 1 read-cache-misses 172382632
# controller-statistics 1 number-of-writes 500652138
# controller-statistics 1 write-cache-hits 281297065
# controller-statistics 1 write-cache-misses 1063951139
# controller-statistics 1 data-read 7711.4GB
# controller-statistics 1 data-read-numeric 7711480795648
# controller-statistics 1 data-written 40.8TB
# controller-statistics 1 data-written-numeric 40830379518976
# controller-statistics 1 num-forwarded-cmds 1
# controller-statistics 1 reset-time 2015-05-22 13:54:37
# controller-statistics 1 reset-time-numeric 1432302877
# controller-statistics 1 start-sample-time 2015-08-21 11:51:52
# controller-statistics 1 start-sample-time-numeric 1440157912
# controller-statistics 1 stop-sample-time 2015-08-21 11:51:57
# controller-statistics 1 stop-sample-time-numeric 1440157917
# controller-statistics 1 total-power-on-hours 2636.59

#   .--controller cpu------------------------------------------------------.
#   |                   _             _ _                                  |
#   |    ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __    ___ _ __  _   _     |
#   |   / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|  / __| '_ \| | | |    |
#   |  | (_| (_) | | | | |_| | | (_) | | |  __/ |    | (__| |_) | |_| |    |
#   |   \___\___/|_| |_|\__|_|  \___/|_|_|\___|_|     \___| .__/ \__,_|    |
#   |                                                     |_|              |
#   +----------------------------------------------------------------------+
#   |                           main check                                 |
#   '----------------------------------------------------------------------'


hp_msa_controller_cpu_default_levels = (80.0, 90.0)


def inventory_hp_msa_controller_cpu(parsed):
    for key in parsed.keys():
        yield key, "hp_msa_controller_cpu_default_levels"


def check_hp_msa_controller_cpu(item, params, parsed):
    if item in parsed:
        # hp msa 2040 reference guide:
        # cpu-load: percentage of time the CPU is busy, from 0-100
        return check_cpu_util(float(parsed[item]["cpu-load"]), params)


check_info['hp_msa_controller'] = {
    'parse_function'            : parse_hp_msa,
    'inventory_function'        : inventory_hp_msa_controller_cpu,
    'check_function'            : check_hp_msa_controller_cpu,
    'service_description'       : 'CPU Utilization %s',
    'has_perfdata'              : True,
    'group'                     : 'cpu_utilization_multiitem',
    'includes'                  : [ "hp_msa.include", "cpu_util.include" ],
}

#.
#   .--controller IO-------------------------------------------------------.
#   |                       _             _ _             ___ ___          |
#   |        ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __  |_ _/ _ \         |
#   |       / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|  | | | | |        |
#   |      | (_| (_) | | | | |_| | | (_) | | |  __/ |     | | |_| |        |
#   |       \___\___/|_| |_|\__|_|  \___/|_|_|\___|_|    |___\___/         |
#   |                                                                      |
#   '----------------------------------------------------------------------'

check_info['hp_msa_controller.io'] = {
    'inventory_function'        : inventory_hp_msa_io,
    'check_function'            : check_hp_msa_io,
    'service_description'       : 'Controller IO %s',
    'has_perfdata'              : True,
    'group'                     : 'diskstat',
    'includes'                  : [ "hp_msa.include", "diskstat.include" ],
}
