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

netapp_fcpio_default_levels = { "read" : (None, None), "write" : (None, None)}

def check_netapp_fcpio(item, params, info):
    read, write = map(int, info[0])
    this_time = int(time.time())
    timedif, avg_read  = get_counter("netapp_fcpio.read", this_time, read)
    timedif, avg_write  = get_counter("netapp_fcpio.write", this_time, write)

    read_warn, read_crit = params['read']
    write_warn, write_crit = params['write']

    perfdata = [("write", avg_write, write_warn, write_crit ),
    		("read", avg_read, read_warn, read_crit ),
    	       ]
    state = 0
    read_msg = ''
    write_msg = ''
    if read_warn != None and read_warn >= read:
        state = 1
	read_msg = ' (!)'
    if read_crit != None and read_crit >= read:
        state = 2
	read_msg = ' (!!)'

    if write_warn != None and write_warn >= write:
        state = max(state, 1)
        write_msg = ' (!)'
    if write_crit != None and write_crit >= write:
        state = 2
	write_msg = ' (!!)'


    infotext = " - %s read%s, %s write%s in last %d sec" % (get_filesize_human_readable(avg_read), \
    read_msg, get_filesize_human_readable(avg_write), write_msg, timedif)

    return(state, nagios_state_names[state] + infotext, perfdata)


check_info["netapp_fcpio"] = {
    "check_function"        : check_netapp_fcpio,
    "inventory_function"    : lambda info: [(None, "netapp_fcpio_default_levels")],
    "service_description"   : "FCP I/O",
    "has_perfdata"          : True,
    "group"                 : "netapp_fcportio",
    "snmp_scan_function"    : lambda oid: oid(".1.3.6.1.4.1.789.1.17.20.0"),
    "snmp_info"		    : ( ".1.3.6.1.4.1.789.1.17", [ 20, 21 ]),
}

