/usr/share/check_mk/checks/netctr 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 | #!/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.
linux_nic_check = "lnx_if"
# levels for warning/critical on error rate - in percentage of total packets!
netctr_default_params = (0.01, 0.1)
netctr_counters = [ 'rx_bytes', 'tx_bytes', 'rx_packets', 'tx_packets', 'rx_errors', 'tx_errors', 'tx_collisions' ]
# Check counters from network interfaces
# Item is devicename.countername, eg,
# eth0.tx_collisions. Available are:
netctr_counter_indices = {
# Receive
'rx_bytes' : 0,
'rx_packets' : 1,
'rx_errors' : 2,
'rx_drop' : 3,
'rx_fifo' : 4,
'rx_frame' : 5,
'rx_compressed' : 6,
'rx_multicast' : 7,
# Transmit
'tx_bytes' : 8,
'tx_packets' : 9,
'tx_errors' : 10,
'tx_drop' : 11,
'tx_fifo' : 12,
'tx_collisions' : 13,
'tx_carrier' : 14,
'tx_compressed' : 15 }
def inventory_netctr_combined(info):
if linux_nic_check != "legacy":
return []
if len(info) == 0:
return []
return [ (l[0], '', 'netctr_default_params') for l in info[1:] if l[0] != 'lo' and not l[0].startswith("sit") ]
def check_netctr_combined(nic, params, info):
try:
warn, crit = params
except:
warn, crit = (0.01, 0.1)
global netctr_counter_indices
this_time = int(info[0][0])
# Look for line describing this nic
for nicline in info[1:]:
if nicline[0] != nic: continue
perfdata = []
infotxt = ""
problems_per_sec = 0.0
packets_per_sec = 0.0
counter_wrapped = None
for countername in netctr_counters:
index = netctr_counter_indices[countername]
value = int(nicline[index + 1])
try:
timedif, items_per_sec = get_counter( "netctr." + nic + "." + countername, this_time, value)
perfdata.append( ( countername, "%dc" % value ) )
except MKCounterWrapped, e:
counter_wrapped = e
# Important: continue counter loop, so that *all* counters get initialized.
# Otherwise this checks would need 7 check cycles until the first result
# would be produced
continue
if countername in [ "rx_errors", "tx_errors", "tx_collisions" ]:
problems_per_sec += items_per_sec
elif countername in [ "rx_packets", "tx_packets" ]:
packets_per_sec += items_per_sec
if countername == 'rx_bytes':
infotxt += ' - Receive: %.2f MB/sec' % (float(items_per_sec) / float(1024*1024))
elif countername == 'tx_bytes':
infotxt += ' - Send: %.2f MB/sec' % (float(items_per_sec) / float(1024*1024))
# if at least one counter wrapped, we cannot send or use performance
# data and leave out this check for this turn
if counter_wrapped:
raise counter_wrapped
error_percentage = 0.0
if problems_per_sec > 0:
error_percentage = (problems_per_sec / packets_per_sec) * 100.0
infotxt += ", error rate %.4f%%" % error_percentage
if error_percentage >= crit:
return (2, "CRIT" + infotxt, perfdata)
elif error_percentage >= warn:
return (1, "WARNING" + infotxt, perfdata)
else:
return (0, "OK" + infotxt, perfdata)
return (3, "UNKNOWN - NIC is not present")
check_info['netctr.combined'] = (check_netctr_combined, "NIC %s counters", 1, inventory_netctr_combined )
check_config_variables.append("netctr_counters")
|