Module: check_mk
Branch: master
Commit: 072d328c273b40910ed9bb449ea4e63bc23ab6f7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=072d328c273b40…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Mon Aug 14 15:29:22 2017 +0200
Refactoring: Extract logic for item calculation and inventory rules from brocade_fcport to
brocade.include
This is in preparation for a new check that needs to share this logic.
Change-Id: Ieef47a0d74855bc3a0876897b4b14d4edad21bf9
---
checks/brocade.include | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
checks/brocade_fcport | 42 ++++++++++------------------------
2 files changed, 74 insertions(+), 30 deletions(-)
diff --git a/checks/brocade.include b/checks/brocade.include
new file mode 100644
index 0000000..66991cd
--- /dev/null
+++ b/checks/brocade.include
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2017 mk(a)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-
+# tails. 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.
+
+# This is the variable for the actual rule
+brocade_fcport_inventory = []
+
+def brocade_fcport_inventory_this_port(admstate, phystate, opstate, settings):
+ default_inventory_phystates = [ 3, 4, 5, 6, 7, 8, 9, 10 ]
+ default_inventory_opstates = [ 1, 2, 3, 4, ]
+ default_inventory_admstates = [ 1, 3, 4, ]
+
+ admstates = settings.get('admstates', default_inventory_admstates)
+ opstates = settings.get('opstates', default_inventory_opstates)
+ phystates = settings.get('phystates', default_inventory_phystates)
+
+ return admstate in admstates and \
+ opstate in opstates and \
+ phystate in phystates
+
+
+
+def brocade_fcport_getitem(number_of_ports, index, portname, is_isl, settings):
+
+ uses_portname = settings.get('use_portname', True)
+ shows_isl = settings.get('show_isl', True)
+
+ itemname = ("%0" + str(len(str(number_of_ports))) + "d") % (index
- 1)
+ if is_isl and shows_isl:
+ itemname += " ISL"
+ if portname.strip() and uses_portname:
+ itemname += " " + portname.strip()
+ return itemname
+
+
+# Inverse to the above. Caveat: Maps back to an index that starts with 1,
+# as the SNMP tables in brocade_fcport and brocade_sfp are indexed this way.
+# TODO: Check whether we can simplify brocade_fcport a bit using this.
+def brocade_item_to_port_number(item):
+ return int(item.split()[0]) + 1
diff --git a/checks/brocade_fcport b/checks/brocade_fcport
index 0b115ed..073b36f 100644
--- a/checks/brocade_fcport
+++ b/checks/brocade_fcport
@@ -88,15 +88,6 @@ isl_speed = {
"512": 16, # sexdecuple (512) - 16 Gbaud
}
-# settings for inventory: which ports should be inventorized
-brocade_fcport_inventory_phystates = [ 3, 4, 5, 6, 7, 8, 9, 10 ]
-brocade_fcport_inventory_opstates = [ 1, 2, 3, 4, ]
-brocade_fcport_inventory_admstates = [ 1, 3, 4, ]
-brocade_fcport_inventory_use_portname = True # use swFCPortName as part of service
description
-brocade_fcport_inventory_show_isl = True # add "ISL" to service description
for interswitch links
-brocade_fcport_inventory = []
-
-
factory_settings["brocade_fcport_default_levels"] = {
"rxcrcs": (3.0, 20.0), # allowed percentage of CRC errors
"rxencoutframes": (3.0, 20.0), # allowed percentage of Enc-OUT Frames
@@ -107,16 +98,6 @@ factory_settings["brocade_fcport_default_levels"] = {
}
-# Helper function for computing item from port number
-def brocade_fcport_getitem(ports, index, portname, is_isl, uses_portname, shows_isl):
- itemname = ("%0" + str(len(str(len(ports)))) + "d") % (index -
1)
- if is_isl and shows_isl:
- itemname += " ISL"
- if portname.strip() and uses_portname:
- itemname += " " + portname.strip()
- return itemname
-
-
def parse_brocade_fcport(info):
if_info, link_info, speed_info, if64_info = info
isl_ports = {}
@@ -202,22 +183,22 @@ def parse_brocade_fcport(info):
def inventory_brocade_fcport(parsed):
settings = host_extra_conf_merged(host_name(), brocade_fcport_inventory)
- uses_portname = settings.get('use_portname',
brocade_fcport_inventory_use_portname)
- shows_isl = settings.get('show_isl', brocade_fcport_inventory_show_isl)
- admstates = settings.get('admstates', brocade_fcport_inventory_admstates)
- opstates = settings.get('opstates', brocade_fcport_inventory_opstates)
- phystates = settings.get('phystates', brocade_fcport_inventory_phystates)
inventory = []
for if_entry in parsed:
+ admstate = if_entry["admstate"]
phystate = if_entry["phystate"]
opstate = if_entry["opstate"]
- admstate = if_entry["admstate"]
- if admstate in admstates and \
- opstate in opstates and \
- phystate in phystates:
- inventory.append((brocade_fcport_getitem(parsed, if_entry["index"],
if_entry["portname"],
- if_entry["is_isl"],
uses_portname, shows_isl),
+ if brocade_fcport_inventory_this_port(admstate=admstate,
+ phystate=phystate,
+ opstate=opstate,
+ settings=settings):
+ inventory.append((brocade_fcport_getitem(
+ number_of_ports=len(parsed),
+ index=if_entry["index"],
+ portname=if_entry["portname"],
+ is_isl=if_entry["is_isl"],
+ settings=settings),
'{ "phystate": [%d], "opstate":
[%d], "admstate": [%d] }' % \
(phystate, opstate, admstate)))
return inventory
@@ -444,6 +425,7 @@ check_info["brocade_fcport"] = {
],
'snmp_scan_function' : lambda oid:
oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.1588.2.1.1") \
and
oid(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.*") != None,
+ 'includes' : [ 'brocade.include' ],
'group' : 'brocade_fcport',
'default_levels_variable' : 'brocade_fcport_default_levels',
}