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

innovaphone_channels_default_levels = (75.0, 80.0)

def inventory_innovaphone_channels(info):
    return [ (x[0], 'innovaphone_channels_default_levels') for x in info \
             if x[1] == "Up" and x[2] == "Up" ]

def check_innovaphone_channels(item, params, info):
    for line in info:
        if line[0] == item:
            link, physical = line[1:3]
            if link != 'Up' or physical != 'Up':
                return 2, "Link: %s, Physical: %s" % (link, physical)
            idle, total = map(float, line[3:])
            perc_used = (idle / total) * 100
            perc_free = 100 - perc_used
            message = "(used: %.0f, free: %.0f, total: %.0f)" % (total - idle, idle, total)
            return check_innovaphone(params, [[None,perc_free]], '%', message )
    return 3, "No Channel information found"

check_info["innovaphone_channels"] = {
    "check_function"        : check_innovaphone_channels,
    "inventory_function"    : inventory_innovaphone_channels,
    "service_description"   : "Channel %s",
    "has_perfdata"          : True,
    "group"                 : "hw_single_channelserature",
    "include"               : ["innovaphone.include"]
}

