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
1diff --git a/.gitignore b/.gitignore
2index 631fcbc..4dcb392 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1,4 +1,5 @@
6 *~
7+.idea
8 *.pyc
9 __pycache__/
10 .venv/
11diff --git a/files/plugins/check_arp_cache.py b/files/plugins/check_arp_cache.py
12new file mode 100755
13index 0000000..4557c89
14--- /dev/null
15+++ b/files/plugins/check_arp_cache.py
16@@ -0,0 +1,75 @@
17+#!/usr/bin/env python3
18+# -*- coding: us-ascii -*-
19+
20+# Copyright (C) 2019 Canonical
21+# All rights reserved
22+
23+import argparse
24+import os
25+
26+from nagios_plugin3 import (
27+ CriticalError,
28+ WarnError,
29+ UnknownError,
30+ try_check,
31+)
32+
33+
34+def check_arp_cache(warn, crit):
35+ """Checks the usage of arp cache against gc_thresh.
36+
37+ Alerts when the number of arp entries exceeds a threshold of gc_thresh3.
38+ See https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt for
39+ full details.
40+
41+ :param warn: integer, % level of hard limit at which to raise Warning
42+ :param crit: integer, % level of hard limit at which to raise Critical
43+ """
44+
45+ ARP_TABLE_ENTRIES = '/proc/net/arp'
46+ GC_THRESH_LOCATION = '/proc/sys/net/ipv4/neigh/default/gc_thresh3'
47+
48+ if not os.path.exists(ARP_TABLE_ENTRIES):
49+ raise UnknownError("No arp table found!")
50+ if not os.path.exists(GC_THRESH_LOCATION):
51+ raise UnknownError("sysctl entry net.ipv4.neigh.default.gc_thresh3 not found!")
52+
53+ with open(GC_THRESH_LOCATION) as fd:
54+ gc_thresh3 = int(fd.read())
55+
56+ with open(ARP_TABLE_ENTRIES) as fd:
57+ arp_cache = fd.read().count('\n') - 1 # remove header
58+ extra_info = "arp cache entries: {}".format(arp_cache)
59+
60+ warn_threshold = gc_thresh3 * warn / 100
61+ crit_threshold = gc_thresh3 * crit / 100
62+
63+ if arp_cache >= crit_threshold:
64+ message = "CRITICAL: arp cache is more than {} of limit, {}".format(crit, extra_info)
65+ raise CriticalError(message)
66+ if arp_cache >= warn_threshold:
67+ message = "WARNING: arp cache is more than {} of limit, {}".format(warn, extra_info)
68+ raise WarnError(message)
69+
70+ print('OK: arp cache is healthy: {}'.format(extra_info))
71+
72+
73+def parse_args():
74+ parser = argparse.ArgumentParser(description='Check bond status')
75+ parser.add_argument('--warn', '-w', type=int,
76+ help='% of gc_thresh3 to exceed for warning',
77+ default=60)
78+ parser.add_argument('--crit', '-c', type=int,
79+ help='% of gc_thresh3 to exceed for critical',
80+ default=80)
81+ args = parser.parse_args()
82+ return args
83+
84+
85+def main():
86+ args = parse_args()
87+ try_check(check_arp_cache, args.warn, args.crit)
88+
89+
90+if __name__ == '__main__':
91+ main()
92diff --git a/hooks/nrpe_helpers.py b/hooks/nrpe_helpers.py
93index 32dfc4f..c3adc6e 100644
94--- a/hooks/nrpe_helpers.py
95+++ b/hooks/nrpe_helpers.py
96@@ -4,6 +4,7 @@ import socket
97 import subprocess
98 import yaml
99
100+from charmhelpers.core.host import is_container
101 from charmhelpers.core.services import helpers
102 from charmhelpers.core import hookenv
103
104@@ -413,6 +414,15 @@ class SubordinateCheckDefinitions(dict):
105 },
106 ]
107
108+ if not is_container():
109+ arp_check = {
110+ 'description': 'ARP cache entries',
111+ 'cmd_name': 'check_arp_cache',
112+ 'cmd_exec': os.path.join(local_plugin_dir, 'check_arp_cache.py'),
113+ 'cmd_params': '-w 60 -c 80', # Specify params here to enable the check, not required otherwise.
114+ }
115+ checks.append(arp_check)
116+
117 if hookenv.config('lacp_bonds').strip():
118 for bond_iface in hookenv.config('lacp_bonds').strip().split():
119 if os.path.exists('/sys/class/net/{}'.format(bond_iface)):

Subscribers

People subscribed via source and target branches