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

# "0=Off, 1=On in DI/DO mode or N=Count in DO counter mode"

def inventory_iologik_register(info):
    inventory = []
    for line in info:
        if line[2]:
            inventory.append((line[0], None ))
    return inventory


def check_iologik_register(item, params, info):
    for line in info:
        if line[0] == item:
            if int(line[2]) in range(0, 2):
                return (int(line[2]), line[1])
            else:
                return (3, "Invalid value %s for register" % line[2])

    return (3, "Register not found")


check_info['moxa_iologik_register'] = {
    "check_function"        : check_iologik_register,
    "inventory_function"    : inventory_iologik_register,
    "service_description"   : "Moxa Register",
    "has_perfdata"          : False,
    "group"                 : "iologik_register",
    "snmp_scan_function"    : lambda oid: oid(".1.3.6.1.4.1.8691.10.2242.2.0").startswith("E2242-T"),
    "snmp_info"             : (".1.3.6.1.4.1.8691.10.2242.10.4.1.1",
                            [ "1", # index
                              "2", # Name
                              "3", # Value
                            ])
}

# DIOEntry
# dioIndex Integer32 (0..11) 	"The channel dio index."
# dioType Integer32 (0..1)  	"The channel dio type. 0=DI, DO=1, AI=2"
# dioMode Integer32 (0..1)  	"The channel dio mode. 0=DI, 1=Event Counter"
# dioStatus Unsigned32 (0..4294967295)	"The channel dio(di/do) status. 0=Off, 1=On in DI/DO mode or N=Count in DO counter mode
# dioFilter Integer32 (1..65535) "The channel dio(di) counter filter. unit=0.5ms"
# dioTrigger Integer32 (0..1)	"The channel dio(di) counter trigger level. 0=L2H, 1=H2L"
# dioCntStart Integer32 (0..1)	"The channel dio(do) counter start/stop. 0=stop, 1=start"
# dioPulseStart	Integer32 (0..1) "The channel dio(do) pulse start/stop. 0=stop, 1=start"
# dioPulseONWidth Unsigned32 (1..4294967295) "The channel dio(do) signal ON width. unit=0.5ms"
# dioPulseOFFWidth Unsigned32 (1..4294967295) "The channel dio(do) signal OFF width. unit=0.5ms"
