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

# drives 1 durable-id disk_01.01
# drives 1 enclosure-id 1
# drives 1 drawer-id 255
# drives 1 slot 1
# drives 1 location 1.1
# drives 1 port 0
# drives 1 scsi-id 0
# drives 1 blocks 1172123568
# drives 1 serial-number W7GB13NV
# drives 1 vendor HP
# drives 1 model EG0600FBVFP
# drives 1 revision HPDC
# drives 1 secondary-channel 0
# drives 1 container-index 0
# drives 1 member-index 0
# drives 1 description SAS
# drives 1 description-numeric 4
# drives 1 architecture HDD
# drives 1 architecture-numeric 1
# drives 1 interface SAS
# drives 1 interface-numeric 0
# drives 1 single-ported Disabled
# drives 1 single-ported-numeric 0
# drives 1 type SAS
# drives 1 type-numeric 4
# drives 1 usage LINEAR POOL
# drives 1 usage-numeric 1
# drives 1 job-running
# drives 1 job-running-numeric 0
# drives 1 state LINEAR POOL
# drives 1 current-job-completion
# drives 1 blink 0
# drives 1 locator-led Off
# drives 1 locator-led-numeric 0
# drives 1 speed 0
# drives 1 smart Enabled
# drives 1 smart-numeric 1
# drives 1 dual-port 1
# drives 1 error 0
# drives 1 fc-p1-channel 0
# drives 1 fc-p1-device-id 0
# drives 1 fc-p1-node-wwn 5000CCA07014111C
# drives 1 fc-p1-port-wwn 0000000000000000
# drives 1 fc-p1-unit-number 0
# drives 1 fc-p2-channel 0
# drives 1 fc-p2-device-id 0
# drives 1 fc-p2-node-wwn
# drives 1 fc-p2-port-wwn
# drives 1 fc-p2-unit-number 0
# drives 1 drive-down-code 0
# drives 1 owner A
# drives 1 owner-numeric 1
# drives 1 index 0
# drives 1 rpm 10
# drives 1 size 600.1GB
# drives 1 size-numeric 1172123568
# drives 1 sector-format 512n
# drives 1 sector-format-numeric 0
# drives 1 transfer-rate 6.0
# drives 1 transfer-rate-numeric 3
# drives 1 attributes
# drives 1 attributes-numeric 2
# drives 1 enclosure-wwn 500C0FF01E82BB3C
# drives 1 recon-state N/A
# drives 1 recon-state-numeric 0
# drives 1 copyback-state N/A
# drives 1 copyback-state-numeric 0
# drives 1 virtual-disk-serial 00c0ff1ec44a00001e23415500000000
# drives 1 disk-group IMSAKO2B1_U1_B01-04
# drives 1 storage-pool-name IMSAKO2B1_U1_B01-04
# drives 1 storage-tier N/A
# drives 1 storage-tier-numeric 0
# drives 1 ssd-life-left N/A
# drives 1 ssd-life-left-numeric 255
# drives 1 led-status-numeric 1
# drives 1 disk-dsd-count 0
# drives 1 spun-down 0
# drives 1 number-of-ios 0
# drives 1 total-data-transferred 0B
# drives 1 total-data-transferred-numeric 0
# drives 1 avg-rsp-time 0
# drives 1 fde-state Not FDE Capable
# drives 1 fde-state-numeric 1
# drives 1 lock-key-id 00000000
# drives 1 import-lock-key-id 00000000
# drives 1 fde-config-time N/A
# drives 1 fde-config-time-numeric 0
# drives 1 pi-formatted Unsupported
# drives 1 pi-formatted-numeric 4
# drives 1 power-on-hours 2663
# drives 1 health OK
# drives 1 health-numeric 0
# drives 1 health-reason
# drives 1 health-recommendation
# disk-statistics 1 durable-id disk_01.01
# disk-statistics 1 serial-number W7GB13NV
# disk-statistics 1 bytes-per-second 771.0KB
# disk-statistics 1 bytes-per-second-numeric 771072
# disk-statistics 1 iops 13
# disk-statistics 1 number-of-reads 49797666
# disk-statistics 1 number-of-writes 20095262
# disk-statistics 1 data-read 50.6TB
# disk-statistics 1 data-read-numeric 50656968970752
# disk-statistics 1 data-written 2800.2GB
# disk-statistics 1 data-written-numeric 2800282933760
# disk-statistics 1 queue-depth 0
# disk-statistics 1 reset-time 2015-05-22 13:55:39
# disk-statistics 1 reset-time-numeric 1432302939
# disk-statistics 1 start-sample-time 2015-08-18 10:37:02
# disk-statistics 1 start-sample-time-numeric 1439894222
# disk-statistics 1 stop-sample-time 2015-08-18 11:09:27
# disk-statistics 1 stop-sample-time-numeric 1439896167
# disk-statistics 1 smart-count-1 0
# disk-statistics 1 io-timeout-count-1 0
# disk-statistics 1 no-response-count-1 0
# disk-statistics 1 spinup-retry-count-1 0
# disk-statistics 1 number-of-media-errors-1 0
# disk-statistics 1 number-of-nonmedia-errors-1 6
# disk-statistics 1 number-of-block-reassigns-1 0
# disk-statistics 1 number-of-bad-blocks-1 0
# disk-statistics 1 smart-count-2 0
# disk-statistics 1 io-timeout-count-2 0
# disk-statistics 1 no-response-count-2 0
# disk-statistics 1 spinup-retry-count-2 0
# disk-statistics 1 number-of-media-errors-2 0
# disk-statistics 1 number-of-nonmedia-errors-2 1
# disk-statistics 1 number-of-block-reassigns-2 0
# disk-statistics 1 number-of-bad-blocks-2 0

