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

Proposed by Xav Paice
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~xavpaice/charm-nrpe:dev/check_mtu
Merge into: ~nrpe-charmers/charm-nrpe:master
Diff against target: 127 lines (+121/-0)
1 file modified
files/plugins/check_mtu.py (+121/-0)
Reviewer Review Type Date Requested Status
Xav Paice (community) Disapprove
Paul Goins Approve
BootStack Reviewers mr tracking; do not claim Pending
BootStack Reviewers Pending
Canonical IS Reviewers Pending
Canonical IS Reviewers Pending
Giuseppe Petralia Pending
Jeremy Lounder Pending
Review via email: mp+387913@code.launchpad.net

This proposal supersedes a proposal from 2020-04-08.

Commit message

MTU checker for neutron-gateway

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

Looks good to me.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Xav Paice (xavpaice) wrote : Posted in a previous version of this proposal

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
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
James Hebden (ec0) wrote :

Great idea. A few comments inline.

Revision history for this message
James Troup (elmo) wrote :

Some commentary.

Revision history for this message
James Troup (elmo) wrote :

Yep, replying to myself

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

Thanks for the reviews - I added a couple of comments below, and will submit an additional commit to address these issues.

~xavpaice/charm-nrpe:dev/check_mtu updated
6cf0d35... by Xav Paice

Address review comments from check_mtu.py

- some documentation fixes
- change get_mtu() to return an int()
- fix the output detail being reset for each interface

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

Ready for another look.

review: Needs Resubmitting
Revision history for this message
Paul Goins (vultaire) wrote :

Added my feedback, hopefully I'm not being too nitpicky.

review: Needs Fixing
~xavpaice/charm-nrpe:dev/check_mtu updated
2728bb5... by Xav Paice

update check_mtu arg syntax

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

Thanks for that, I've updated the change and the change at https://review.opendev.org/#/c/718168 has been updated to reflect the changed CLI args.

review: Needs Resubmitting
Revision history for this message
Paul Goins (vultaire) wrote :

LGTM

review: Approve
Revision history for this message
Drew Freiberger (afreiberger) wrote :

minor nit on wording of "OK" response. "is sane" seems judgemental and unscientific. Would be more accurate to say "matches expected value".

Revision history for this message
James Troup (elmo) wrote :

Minor commentary; don't feel obliged to block on it.

Revision history for this message
Drew Freiberger (afreiberger) wrote :

+1 on the typecasting overkill noted by James

~xavpaice/charm-nrpe:dev/check_mtu updated
eed1103... by Xav Paice

minor rework on check_mtu.py

Adjust some wording and layout in response to review feedback for the
check_mtu.py NRPE check.

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

Thanks for these, adjusted and added a fresh commit.

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

