Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / netctr
blob1f2ce90d0e4b03500840ed7e972a6ff3015692ab
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 linux_nic_check = "lnx_if"
29 # levels for warning/critical on error rate - in percentage of total packets!
30 netctr_default_params = (0.01, 0.1)
32 netctr_counters = [
33 'rx_bytes', 'tx_bytes', 'rx_packets', 'tx_packets', 'rx_errors', 'tx_errors', 'tx_collisions'
36 # Check counters from network interfaces
37 # Item is devicename.countername, eg,
38 # eth0.tx_collisions. Available are:
40 netctr_counter_indices = {
41 # Receive
42 'rx_bytes': 0,
43 'rx_packets': 1,
44 'rx_errors': 2,
45 'rx_drop': 3,
46 'rx_fifo': 4,
47 'rx_frame': 5,
48 'rx_compressed': 6,
49 'rx_multicast': 7,
50 # Transmit
51 'tx_bytes': 8,
52 'tx_packets': 9,
53 'tx_errors': 10,
54 'tx_drop': 11,
55 'tx_fifo': 12,
56 'tx_collisions': 13,
57 'tx_carrier': 14,
58 'tx_compressed': 15
62 def inventory_netctr_combined(info):
63 if linux_nic_check != "legacy":
64 return []
65 if len(info) == 0:
66 return []
67 return [(l[0], '', 'netctr_default_params')
68 for l in info[1:]
69 if l[0] != 'lo' and not l[0].startswith("sit")]
72 def check_netctr_combined(nic, params, info):
73 try:
74 warn, crit = params
75 except:
76 warn, crit = (0.01, 0.1)
78 this_time = int(info[0][0])
80 # Look for line describing this nic
81 for nicline in info[1:]:
82 if nicline[0] != nic:
83 continue
84 perfdata = []
85 infotxt = ""
86 problems_per_sec = 0.0
87 packets_per_sec = 0.0
88 for countername in netctr_counters:
89 index = netctr_counter_indices[countername]
90 value = int(nicline[index + 1])
91 items_per_sec = get_rate("netctr." + nic + "." + countername, this_time, value)
92 perfdata.append((countername, "%dc" % value))
94 if countername in ["rx_errors", "tx_errors", "tx_collisions"]:
95 problems_per_sec += items_per_sec
96 elif countername in ["rx_packets", "tx_packets"]:
97 packets_per_sec += items_per_sec
98 if countername == 'rx_bytes':
99 infotxt += ' - Receive: %.2f MB/sec' % (float(items_per_sec) / float(1024 * 1024))
100 elif countername == 'tx_bytes':
101 infotxt += ' - Send: %.2f MB/sec' % (float(items_per_sec) / float(1024 * 1024))
103 error_percentage = 0.0
104 if problems_per_sec > 0:
105 error_percentage = (problems_per_sec / packets_per_sec) * 100.0
106 infotxt += ", error rate %.4f%%" % error_percentage
107 if error_percentage >= crit:
108 return (2, infotxt, perfdata)
109 elif error_percentage >= warn:
110 return (1, infotxt, perfdata)
111 return (0, infotxt, perfdata)
113 return (3, "NIC is not present")
116 check_config_variables.append("netctr_counters")
118 check_info["netctr.combined"] = {
119 'check_function': check_netctr_combined,
120 'inventory_function': inventory_netctr_combined,
121 'service_description': 'NIC %s counters',
122 'has_perfdata': True,