/usr/share/check_mk/checks/if.include is in check-mk-server 1.1.12-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | #!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2010 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.
# Functions and definitions used by if and if64
if_inventory_porttypes = [ '6', '32', '117' ]
if_inventory_portstates = [ '1' ]
if_inventory_uses_description = False
if_inventory_uses_alias = False
if_inventory_monitor_speed = True
if_inventory_monitor_state = True
if_default_levels = (0.01, 0.1, None, None, ('1', 'up')) # Only defined for legacy compatibility
if_default_error_levels = (0.01, 0.1) # percentages or errors!
if_default_traffic_levels = (None, None) # No levels and bandwidth usage
if_default_average = None # No average computing
# Remove 0 bytes from strings. They lead to problems e.g. here:
# On windows hosts the labels of network interfaces in oid
# iso.3.6.1.2.1.2.2.1.2.1 are given as hex strings with tailing
# 0 byte. When this string is part of the data which is sent to
# the nagios pipe all chars after the 0 byte are stripped of.
# Stupid fix: Remove all 0 bytes. Hope this causes no problems.
def cleanup_if_strings(s):
if s and s != '':
return "".join([ c for c in s if c not in nagios_illegal_chars+chr(0) ]).strip()
else:
return s
# make sure, that configuration variable is present in precompiled host checks
check_config_variables.append("nagios_illegal_chars")
# default error levels are needed in case of incomplete parameter dictionary
check_config_variables.append("if_default_error_levels")
# Name of state (lookup SNMP enum)
def if_statename(st):
names = { '1': 'up', '2': 'down',
'3': 'testing', '4': 'unknown',
'5': 'dormant', '6': 'notPresent',
'7': 'lowerLayerDown' }
return names.get(st, st)
def inventory_if_common(info):
if len(info) == 0 or len(info[0]) != 19:
return []
pre_inventory = []
seen_items = set([])
duplicate = set([])
for ifIndex, ifDescr, ifType, ifSpeed, ifOperStatus, ifInOctets, inucast, inmcast, inbcast, ifInDiscards, \
ifInErrors, ifOutOctets, outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors, ifOutQLen, ifAlias in info:
ifDescr = cleanup_if_strings(ifDescr)
ifAlias = cleanup_if_strings(ifAlias)
# compute item now - also for unmonitored ports - in order to see if it
# is uninque.
if if_inventory_uses_description and ifDescr:
item = ifDescr
elif if_inventory_uses_alias and ifAlias:
item = ifAlias
else:
item = ifIndex
if item in seen_items: # duplicate
duplicate.add(item)
seen_items.add(item)
if ifType in if_inventory_porttypes and ifOperStatus in if_inventory_portstates:
paramstring = '{ "errors" : if_default_error_levels, ' \
'"traffic" : if_default_traffic_levels, ' \
'"average" : if_default_average '
if if_inventory_monitor_state:
paramstring += ', "state" : "%s"' % ifOperStatus
if ifSpeed != "" and if_inventory_monitor_speed:
paramstring += ', "speed" : %d' % int(ifSpeed)
paramstring += "}"
pre_inventory.append( (item, paramstring, int(ifIndex)) )
# Check for duplicate items (e.g. when using Alias as item and the alias is not unique)
inventory = []
for item, params, index in pre_inventory:
if item in duplicate:
new_item = "%s %d" % (item, index)
else:
new_item = item
inventory.append((new_item, params))
return inventory
def check_if_common(item, params, info):
err_warn, err_crit = 0, 0
targetspeed = None
targetstate = None
bw_warn, bw_crit = None, None
average = None
# new style of check parameters since 1.1.9i1
if type(params) == dict:
err_warn, err_crit = params.get("errors", if_default_error_levels)
targetspeed = params.get("speed")
targetstate = params.get("state")
bw_warn, bw_crit = params.get("traffic", (None, None))
average = params.get("average")
# old style of parameters: tuple with various length
elif len(params) == 3:
err_warn, err_crit, targetspeed = params
elif len(params) == 5:
err_warn, err_crit, targetspeed, bw_warn, bw_crit = params
elif len(params) == 6:
err_warn, err_crit, targetspeed, bw_warn, bw_crit, targetstate = params
for ifIndex, ifDescr, ifType, ifSpeed, ifOperStatus, ifInOctets, \
inucast, inmcast, inbcast, ifInDiscards, ifInErrors, ifOutOctets, \
outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors, \
ifOutQLen, ifAlias in info:
ifDescr = cleanup_if_strings(ifDescr)
ifAlias = cleanup_if_strings(ifAlias)
if item == ifIndex \
or item == ifAlias \
or item == ifDescr \
or item == "%s %s" % (ifAlias, ifIndex) \
or item == "%s %s" % (ifDescr, ifIndex):
# Display port number or alias in infotext if that is not part
# of the service description anyway
if item == ifIndex and (item == ifAlias or ifAlias == '') \
and (item == ifDescr or ifDescr == ''): # description trivial
infotext = ""
elif item == "%s %s" % (ifAlias, ifIndex) and ifDescr != '': # non-unique Alias
infotext = "[%s/%s]" % (ifAlias, ifDescr)
elif item != ifAlias and ifAlias != '': # alias useful
infotext = "[%s] " % ifAlias
elif item != ifDescr and ifDescr != '': # description useful
infotext = "[%s] " % ifDescr
else:
infotext = "[%s] " % ifIndex
state = 0
operstatus = if_statename(str(ifOperStatus))
if targetstate and \
(ifOperStatus != targetstate
and not (type(targetstate) in [ list, tuple ] and ifOperStatus in targetstate)):
state = 2
infotext += "(%s)(!!) " % operstatus
else:
infotext += "(%s) " % operstatus
# prepare reference speed for computing relative bandwidth usage
speed = saveint(ifSpeed)
if speed:
ref_speed = speed / 8.0
elif targetspeed:
ref_speed = targetspeed / 8.0
else:
ref_speed = None
# Check speed settings of interface, but only if speed information
# is available. This is not always the case.
if speed:
infotext += get_nic_speed_human_readable(speed)
if not targetspeed is None and speed != targetspeed:
infotext += " (wrong speed, expected: %s)(!)" % get_nic_speed_human_readable(targetspeed)
state = max(state, 1)
elif targetspeed:
infotext += "assuming %s" % get_nic_speed_human_readable(targetspeed)
else:
infotext += "speed unknown"
# convert percentages to absolute values if levels are float
# this is only possible if a reference speed is available.
if ref_speed:
if bw_warn != None and type(bw_warn) == float:
bw_warn = bw_warn / 100.0 * ref_speed
if bw_crit != None and type(bw_crit) == float:
bw_crit = bw_crit / 100.0 * ref_speed
# Ignore percentual levels if no reference speed is available
else:
if bw_warn != None and type(bw_warn) == float:
bw_warn = None
if bw_crit != None and type(bw_crit) == float:
bw_crit = None
# Performance counters
this_time = time.time()
rates = []
wrapped = False
perfdata = []
for name, counter, warn, crit, mmin, mmax in [
( "in", ifInOctets, bw_warn, bw_crit, 0, ref_speed),
( "inucast", inucast, None, None, None, None),
( "innucast", saveint(inmcast) + saveint(inbcast), None, None, None, None),
( "indisc", ifInDiscards, None, None, None, None),
( "inerr", ifInErrors, err_warn, err_crit, None, None),
( "out", ifOutOctets, bw_warn, bw_crit, 0, ref_speed),
( "outucast", outucast, None, None, None, None),
( "outnucast", saveint(outmcast) + saveint(outbcast), None, None, None, None),
( "outdisc", ifOutDiscards, None, None, None, None),
( "outerr", ifOutErrors, err_warn, err_crit, None, None) ]:
try:
timedif, rate = get_counter("if.%s.%s" % (name, item), this_time, saveint(counter))
rates.append(rate)
perfdata.append( (name, rate, warn, crit, mmin, mmax) )
except MKCounterWrapped:
wrapped = True
# continue, other counters might wrap as well
# if at least one counter wrapped, we do not handle the counters at all
if wrapped:
perfdata = []
else:
perfdata.append(("outqlen", saveint(ifOutQLen)))
for what, errorrate, okrate, traffic in \
[ ("in", rates[4], rates[1] + rates[2], rates[0]),
("out", rates[9], rates[6] + rates[7], rates[5]) ]:
infotext += ", %s: %s/s" % (what, get_bytes_human_readable(traffic))
if ref_speed:
perc_used = 100.0 * traffic / ref_speed
infotext += "(%.1f%%)" % perc_used
# handle computation of average
if average:
timedif, traffic_avg = get_average("if.%s.%s.avg" % (what, item), this_time, traffic, average)
infotext += ", %dmin avg: %s/s" % (average, get_bytes_human_readable(traffic_avg))
perfdata.append( ("%s_avg_%d" % (what, average), traffic_avg, bw_warn, bw_crit, 0, ref_speed) )
traffic = traffic_avg # apply levels to average traffic
# Check bandwidth thresholds
if not bw_crit is None and traffic >= bw_crit:
state = 2
infotext += ' (!!) >= ' + get_bytes_human_readable(bw_crit) + "/s"
elif not bw_warn is None and traffic >= bw_warn:
state = max(state, 1)
infotext += ' (!) >= ' + get_bytes_human_readable(bw_warn) + "/s"
pacrate = okrate + errorrate
if pacrate > 0.0: # any packets transmitted?
errperc = 100.0 * errorrate / (okrate + errorrate)
if errperc > 0:
infotext += ", %s-errors: %.2f%%" % (what, errperc)
if errperc >= err_crit:
state = 2
infotext += "(!!) >= " + str(err_crit)
elif errperc >= err_warn:
state = max(state, 1)
infotext += "(!) >= " + str(err_warn)
return (state, "%s - %s" % (nagios_state_names[state], infotext), perfdata)
return (3, "UNKNOWN - no such interface")
# possible port types are:
# other(1), regular1822(2), hdh1822(3), ddnX25(4), rfc877x25(5),
# ethernetCsmacd(6), iso88023Csmacd(7), iso88024TokenBus(8),
# iso88025TokenRing(9), iso88026Man(10), starLan(11), proteon10Mbit(12),
# proteon80Mbit(13), hyperchannel(14), fddi(15), lapb(16), sdlc(17), ds1(18),
# e1(19), basicISDN(20), primaryISDN(21), propPointToPointSerial(22),
# ppp(23), softwareLoopback(24), eon(25), ethernet3Mbit(26),
# nsip(27), slip(28), ultra(29), ds3(30), sip(31), frameRelay(32),
# rs232(33), para(34), arcnet(35), arcnetPlus(36), atm(37), miox25(38),
# sonet(39), x25ple(40), iso88022llc(41), localTalk(42), smdsDxi(43),
# frameRelayService(44), v35(45), hssi(46), hippi(47), modem(48),
# aal5(49), sonetPath(50), sonetVT(51), smdsIcip(52), propVirtual(53),
# propMultiplexor(54), ieee80212(55), fibreChannel(56), hippiInterface(57),
# frameRelayInterconnect(58), aflane8023(59), aflane8025(60), cctEmul(61),
# fastEther(62), isdn(63), v11(64), v36(65), g703at64k(66), g703at2mb(67),
# qllc(68), fastEtherFX(69), channel(70), ieee80211(71), ibm370parChan(72),
# escon(73), dlsw(74), isdns(75), isdnu(76), lapd(77), ipSwitch(78),
# rsrb(79), atmLogical(80), ds0(81), ds0Bundle(82), bsc(83), async(84),
# cnr(85), iso88025Dtr(86), eplrs(87), arap(88), propCnls(89), hostPad(90),
# termPad(91), frameRelayMPI(92), x213(93), adsl(94), radsl(95), sdsl(96),
# vdsl(97), iso88025CRFPInt(98), myrinet(99), voiceEM(100), voiceFXO(101),
# voiceFXS(102), voiceEncap(103), voiceOverIp(104), atmDxi(105), atmFuni(106),
# atmIma(107), pppMultilinkBundle(108), ipOverCdlc(109), ipOverClaw(110),
# stackToStack(111), virtualIpAddress(112), mpc(113), ipOverAtm(114),
# iso88025Fiber(115), tdlc(116), gigabitEthernet(117), hdlc(118), lapf(119),
# v37(120), x25mlp(121), x25huntGroup(122), trasnpHdlc(123), interleave(124),
# fast(125), ip(126), docsCableMaclayer(127), docsCableDownstream(128),
# docsCableUpstream(129), a12MppSwitch(130), tunnel(131), coffee(132),
# ces(133), atmSubInterface(134), l2vlan(135), l3ipvlan(136), l3ipxvlan(137),
# digitalPowerline(138), mediaMailOverIp(139), dtm(140), dcn(141),
# ipForward(142), msdsl(143), ieee1394(144), if-gsn(145), dvbRccMacLayer(146),
# dvbRccDownstream(147), dvbRccUpstream(148), atmVirtual(149), mplsTunnel(150),
# srp(151), voiceOverAtm(152), voiceOverFrameRelay(153), idsl(154),
# compositeLink(155), ss7SigLink(156), propWirelessP2P(157), frForward(158),
# rfc1483(159), usb(160), ieee8023adLag(161), bgppolicyaccounting(162),
# frf16MfrBundle(163), h323Gatekeeper(164), h323Proxy(165), mpls(166),
# mfSigLink(167), hdsl2(168), shdsl(169), ds1FDL(170), pos(171), dvbAsiIn(172),
# dvbAsiOut(173), plc(174), nfas(175), tr008(176), gr303RDT(177), gr303IDT(178),
# isup(179), propDocsWirelessMaclayer(180), propDocsWirelessDownstream(181),
# propDocsWirelessUpstream(182), hiperlan2(183), propBWAp2Mp(184),
# sonetOverheadChannel(185), digitalWrapperOverheadChannel(186),
# aal2(187), radioMAC(188), atmRadio(189), imt(190), mvl(191), reachDSL(192),
# frDlciEndPt(193), atmVciEndPt(194), opticalChannel(195), opticalTransport(196),
# propAtm(197), voiceOverCable(198), infiniband(199), teLink(200), q2931(201),
# virtualTg(202), sipTg(203), sipSig(204), docsCableUpstreamChannel(205),
# econet(206), pon155(207), pon622(208), bridge(209), linegroup(210),
# voiceEMFGD(211), voiceFGDEANA(212), voiceDID(213), mpegTransport(214),
# sixToFour(215), gtp(216), pdnEtherLoop1(217), pdnEtherLoop2(218),
# opticalChannelGroup(219), homepna(220), gfp(221), ciscoISLvlan(222),
# actelisMetaLOOP(223), fcipLink(224), rpr(225), qam(226), lmp(227),
# cblVectaStar(228), docsCableMCmtsDownstream(229), adsl2(230)
|