This needs some rework and confirmation of assumptions, marking WIP and it needs to head back to the backlog (along with an associated bug report which I've not found yet)

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

I think this belongs in charmhelpers (under contrib/openstack/files) or in the neutron-gateway charm itself, rather than in nrpe. I'll draft a change in charmhelpers, since the plugin seems to be something that could be useful outside the neutron-gateway unit itself.

review: Disapprove

Unmerged commits

eed1103... by Xav Paice

minor rework on check_mtu.py

Adjust some wording and layout in response to review feedback for the
check_mtu.py NRPE check.

2728bb5... by Xav Paice

update check_mtu arg syntax

6cf0d35... by Xav Paice

Address review comments from check_mtu.py

- some documentation fixes
- change get_mtu() to return an int()
- fix the output detail being reset for each interface

a70f663... by Xav Paice

update check_mtu.py plugin for one line of output

172acab... 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..cdd8854
4--- /dev/null
5+++ b/files/plugins/check_mtu.py
6@@ -0,0 +1,121 @@
7+#!/usr/bin/env python3
8+
9+# Author: David O Neill <david.o.neill@canonical.com>
10+
11+import argparse
12+import subprocess
13+
14+from nagios_plugin3 import UnknownError, WarnError, try_check
15+
16+
17+# Note:
18+# GRE padding typically 22 bytes,
19+# The recommended padding for vxlan is 50.
20+# Assuming 50 for all encapped networks.
21+PADDING = 50
22+
23+
24+def get_mtu(device):
25+ """Get the MTU of a device.
26+
27+ Reads /sys/class/net/ for the device MTU
28+
29+ Args:
30+ device (string): The name of the device
31+
32+ Returns:
33+ int: The MTU of the device, or 0 if there's any kind of error
34+ """
35+ try:
36+ with open("/sys/class/net/" + device + "/mtu") as f:
37+ mtu = f.read().strip()
38+ return int(mtu)
39+ except FileNotFoundError:
40+ return 0
41+ except AttributeError:
42+ return 0
43+
44+
45+def get_taps(bridge):
46+ """Return taps array associated with a bridge."""
47+ try:
48+ process = subprocess.Popen(
49+ ["ovs-vsctl", "list-ports", bridge], stdout=subprocess.PIPE
50+ )
51+ return (process.communicate()[0]).decode("utf-8").split("\n")
52+ except subprocess.CalledProcessError:
53+ raise UnknownError("UNKNOWN: Unable to read bridge information from ovs-vsctl")
54+
55+
56+def check_bridge_mtus(iface_br, iface_remap):
57+ """Check that the tap devices associated with bridge have smaller MTUs."""
58+ bridge_iface = iface_remap if iface_remap is not False else iface_br
59+ ifaces = get_taps(bridge_iface)
60+
61+ bridge_mtu = get_mtu(iface_br)
62+ if bridge_mtu <= 0:
63+ raise UnknownError(
64+ "UNKNOWN: Unable to read bridge information from /sys/class/net"
65+ )
66+ bad_mtus = {}
67+
68+ for iface in ifaces:
69+ mtu = get_mtu(iface)
70+ if iface_remap is not False:
71+ if mtu + PADDING > bridge_mtu:
72+ bad_mtus[iface] = mtu
73+ else:
74+ if mtu > bridge_mtu:
75+ bad_mtus[iface] = mtu
76+
77+ return bad_mtus
78+
79+
80+def iterate_bridges(bridges):
81+ """Iterates the bridges."""
82+ results = {}
83+ to_check = {"br-tun": "br-int"}
84+
85+ for brbinding in bridges:
86+ to_check[brbinding] = False
87+
88+ for key, value in to_check.items():
89+ # format is br-ex:eno2
90+ iface_br = key if ":" not in key else key.split(":")[0]
91+ results[iface_br] = check_bridge_mtus(iface_br, value)
92+
93+ nagios_ok = True
94+ msg_detail = []
95+ for bridge in results.keys():
96+ if len(results[bridge].keys()) > 0:
97+ msg_detail.append(bridge + ": " + str(results[bridge]))
98+ nagios_ok = False
99+
100+ if nagios_ok:
101+ print("OK: Tenant MTU configuration is acceptable")
102+ else:
103+ msg = "WARNING: found tenant MTUs greater than bridge MTU, {}".format(
104+ "; ".join(msg_detail)
105+ )
106+ raise WarnError(msg)
107+
108+
109+def parse_args():
110+ parser = argparse.ArgumentParser(description="Check MTU on bridge devices")
111+ parser.add_argument("br", nargs="*", help="space separated list of bridges")
112+ args = parser.parse_args()
113+ return args
114+
115+
116+def main():
117+ """Nagios plugin to check MTUs in OVS bridges."""
118+ args = parse_args()
119+
120+ if len(args.br) < 1:
121+ raise UnknownError("UNKNOWN: No bridges provided for MTU check?")
122+
123+ try_check(iterate_bridges, args.br)
124+
125+
126+if __name__ == "__main__":
127+ main()

Subscribers

People subscribed via source and target branches