|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +# Description: Check-MK plugin for monitoring adsl lines |
| 4 | +# File: adsl_line.py |
| 5 | +# Version: 1.1 (requires check_mk 2.0) |
| 6 | +# Author: Ulrich Baumann <check_mk@uli-baumann.de> |
| 7 | +# |
| 8 | +# https://www.draytek.com/support/knowledge-base/5517 |
| 9 | +# supported ADSL-LINE-MIB OIDs in Draytek Vigor Routers |
| 10 | +# (ADSL and VDSL are using same OIDs) |
| 11 | +# 1.3.6.1.2.1.10.94.1.1.1.1.1 adslLineCoding |
| 12 | +# 1.3.6.1.2.1.10.94.1.1.1.1.2 adslLineType |
| 13 | +# 1.3.6.1.2.1.10.94.1.1.1.1.3 adslLineSpecific |
| 14 | +# 1.3.6.1.2.1.10.94.1.1.1.1.4 adslLineConfProfile |
| 15 | +# 1.3.6.1.2.1.10.94.1.1.1.1.5 adslLineAlarmConfProfile |
| 16 | +# 1.3.6.1.2.1.10.94.1.1.3.1.1 adslAturInvSerialNumber |
| 17 | +# 1.3.6.1.2.1.10.94.1.1.3.1.2 adslAturInvVendorID |
| 18 | +# 1.3.6.1.2.1.10.94.1.1.3.1.3 adslAturInvVersionNumber |
| 19 | +# 1.3.6.1.2.1.10.94.1.1.3.1.4 adslAturCurrSnrMgn |
| 20 | +# 1.3.6.1.2.1.10.94.1.1.3.1.5 adslAturCurrAtn |
| 21 | +# 1.3.6.1.2.1.10.94.1.1.3.1.6 adslAturCurrStatus |
| 22 | +# 1.3.6.1.2.1.10.94.1.1.3.1.7 adslAturCurrOutputPwr |
| 23 | +# 1.3.6.1.2.1.10.94.1.1.3.1.8 adslAturCurrAttainableRate |
| 24 | +# 1.3.6.1.2.1.10.94.1.1.4.1.2 adslAtucChanCurrTxRate (DSL router's Rx Rate) |
| 25 | +# 1.3.6.1.2.1.10.94.1.1.5.1.1 adslAturChanInterleaveDelay |
| 26 | +# 1.3.6.1.2.1.10.94.1.1.5.1.2 adslAturChanCurrTxRate (DSL router's Tx rate) |
| 27 | +# 1.3.6.1.2.1.10.94.1.1.5.1.3 adslAturChanPrevTxRate |
| 28 | +# 1.3.6.1.2.1.10.94.1.1.5.1.4 adslAturChanCrcBlockLength |
| 29 | + |
| 30 | +from .agent_based_api.v1 import * |
| 31 | +from .utils.interfaces import cleanup_if_strings |
| 32 | +from cmk.base.check_api import get_nic_speed_human_readable |
| 33 | + |
| 34 | + |
| 35 | +# helper function for combining states |
| 36 | +def worst(old,new): |
| 37 | + if (new==State.CRIT) or (old==State.CRIT): |
| 38 | + return State.CRIT |
| 39 | + elif (new==State.WARN) or (old==State.WARN): |
| 40 | + return State.WARN |
| 41 | + else: return State.OK |
| 42 | + |
| 43 | +# discovery function |
| 44 | +def discover_adsl_line(section): |
| 45 | + for oid_end,adslLineCoding, adslLineType, adslLineSpecific, \ |
| 46 | + adslAturInvSerialNumber, adslAturInvVendorID, adslAturInvVersionNumber, \ |
| 47 | + adslAturCurrSnrMgn, adslAturCurrAtn, adslAturCurrStatus, adslAturCurrOutputPwr, \ |
| 48 | + adslAturCurrAttainableRate, adslAtucChanCurrTxRate, adslAturChanCurrTxRate \ |
| 49 | + in section: |
| 50 | + yield Service(item=oid_end) # item name follows oid enumeration |
| 51 | + |
| 52 | +# check function |
| 53 | +def check_adsl_line(item, params, section): |
| 54 | + # constants from ADSL-LINE-MIB |
| 55 | + adslLineCodings = { 1: "other", 2: "dmt", 3: "cap", 4: "qam" } |
| 56 | + adslLineTypes = { 1: "noChannel", 2: "fastOnly", 3: "interleavedOnly", \ |
| 57 | + 4: "fastOrInterleaved", 5: "fastAndInterleaved" } |
| 58 | + # iterate ADSL Lines |
| 59 | + for oid_end,adslLineCoding, adslLineType, adslLineSpecific, \ |
| 60 | + adslAturInvSerialNumber, adslAturInvVendorID, adslAturInvVersionNumber, \ |
| 61 | + adslAturCurrSnrMgn, adslAturCurrAtn, adslAturCurrStatus, adslAturCurrOutputPwr, \ |
| 62 | + adslAturCurrAttainableRate, adslAtucChanCurrTxRate, adslAturChanCurrTxRate \ |
| 63 | + in section: |
| 64 | + if (item != oid_end): continue |
| 65 | + status = State.OK |
| 66 | + statusString = '' |
| 67 | + perfData = [] |
| 68 | + # check link status |
| 69 | + adslAturCurrStatus=cleanup_if_strings(adslAturCurrStatus) |
| 70 | + statusString += adslAturCurrStatus |
| 71 | + if adslAturCurrStatus != "SHOWTIME": |
| 72 | + status = worst(status, State.CRIT) |
| 73 | + # check upstream |
| 74 | + statusString += ', Up: '+get_nic_speed_human_readable(adslAturChanCurrTxRate) |
| 75 | + if 'upstream_params' in params: |
| 76 | + upstream_warn,upstream_crit = params['upstream_params'] |
| 77 | + upstream_warn=int(upstream_warn)*10**6 |
| 78 | + upstream_crit=int(upstream_crit)*10**6 |
| 79 | + if int(adslAturChanCurrTxRate) < upstream_crit: |
| 80 | + status = worst(status, State.CRIT) |
| 81 | + statusString += ' (CRIT at '+get_nic_speed_human_readable(upstream_crit)+')' |
| 82 | + elif int(adslAturChanCurrTxRate) < upstream_warn: |
| 83 | + status = worst(status, State.WARN) |
| 84 | + statusString += ' (WARN at '+get_nic_speed_human_readable(upstream_warn)+')' |
| 85 | + else: upstream_warn,upstream_crit=None,None |
| 86 | + yield Metric("adsl_up_rate",int(adslAturChanCurrTxRate), levels=(upstream_warn,upstream_crit)) |
| 87 | + # check downstream |
| 88 | + statusString += ', Down: '+get_nic_speed_human_readable(adslAtucChanCurrTxRate) |
| 89 | + if 'downstream_params' in params: |
| 90 | + downstream_warn,downstream_crit = params['downstream_params'] |
| 91 | + downstream_warn=downstream_warn*10**6 |
| 92 | + downstream_crit=downstream_crit*10**6 |
| 93 | + if int(adslAtucChanCurrTxRate) < downstream_crit: |
| 94 | + status = worst(status, State.CRIT) |
| 95 | + statusString += ' (CRIT at '+get_nic_speed_human_readable(downstream_crit)+')' |
| 96 | + elif int(adslAtucChanCurrTxRate) < downstream_warn: |
| 97 | + status = worst(status, State.WARN) |
| 98 | + statusString += ' (WARN at '+get_nic_speed_human_readable(downstream_warn)+')' |
| 99 | + else: downstream_warn,downstream_crit=None,None |
| 100 | + yield Metric("adsl_down_rate",int(adslAtucChanCurrTxRate),levels=(downstream_warn,downstream_crit)) |
| 101 | + |
| 102 | + # attainable data rate |
| 103 | + statusString += ', Attainable: '+get_nic_speed_human_readable(adslAturCurrAttainableRate) |
| 104 | + yield Metric("adsl_attainable",int(adslAturCurrAttainableRate)) |
| 105 | + |
| 106 | + # check snr_margin |
| 107 | + statusString += ', SNR Margin: ' + adslAturCurrSnrMgn+' dB' |
| 108 | + if 'snr_margin_params' in params: |
| 109 | + snr_margin_warn,snr_margin_crit = params['snr_margin_params'] |
| 110 | + if int(adslAturCurrSnrMgn) < snr_margin_crit: |
| 111 | + status = worst(status, State.CRIT) |
| 112 | + statusString += ' (CRIT at '+str(snr_margin_crit)+' dB)' |
| 113 | + elif int(adslAturCurrSnrMgn) < snr_margin_warn: |
| 114 | + status = worst(status, State.WARN) |
| 115 | + statusString += ' (WARN at '+str(snr_margin_warn)+' dB)' |
| 116 | + else: snr_margin_warn,snr_margin_crit=None,None |
| 117 | + yield Metric("adsl_snr_margin",int(adslAturCurrSnrMgn),levels=(snr_margin_warn,snr_margin_crit)) |
| 118 | + |
| 119 | + # check attenuation |
| 120 | + statusString += ', Attenuation: ' + adslAturCurrAtn+' dB' |
| 121 | + if 'attenuation_params' in params: |
| 122 | + attenuation_warn,attenuation_crit = params['attenuation_params'] |
| 123 | + if int(adslAturCurrAtn) > attenuation_crit: |
| 124 | + status = worst(status, State.CRIT) |
| 125 | + statusString += ' (CRIT at '+str(attenuation_crit)+' dB)' |
| 126 | + elif int(adslAturCurrAtn) > attenuation_warn: |
| 127 | + status = worst(status, State.WARN) |
| 128 | + statusString += ' (WARN at '+str(attenuation_warn)+' dB)' |
| 129 | + else: attenuation_warn,attenuation_crit=None,None |
| 130 | + yield Metric("adsl_attenuation",int(adslAturCurrAtn),levels=(attenuation_warn,attenuation_crit)) |
| 131 | + |
| 132 | + # additional info for status string |
| 133 | + statusString += ', '+\ |
| 134 | + 'Output Power: '+adslAturCurrOutputPwr+' db, '+\ |
| 135 | + 'Line Coding: '+adslLineCodings.get(int(adslLineCoding),"unknown")+', '+\ |
| 136 | + 'Line Type: '+adslLineTypes.get(int(adslLineType),"unknown") |
| 137 | + yield Metric("adsl_output_power",int(adslAturCurrOutputPwr)) |
| 138 | + |
| 139 | + yield Result(state=status,summary=f"{statusString}") |
| 140 | + |
| 141 | + |
| 142 | +register.snmp_section( |
| 143 | + name = "adsl_line", |
| 144 | + detect = matches(".1.3.6.1.2.1.1.1.0", ".*Vigor(130|165).*"), |
| 145 | + fetch = SNMPTree( |
| 146 | + base = '.1.3.6.1.2.1.10.94.1.1', |
| 147 | + oids = [ |
| 148 | + OIDEnd(), # interface number |
| 149 | + "1.1.1", # adslLineCoding |
| 150 | + "1.1.2", # adslLineType |
| 151 | + "1.1.3", # adslLineSpecific |
| 152 | + "3.1.1", # adslAturInvSerialNumber |
| 153 | + "3.1.2", # adslAturInvVendorID |
| 154 | + "3.1.3", # adslAturInvVersionNumber |
| 155 | + "3.1.4", # adslAturCurrSnrMgn |
| 156 | + "3.1.5", # adslAturCurrAtn |
| 157 | + "3.1.6", # adslAturCurrStatus |
| 158 | + "3.1.7", # adslAturCurrOutputPwr |
| 159 | + "3.1.8", # adslAturCurrAttainableRate |
| 160 | + "4.1.2", # adslAtucChanCurrTxRate |
| 161 | + "5.1.2", # adslAtucChanCurrTxRate |
| 162 | + ] ), |
| 163 | +) |
| 164 | + |
| 165 | +CHECK_DEFAULT_PARAMETERS = { |
| 166 | + 'downstream_params': (0,0), |
| 167 | + 'upstream_params': (0,0), |
| 168 | + 'attenuation_params': (30,45), |
| 169 | + 'snr_margin_params': (10,6), |
| 170 | +} |
| 171 | + |
| 172 | +register.check_plugin( |
| 173 | + name = "adsl_line", |
| 174 | + service_name = "ADSL Interface %s", |
| 175 | + discovery_function = discover_adsl_line, |
| 176 | + check_function = check_adsl_line, |
| 177 | + check_ruleset_name="adsl_line", |
| 178 | + check_default_parameters=CHECK_DEFAULT_PARAMETERS, |
| 179 | +) |
| 180 | + |
0 commit comments