Merge ~xavpaice/charm-nrpe:arp_cache into ~nrpe-charmers/charm-nrpe:master

Proposed by Xav Paice
Status: Merged
Approved by: Xav Paice
Approved revision: d01f831f6ed70fbae4b8e1e89ad5a7b63bce1477
Merged at revision: aa6722df08b2d6333f829f24fe388882beb0b61f
Proposed branch: ~xavpaice/charm-nrpe:arp_cache
Merge into: ~nrpe-charmers/charm-nrpe:master
Diff against target: 119 lines (+86/-0)
3 files modified
.gitignore (+1/-0)
files/plugins/check_arp_cache.py (+75/-0)
hooks/nrpe_helpers.py (+10/-0)
Reviewer Review Type Date Requested Status
Joel Sing (community) +1 Approve
James Hebden (community) Approve
Alvaro Uria Pending
Review via email: mp+364280@code.launchpad.net

This proposal supersedes a proposal from 2019-03-11.

Commit message

Add check_arp_cache

To post a comment you must log in.
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
Alvaro Uria (aluria) wrote : Posted in a previous version of this proposal

Please find comments inline.

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

Thanks for the review - I've updated the change based on those comments, and added a couple of notes inline.

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 :

LGTM

review: Approve
Revision history for this message
Joel Sing (jsing) wrote :

LGTM for standards/readability, however please see comments inline.

It would also be good to see test coverage for at least the new code/script being added.

review: Approve (+1)
Revision history for this message
Xav Paice (xavpaice) wrote :

Thanks Joel, changes made as suggested. We need to get unit test coverage of the entire charm, which should be a separate change. Will raise a bug for this to ensure it's not forgotten.

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

Change successfully merged at revision aa6722df08b2d6333f829f24fe388882beb0b61f

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/.gitignore b/.gitignore
index 631fcbc..4dcb392 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
1*~1*~
2.idea
2*.pyc3*.pyc
3__pycache__/4__pycache__/
4.venv/5.venv/
diff --git a/files/plugins/check_arp_cache.py b/files/plugins/check_arp_cache.py
5new file mode 1007556new file mode 100755
index 0000000..4557c89
--- /dev/null
+++ b/files/plugins/check_arp_cache.py
@@ -0,0 +1,75 @@
1#!/usr/bin/env python3
2# -*- coding: us-ascii -*-
3
4# Copyright (C) 2019 Canonical
5# All rights reserved
6
7import argparse
8import os
9
10from nagios_plugin3 import (
11 CriticalError,
12 WarnError,
13 UnknownError,
14 try_check,
15)
16
17
18def check_arp_cache(warn, crit):
19 """Checks the usage of arp cache against gc_thresh.
20
21 Alerts when the number of arp entries exceeds a threshold of gc_thresh3.
22 See https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt for
23 full details.
24
25 :param warn: integer, % level of hard limit at which to raise Warning
26 :param crit: integer, % level of hard limit at which to raise Critical
27 """
28
29 ARP_TABLE_ENTRIES = '/proc/net/arp'
30 GC_THRESH_LOCATION = '/proc/sys/net/ipv4/neigh/default/gc_thresh3'
31
32 if not os.path.exists(ARP_TABLE_ENTRIES):
33 raise UnknownError("No arp table found!")
34 if not os.path.exists(GC_THRESH_LOCATION):
35 raise UnknownError("sysctl entry net.ipv4.neigh.default.gc_thresh3 not found!")
36
37 with open(GC_THRESH_LOCATION) as fd:
38 gc_thresh3 = int(fd.read())
39
40 with open(ARP_TABLE_ENTRIES) as fd:
41 arp_cache = fd.read().count('\n') - 1 # remove header
42 extra_info = "arp cache entries: {}".format(arp_cache)
43
44 warn_threshold = gc_thresh3 * warn / 100
45 crit_threshold = gc_thresh3 * crit / 100
46
47 if arp_cache >= crit_threshold:
48 message = "CRITICAL: arp cache is more than {} of limit, {}".format(crit, extra_info)
49 raise CriticalError(message)
50 if arp_cache >= warn_threshold:
51 message = "WARNING: arp cache is more than {} of limit, {}".format(warn, extra_info)
52 raise WarnError(message)
53
54 print('OK: arp cache is healthy: {}'.format(extra_info))
55
56
57def parse_args():
58 parser = argparse.ArgumentParser(description='Check bond status')
59 parser.add_argument('--warn', '-w', type=int,
60 help='% of gc_thresh3 to exceed for warning',
61 default=60)
62 parser.add_argument('--crit', '-c', type=int,
63 help='% of gc_thresh3 to exceed for critical',
64 default=80)
65 args = parser.parse_args()
66 return args
67
68
69def main():
70 args = parse_args()
71 try_check(check_arp_cache, args.warn, args.crit)
72
73
74if __name__ == '__main__':
75 main()
diff --git a/hooks/nrpe_helpers.py b/hooks/nrpe_helpers.py
index 32dfc4f..c3adc6e 100644
--- a/hooks/nrpe_helpers.py
+++ b/hooks/nrpe_helpers.py
@@ -4,6 +4,7 @@ import socket
4import subprocess4import subprocess
5import yaml5import yaml
66
7from charmhelpers.core.host import is_container
7from charmhelpers.core.services import helpers8from charmhelpers.core.services import helpers
8from charmhelpers.core import hookenv9from charmhelpers.core import hookenv
910
@@ -413,6 +414,15 @@ class SubordinateCheckDefinitions(dict):
413 },414 },
414 ]415 ]
415416
417 if not is_container():
418 arp_check = {
419 'description': 'ARP cache entries',
420 'cmd_name': 'check_arp_cache',
421 'cmd_exec': os.path.join(local_plugin_dir, 'check_arp_cache.py'),
422 'cmd_params': '-w 60 -c 80', # Specify params here to enable the check, not required otherwise.
423 }
424 checks.append(arp_check)
425
416 if hookenv.config('lacp_bonds').strip():426 if hookenv.config('lacp_bonds').strip():
417 for bond_iface in hookenv.config('lacp_bonds').strip().split():427 for bond_iface in hookenv.config('lacp_bonds').strip().split():
418 if os.path.exists('/sys/class/net/{}'.format(bond_iface)):428 if os.path.exists('/sys/class/net/{}'.format(bond_iface)):

Subscribers

People subscribed via source and target branches