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

Proposed by Xav Paice
Status: Superseded
Proposed branch: ~xavpaice/charm-nrpe:arp_cache
Merge into: ~nrpe-charmers/charm-nrpe:master
Diff against target: 116 lines (+84/-0)
3 files modified
.gitignore (+1/-0)
files/plugins/check_arp_cache.py (+73/-0)
hooks/nrpe_helpers.py (+10/-0)
Reviewer Review Type Date Requested Status
Alvaro Uria (community) Needs Fixing
James Hebden Pending
Review via email: mp+364239@code.launchpad.net

This proposal has been superseded by 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 :

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

Revision history for this message
Alvaro Uria (aluria) wrote :

Please find comments inline.

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

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

Unmerged commits

cb8c792... by Xav Paice

Add check_arp_cache

Adds a new default check for non-container units that compares the
number of arp entries against the kernel limits configured, and alerts
if >80%.

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

Subscribers

People subscribed via source and target branches