#   .--health--------------------------------------------------------------.
#   |                    _                _ _   _                          |
#   |                   | |__   ___  __ _| | |_| |__                       |
#   |                   | '_ \ / _ \/ _` | | __| '_ \                      |
#   |                   | | | |  __/ (_| | | |_| | | |                     |
#   |                   |_| |_|\___|\__,_|_|\__|_| |_|                     |
#   |                                                                      |
#   +----------------------------------------------------------------------+
#   |                           main check                                 |
#   '----------------------------------------------------------------------'

check_info['hp_msa_disk'] = {
    'parse_function'            : parse_hp_msa,
    'inventory_function'        : inventory_hp_msa_health,
    'check_function'            : check_hp_msa_health,
    'service_description'       : 'Disk Health %s',
    'includes'                  : [ "hp_msa.include" ],
}

#.
#   .--disk IO-------------------------------------------------------------.
#   |                         _ _     _      ___ ___                       |
#   |                      __| (_)___| | __ |_ _/ _ \                      |
#   |                     / _` | / __| |/ /  | | | | |                     |
#   |                    | (_| | \__ \   <   | | |_| |                     |
#   |                     \__,_|_|___/_|\_\ |___\___/                      |
#   |                                                                      |
#   '----------------------------------------------------------------------'

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

#.
#   .--temperature---------------------------------------------------------.
#   |      _                                      _                        |
#   |     | |_ ___ _ __ ___  _ __   ___ _ __ __ _| |_ _   _ _ __ ___       |
#   |     | __/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \      |
#   |     | ||  __/ | | | | | |_) |  __/ | | (_| | |_| |_| | | |  __/      |
#   |      \__\___|_| |_| |_| .__/ \___|_|  \__,_|\__|\__,_|_|  \___|      |
#   |                       |_|                                            |
#   '----------------------------------------------------------------------'


factory_settings["hp_msa_disk_temp_default_levels"] = {
    "levels"        : (40.0, 45.0), # just an assumption
}


def inventory_hp_msa_disk_temp(parsed):
    return [ ("Disks", {}) ]


def check_hp_msa_disk_temp(item, params, parsed):
    disks = []
    for key, values in parsed.items():
        disks.append( (key, float( values["temperature-numeric"] )) )

    return check_temperature_list(disks, params, "hp_msa_disk_temp_%s" % item)


check_info['hp_msa_disk.temp'] = {
    'inventory_function'        : inventory_hp_msa_disk_temp,
    'check_function'            : check_hp_msa_disk_temp,
    'service_description'       : 'Temperature %s',
    'group'                     : 'temperature',
    'has_perfdata'              : True,
    'default_levels_variable'   : "hp_msa_disk_temp_default_levels",
    'includes'                  : [ "hp_msa.include", "temperature.include" ],
}

#.
