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


def convert_huawei_osn_if(line):
    return [
        line[0],     # ifIndex                    0
        line[0],     # ifDescr                    1
        '39',        # ifType                     2
        '0',         # ifSpeed                    3
        '1',         # ifOperStatus               4
        line[7],     # ifHCInOctets               5
        line[1],     # ifHCInUcastPkts            6
        line[2],     # ifHCInMulticastPkts        7
        line[3],     # ifHCInBroadcastPkts        8
        '0',         # ifInDiscards               9
        line[13],    # ifInErrors                10
        line[8],     # ifHCOutOctets             11
        line[4],     # ifHCOutUcastPkts          12
        line[5],     # ifHCOutMulticastPkts      13
        line[6],     # ifHCOutBroadcastPkts      14
        '0',         # ifOutDiscards             15
        line[14],    # ifOutErrors               16
        '0',         # ifOutQLen                 17
        line[0],     # ifAlias                   18
        '',          # ifPhysAddress             19
    ]


def inventory_huawei_osn_if(info):
    for line in info:
        yield (line[0], {})


def check_huawei_osn_if(item, params, info):
    payload = []
    for line in info:
        if item == line[0]:
            payload.append(convert_huawei_osn_if(line))
            return check_if_common(item, params, payload)


check_info['huawei_osn_if'] = {
    'inventory_function'        : inventory_huawei_osn_if,
    'check_function'            : check_huawei_osn_if,
    'service_description'       : 'Interface %s',
    'snmp_info'                 : ('.1.3.6.1.4.1.2011.2.25.3.40.50.96.50.1', [
                                        "3.200", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmPara                   0
                                        "4.113", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXUNICAST   1
                                        "4.114", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXMULCAST   2
                                        "4.115", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXBRDCAST   3
                                        "4.116", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXUNICAST   4
                                        "4.117", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXMULCAST   5
                                        "4.118", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXBRDCAST   6
                                        "4.200", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXOCTETS    7
                                        "4.199", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXOCTETS    8
                                        "4.201", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXPKTS      9
                                        "4.198", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXPKTS     10
                                        "4.128", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXBBAD     11
                                        "4.129", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXBBAD     12
                                        "4.944", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXPBAD     13
                                        "4.945", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXPBAD     14
                                  ]),
    'snmp_scan_function'        : huawei_osn_scan_function,
    'has_perfdata'              : True,
    'includes'                  : [ 'huawei_osn.include', 'if.include' ],
    'group'                     : 'if',
    'default_levels_variable'   : 'if_default_levels',
}
