Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit 4d0bb03c authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent 65b6b741
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
# 2021-07-01: extended if64 to use ifNAme instead of ifDescr
from typing import (
List,
)
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
SNMPTree,
type_defs,
)
from cmk.base.plugins.agent_based.utils import if64, interfaces
_interface_displayhints = {
'ethernet': 'Eth',
'fastethernet': 'Fa',
'gigabitethernet': 'Gi',
'tengigabitethernet': 'Te',
'fortygigabitethernet': 'Fo',
'hundredgigabitethernet': 'Hu',
'port-channel': 'Po',
'tunnel': 'Tu',
'loopback': 'Lo',
'cellular': 'Cel',
'vlan': 'Vlan',
'management': 'Ma',
}
def _get_short_if_name(ifname: str) -> str:
"""
returns short interface name from long interface name
ifname: is the long interface name
:type ifname: str
"""
for ifname_prefix in _interface_displayhints.keys():
if ifname.lower().startswith(ifname_prefix.lower()):
ifname_short = _interface_displayhints[ifname_prefix]
return ifname.lower().replace(ifname_prefix.lower(), ifname_short, 1)
return ifname
def parse_if64name(string_table: List[type_defs.StringByteTable]) -> interfaces.Section:
for interface in string_table[0]:
if interface[-1] is not '':
interface[1] = interface[-1] # replace ifDescr with ifName (.1.3.6.1.2.1.31.1.1.1.1)
interface[1] = _get_short_if_name(interface[1]) # ifDescr (.1.3.6.1.2.1.2.2.1.2)
interface.pop() # remove last entry from interfaces (ifName) -> return original if64 format
return if64.parse_if64(string_table)
register.snmp_section(
name="if64name",
parsed_section_name='if64',
parse_function=parse_if64name,
fetch=[
SNMPTree(
base=if64.BASE_OID,
oids=if64.END_OIDS + ['31.1.1.1.1'] # IF-MIB::ifName,
),
],
detect=if64.HAS_ifHCInOctets,
supersedes=['if', 'statgrab_net', 'if64'],
)
File added
{'author': 'thl-cmk[at]outlook[dot]com',
'description': 'This snmp section/(parse function extends the if64 check by '
'replacing ifDescr with ifName if available. It will also '
'replace the long interface name with a short version.\n'
'To use this extension you need to have a interface discovery '
'rule that uses interface description for the service item. To '
'use the unchanged if64 version, just disable the if64_name '
'snmp section.\n',
'download_url': 'https://thl-cmk.hopto.org',
'files': {'agent_based': ['if64name.py']},
'name': 'if64name',
'num_files': 1,
'title': 'ifName extension for if64',
'version': '20210704_v0.0.1',
'version.min_required': '2.0.0',
'version.packaged': '2021.04.10',
'version.usable_until': None}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment