#!/usr/bin/python
# -*- coding: utf-8; py-indent-offset: 4 -*-
#  _______ __   _ ____     __
# |       |  \ | |___ \   / /
# |       |   \| | __) | / /-,_
# |       | |\   |/ __/ /__   _|
# |_______|_| \__|_____|   |_|
#
# @author Markus Birth <markus.birth@weltn24.de>
# MIBs: ftp://ftp.snellgroup.com/RollCall/SNMP_MIBs/

def inventory_snell_iqh_eth(info):
    inventory = []
    for oidend, lname, lstate, lspeed, llastchange, lerrors, ltrafficin, ltrafficout in info[0]:
        if lstate == "Active":
            inventory.append( ( lname, None) )
    return inventory

def check_snell_iqh_eth(item, _no_params, info):
    for oidend, lname, lstate, lspeed, llastchange, lerrors, ltrafficin, ltrafficout in info[0]:
        if lname == item:
            message = "%s with %s, Errors: %s (IN: %s / OUT: %s)" % (lstate, lspeed, lerrors, ltrafficin, ltrafficout)
            if lstate == "Active":
                status = 0
            else:
                status = 2

            errorcount = int("0"+lerrors.split(" ")[0])
            tin  = savefloat(ltrafficin.split(" ")[0])
            tout = savefloat(ltrafficout.split(" ")[0])

            perfdata = [
                ("Traffic_In", tin, None, None, 0, 100),
                ("Traffic_Out", tout, None, None, 0, 100),
                ("Errors", errorcount, None, None, 0, 100),
            ]

            return status, message, perfdata

    return 3, "%s not found in SNMP data." % item

check_info["snell_iqh_eth"] = {
    "check_function"        : check_snell_iqh_eth,
    "inventory_function"    : inventory_snell_iqh_eth,
    "service_description"   : "%s",
    "snmp_info"             : [(".1.3.6.1.4.1.7995.1.3.1", [ "429.1.1", "475.1.1" ], [
                                    OID_END,
                                    2030,    # lan1name       ("FastEthernet0/1")
                                    2031,    # lan1state      ("Active")
                                    2032,    # lan1speed      ("100 Mbit/s Full Dup")
                                    2033,    # lan1lastChange ("000:00:00:00")
                                    2034,    # lan1errors     ("0 in total")
                                    2035,    # lan1trafficIn  ("0.0 KBytes/sec")
                                    2036,    # lan1trafficOut ("0.0 KBytes/sec")
                              ])],
    "snmp_scan_function"    : lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.7995.1.3"),
    "has_perfdata"          : True
}
