GUI CSS: Deployed view styles for layouts (CMK-1171)
[check_mk.git] / checks / rmon_stats
blob5840e80647c9deb921fd6aab571f29b4589f7c2d
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 # This check extracts data from 1.3.6.1.2.1.16.1.1.1 =
28 # iso(1). org(3). dod(6). internet(1). mgmt(2). mib-2(1). rmon(16).
29 # statistics(1). etherStatsTable(1). etherStatsEntry(1)
30 # The MIB is called RMON-MIB
32 inventory_if_rules = []
35 def inventory_rmon_stats(info):
36 settings = host_extra_conf_merged(host_name(), inventory_if_rules)
37 if settings.get("rmon"):
38 inventory = []
39 for line in info:
40 inventory.append((line[0], None))
41 return inventory
44 def check_rmon_stats(item, _no_params, info):
45 bytes_map = {
46 1: 'bcast',
47 2: 'mcast',
48 3: '0-63b',
49 4: '64-127b',
50 5: '128-255b',
51 6: '256-511b',
52 7: '512-1023b',
53 8: '1024-1518b'
55 perfdata = []
56 infotext = ''
57 now = time.time()
58 for line in info:
59 if line[0] == item:
60 for i, val in bytes_map.items():
61 octets = int(re.sub(' Packets', '', line[i]))
62 rate = get_rate("%s-%s" % (item, val), now, octets)
63 perfdata.append((val, rate, 0, 0, 0))
64 infotext += "%s=%.0f " % (val, rate)
65 infotext += 'octets/sec'
66 return 0, infotext, perfdata
68 return (3, "port not found")
70 check_info["rmon_stats"] = {
71 'check_function' : check_rmon_stats,
72 'inventory_function' : inventory_rmon_stats,
73 'service_description' : 'RMON Stats IF %s',
74 'has_perfdata' : True,
75 'snmp_info' : ('.1.3.6.1.2.1.16.1.1.1', [ #
76 '1', # etherStatsIndex = Item
77 '6', # etherStatsBroadcastPkts
78 '7', # etherStatsMulticastPkts
79 '14', # etherStatsPkts64Octets
80 '15', # etherStatsPkts65to127Octets
81 '16', # etherStatsPkts128to255Octets
82 '17', # etherStatsPkts256to511Octets
83 '18', # etherStatsPkts512to1023Octets
84 '19', # etherStatsPkts1024to1518Octets
85 ]),
86 # for the scan we need to check for any single object in the RMON tree,
87 # we choose netDefaultGateway in the hope that it will always be present
88 'snmp_scan_function' : lambda oid: ( oid(".1.3.6.1.2.1.1.1.0").lower().startswith("cisco") \
89 or oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.11863.1.1.3" \
90 ) and oid(".1.3.6.1.2.1.16.19.12.0") is not None,