Merge ~dmzoneill/charm-nrpe:dev/check_mtu into ~nrpe-charmers/charm-nrpe:master

Proposed by David O Neill
Status: Superseded
Proposed branch: ~dmzoneill/charm-nrpe:dev/check_mtu
Merge into: ~nrpe-charmers/charm-nrpe:master
Diff against target: 126 lines (+120/-0)
1 file modified
files/plugins/check_mtu.py (+120/-0)
Reviewer Review Type Date Requested Status
Xav Paice (community) Needs Fixing
Giuseppe Petralia Approve
Canonical IS Reviewers Pending
Paul Goins Pending
Jeremy Lounder Pending
Review via email: mp+381947@code.launchpad.net

This proposal has been superseded by a proposal from 2020-07-23.

Commit message

MTU checker for neutron-gateway

To post a comment you must log in.
Revision history for this message
Giuseppe Petralia (peppepetra) wrote :

Looks good to me.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Xav Paice (xavpaice) wrote :

Example output:

./check_mtu.py --br br-int
br-tun: {'tap1da46df0-92': '1500', 'tap2677f6d5-30': '1500', 'tap2f307b01-8f': '1500', 'tap3ec55528-46': '1500', 'tap419c0544-fb': '1500', 'tap459fbadd-fb': '1500', 'tap490f00ee-2a': '1500', 'tap5f347b80-bc': '1500', 'tap650c3391-0b': '1500', 'tap697a22b3-a9': '8900', 'tap6e473310-2e': '1500', 'tap832fb175-1b': '1500', 'tap88db0ccc-0f': '1500', 'tap8a586526-f3': '1500', 'tap8de5df09-4e': '1500', 'tap9486dc0f-39': '1500', 'tap9aa78180-c4': '1500', 'tapaf94b5dc-0e': '1500', 'tapb3729a8b-c9': '1500', 'tapb91190ec-58': '1500', 'tapc88975d5-c0': '1500', 'tapcb431075-db': '1500', 'tapd60ad8ba-3e': '1500', 'tapdf6a3c1b-d2': '1500', 'tapea6c2a8f-07': '1500', 'tapee3b1760-c7': '1500', 'tapeea0bf18-0d': '1500', 'tapf4d69938-c5': '1500', 'tapfd05a248-11': '8900'}
br-int: {'tap697a22b3-a9': '8900', 'tapfd05a248-11': '8900'}
WARNING: found tenant MTUs greater than bridge MTU

The standards for Nagios plugins dicatate that the plugin should output just one line of info, rather than multiple - otherwise Nagios can't process it.

I don't see any implementation of the plugin here, this just delivers the plugin for something else to make use of it - assuming there's a separate change to the neutron-gateway charm or some such, in order to do that.

review: Needs Fixing

Unmerged commits

0174f7b... by David O Neill

MTU checker for neutron-gateway

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/files/plugins/check_mtu.py b/files/plugins/check_mtu.py
2new file mode 100755
3index 0000000..5f53efb
4--- /dev/null
5+++ b/files/plugins/check_mtu.py
6@@ -0,0 +1,120 @@
7+#!/usr/bin/env python3
8+# -*- coding: us-ascii -*-
9+
10+# Copyright (C) 2017 Canonical
11+# All rights reserved
12+# Author: David O Neill <david.o.neill@canonical.com>
13+
14+import argparse
15+import subprocess
16+
17+from nagios_plugin3 import (
18+ CriticalError,
19+ WarnError,
20+ try_check,
21+)
22+
23+
24+def get_mtu(device):
25+ """Get the MTU of a device."""
26+ try:
27+ with open("/sys/class/net/" + device + "/mtu") as f:
28+ return f.read().strip()
29+ except FileNotFoundError:
30+ return None
31+ except AttributeError:
32+ return None
33+
34+
35+def get_taps(bridge):
36+ """Return taps array associated with a bridge."""
37+ try:
38+ process = subprocess.Popen(['ovs-vsctl', 'list-ports', bridge],
39+ stdout=subprocess.PIPE)
40+ return (process.communicate()[0]).decode('utf-8').split('\n')
41+ except subprocess.CalledProcessError:
42+ raise CriticalError(
43+ 'CRITICAL: Unable to read bridge information from ovs-vsctl')
44+
45+
46+def check_bridge_mtus(iface_br, iface_remap):
47+ """Check that the tap devices associated with bridge have smaller MTUS. """
48+ bridge_iface = iface_remap if iface_remap is not False else iface_br
49+ ifaces = get_taps(bridge_iface)
50+
51+ bridge_mtu = get_mtu(iface_br)
52+ bad_mtus = {}
53+
54+ for iface in ifaces:
55+ mtu = get_mtu(iface)
56+ if mtu is not None:
57+ if iface_remap is not False:
58+ # gre 24 bytes, vxlan 50 recommended padding
59+ if int(mtu) + 50 > int(bridge_mtu):
60+ bad_mtus[iface] = mtu
61+ else:
62+ if int(mtu) > int(bridge_mtu):
63+ bad_mtus[iface] = mtu
64+
65+ return bad_mtus
66+
67+
68+def iterate_bridges(bridges):
69+ """Iterates the bridges."""
70+ results = {}
71+ to_check = {
72+ 'br-tun': 'br-int'
73+ }
74+
75+ if " " in bridges.strip():
76+ # mutiple bridges to check
77+ for brbinding in bridges.split(" "):
78+ to_check[brbinding] = False
79+ else:
80+ # single bridge
81+ to_check[bridges] = False
82+
83+ for key, value in to_check.items():
84+ # format is br-ex:eno2
85+ iface_br = key if ":" not in key else key.split(":")[0]
86+ results[iface_br] = check_bridge_mtus(iface_br, value)
87+
88+ nagios_ok = True
89+ for bridge in results.keys():
90+ if len(results[bridge].keys()) > 0:
91+ print(bridge + ": " + str(results[bridge]))
92+ nagios_ok = False
93+
94+ if nagios_ok:
95+ print("OK: Tenant MTU configuration is sane")
96+ else:
97+ msg = 'WARNING: found tenant MTUs greater than bridge MTU'
98+ raise WarnError(msg)
99+
100+
101+def parse_args():
102+ parser = argparse.ArgumentParser(description='Check mtu on bridge slaves')
103+ parser.add_argument('--br', '-br', help='space separated list of bridges')
104+ args = parser.parse_args()
105+ return args
106+
107+
108+def main():
109+ """
110+ GRE padding typically 22 bytes,
111+ The recommended padding for vxlan is 50.
112+ Assuming 50 for all encapped networks.
113+ 9000
114+ 1450 1450 1450 1500 1450
115+ packet -> br-ex -> br-int -> br-tun -> machine
116+ """
117+ args = parse_args()
118+
119+ if args.br is None or args.br.strip() == "":
120+ raise CriticalError('WARNING: No bridges provided for MTU check?')
121+
122+ try_check(iterate_bridges, args.br)
123+
124+
125+if __name__ == '__main__':
126+ main()

Subscribers

People subscribed via source and target branches