Merge lp:~ben-kaehne/charms/trusty/nagios-extra-scripts/check_interface into lp:~jillrouleau/charms/trusty/nagios-extra-scripts/refactored-checks

Proposed by Benjamin Kaehne
Status: Needs review
Proposed branch: lp:~ben-kaehne/charms/trusty/nagios-extra-scripts/check_interface
Merge into: lp:~jillrouleau/charms/trusty/nagios-extra-scripts/refactored-checks
Diff against target: 319 lines (+209/-22)
8 files modified
files/cron/checknet-ethtooldata (+1/-0)
files/localbin/cat-check-network (+22/-0)
files/nrpe/interfaces_status.py (+122/-0)
hooks/hooks.py (+19/-9)
hooks/services.py (+12/-8)
metadata.yaml (+5/-5)
templates/interfaces_nagios.cfg.j2 (+22/-0)
templates/interfaces_nrpe.cfg.j2 (+6/-0)
To merge this branch: bzr merge lp:~ben-kaehne/charms/trusty/nagios-extra-scripts/check_interface
Reviewer Review Type Date Requested Status
Jill Rouleau Pending
Review via email: mp+291202@code.launchpad.net

Description of the change

I have added in the "check_interfaces" check.

To post a comment you must log in.
Revision history for this message
Jill Rouleau (jillrouleau) :

Unmerged revisions

19. By Benjamin Kaehne

nagios check to check interfaces now installed into this repo with some code tidy.

Check willd default to 10g links; as per our cloud installs

18. By Benjamin Kaehne

fix

17. By Benjamin Kaehne

Pushing to test in staging. Part 1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'files/cron'
2=== added file 'files/cron/checknet-ethtooldata'
3--- files/cron/checknet-ethtooldata 1970-01-01 00:00:00 +0000
4+++ files/cron/checknet-ethtooldata 2016-04-07 05:19:48 +0000
5@@ -0,0 +1,1 @@
6+23 */3 * * * root /usr/local/sbin/cat-check-network
7
8=== added directory 'files/localbin'
9=== added file 'files/localbin/cat-check-network'
10--- files/localbin/cat-check-network 1970-01-01 00:00:00 +0000
11+++ files/localbin/cat-check-network 2016-04-07 05:19:48 +0000
12@@ -0,0 +1,22 @@
13+#!/bin/sh
14+# m
15+# mmmm m m mmmm mmmm mmm mm#mm
16+# #" "# # # #" "# #" "# #" # #
17+# # # # # # # # # #"""" #
18+# ##m#" "mm"# ##m#" ##m#" "#mm" "mm
19+# # # #
20+# " " "
21+# This file is managed by puppet. Do not make local changes.
22+
23+# cache ethtool results so nagios can check the interfaces.
24+
25+PATH='/sbin:/usr/sbin'
26+
27+# Remove existing files, otherwise nagios alerts on removed network interfaces
28+/bin/rm -f /var/lib/nagios/ethtool.*
29+
30+# most boxes have eth?, arm buildds have usb?. add other funky interface types
31+# as we become aware of them.
32+for dev in $(/sbin/ifconfig -s | /usr/bin/awk '/^p?eth|usb[0-9]+[^:]/ {print $1}'); do
33+ ethtool ${dev} > /var/lib/nagios/ethtool.${dev};
34+done
35
36=== added file 'files/nrpe/interfaces_status.py'
37--- files/nrpe/interfaces_status.py 1970-01-01 00:00:00 +0000
38+++ files/nrpe/interfaces_status.py 2016-04-07 05:19:48 +0000
39@@ -0,0 +1,122 @@
40+#!/usr/bin/env python
41+# m
42+# mmmm m m mmmm mmmm mmm mm#mm
43+# #" "# # # #" "# #" "# #" # #
44+# # # # # # # # # #"""" #
45+# ##m#" "mm"# ##m#" ##m#" "#mm" "mm
46+# # # #
47+# " " "
48+# This file is managed by puppet. Do not make local changes.
49+
50+# Copyright (C) 2009, 2012 James Troup <james.troup@canonical.com>
51+
52+################################################################################
53+
54+import nagios_plugin
55+import glob
56+from optparse import OptionParser
57+
58+
59+###########################################################################
60+
61+def compare_expected(line, expected, type, interface):
62+ expected = expected.strip().lower()
63+ value = line.split(":")[1].strip().lower()
64+ if value != expected:
65+ raise nagios_plugin.CriticalError(
66+ "%s: %s is '%s' not '%s'" % (interface, type, value, expected))
67+
68+
69+################################################################################
70+
71+## Example ethtool output:
72+
73+# Settings for eth0:
74+# Supported ports: [ TP ]
75+# Supported link modes: 10baseT/Half 10baseT/Full
76+# 100baseT/Half 100baseT/Full
77+# 1000baseT/Half 1000baseT/Full
78+# Supports auto-negotiation: Yes
79+# Advertised link modes: 10baseT/Half 10baseT/Full
80+# 100baseT/Half 100baseT/Full
81+# 1000baseT/Half 1000baseT/Full
82+# Advertised auto-negotiation: Yes
83+# Speed: 1000Mb/s
84+# Duplex: Full
85+# Port: Twisted Pair
86+# PHYAD: 1
87+# Transceiver: internal
88+# Auto-negotiation: on
89+# Supports Wake-on: g
90+# Wake-on: g
91+# Current message level: 0x000000ff (255)
92+# Link detected: yes
93+
94+def check_interface(filename, interface, expected_speed, half_duplex):
95+ nagios_plugin.check_file_freshness(filename, 2 * 3 * 60 * 60)
96+ input_file = open(filename)
97+ link_status = False
98+ for line in input_file.readlines():
99+ line = line.lstrip()
100+ if line.startswith("Speed: "):
101+ compare_expected(line, expected_speed, "speed", interface)
102+ if line.startswith("Duplex: ") and interface not in half_duplex:
103+ compare_expected(line, "Full", "duplex", interface)
104+ if line.startswith("Link detected: "):
105+ compare_expected(line, "Yes", "link detected", interface)
106+ link_status = True
107+ # We can't error out on lack of speed/duplex as Xen guest or
108+ # bridge interfaces don't have them.
109+
110+ # On the other hand, we can error out if we don't find any 'link
111+ # detected' line. This check should simply be disabled on any
112+ # hardware (e.g. hppa) which is so pre-historic it doesn't even
113+ # support ethtool.
114+ if not link_status:
115+ raise nagios_plugin.CriticalError(
116+ "%s: did not find link detected information" % (interface))
117+
118+
119+################################################################################
120+
121+def main():
122+ parser = OptionParser()
123+ parser.add_option("--speed", dest="expected_speed",
124+ help="expected speed of nics [default=%default]",
125+ default="1000MB/s")
126+ parser.add_option("--eth0", dest="eth0",
127+ help="expected speed of eth0 [default=global]")
128+ parser.add_option("--eth1", dest="eth1",
129+ help="expected speed of eth1 [default=global]")
130+ parser.add_option("--eth2", dest="eth2",
131+ help="expected speed of eth2 [default=global]")
132+ parser.add_option("--half", dest="half_duplex", action="append",
133+ default=[], help="list of interfaces that are "
134+ " expected to be half duplex")
135+ (opts, args) = parser.parse_args()
136+ interfaces = []
137+ etoutputs = glob.glob("/var/lib/nagios/ethtool.*")
138+ # glob can return an empty list if there are no files. check result
139+ # should then be unknown.
140+ if not etoutputs:
141+ raise nagios_plugin.UnknownError("No ethtool output in /var/lib/nagios")
142+ for filename in etoutputs:
143+ # only check non-vlan interfaces
144+ # vlan interfaces have a filename ending in "ethtool.eth2.2590" or such
145+ # while non-vlan will end with "ethtool.eth0"
146+ # Ignore anything with multiple dots in the name, since ethtool
147+ # will simply say it has no info for the vlans
148+ # also ignore aliases on an interface, on the assumption that we
149+ # always have the non-alias interface as well
150+ if filename.count(".") == 1 and filename.count(":") == 0:
151+ interface = filename.split(".")[-1]
152+ expected_speed = opts.__dict__.get(interface, None)
153+ if not expected_speed:
154+ expected_speed = opts.expected_speed
155+ check_interface(filename, interface, expected_speed,
156+ half_duplex=opts.half_duplex)
157+ interfaces.append(interface)
158+ print "All OK on: %s" % (", ".join(interfaces))
159+
160+if __name__ == "__main__":
161+ nagios_plugin.try_check(main)
162
163=== modified file 'hooks/hooks.py'
164--- hooks/hooks.py 2015-11-24 01:00:30 +0000
165+++ hooks/hooks.py 2016-04-07 05:19:48 +0000
166@@ -14,6 +14,11 @@
167
168 NAGIOS_EXPORT = "/var/lib/nagios/export/"
169 NAGIOS_PLUGINS = '/usr/lib/nagios/plugins/'
170+SCRIPT_DEST = { 'nrpe': NAGIOS_PLUGINS,
171+ 'localbin': '/usr/local/sbin/',
172+ 'cron': '/etc/cron.d/' }
173+
174+
175 hooks = hookenv.Hooks()
176 config = hookenv.config()
177
178@@ -24,13 +29,11 @@
179 ContainerType = "metal"
180
181
182-def install_nrpe_scripts(script):
183- # We want to be able to specify which scripts to copy
184- # Not all scripts in CHARM_DIR/files will go on all units
185- nrpe_files_dir = os.path.join(os.environ["CHARM_DIR"], "files", "nrpe")
186- for fname in glob.glob(os.path.join(nrpe_files_dir, script)):
187+def install_scripts(file, type):
188+ nrpe_files_dir = os.path.join(os.environ["CHARM_DIR"], "files", type)
189+ for fname in glob.glob(os.path.join(nrpe_files_dir, file)):
190 shutil.copy2(fname,
191- os.path.join(NAGIOS_PLUGINS, os.path.basename(fname)))
192+ os.path.join(SCRIPT_DEST[type], os.path.basename(fname)))
193
194
195 @hooks.hook('install', 'start')
196@@ -94,16 +97,23 @@
197
198 # If this is a bare metal host, check conntrack
199 if ContainerType is "lxc":
200- install_nrpe_scripts("conntrack_status.py")
201+ install_scripts('conntrack_status.py', 'nrpe')
202 nrpe_setup.add_check('conntrack_max', 'Check Maximum Conntrack',
203 'conntrack_status.py conntrack_max'),
204 nrpe_setup.add_check('conntrack_used', 'Check Used Conntrack',
205 'conntrack_status.py conntrack_used'),
206
207 # In all cases, check ksplice status.
208- install_nrpe_scripts("ksplice_status.py"),
209+ install_scripts('ksplice_status.py', 'nrpe')
210 nrpe_setup.add_check('ksplice_status', 'Check KSplice Status',
211- 'ksplice_status.py'),
212+ 'ksplice_status.py')
213+
214+ install_scripts('interfaces_status.py', 'nrpe')
215+ install_scripts('cat-check-network', 'localbin')
216+ install_scripts('checknet-ethtooldata', 'cron')
217+
218+ nrpe_setup.add_check('interfaces_status', 'Check Interface',
219+ 'interfaces_status.py')
220
221 nrpe_setup.write()
222
223
224=== modified file 'hooks/services.py'
225--- hooks/services.py 2015-10-10 00:36:15 +0000
226+++ hooks/services.py 2016-04-07 05:19:48 +0000
227@@ -60,11 +60,6 @@
228 ],
229 'data_ready': [
230 helpers.render_template(
231- source='conntrack_status.py',
232- target='/usr/lib/nagios/plugins/conntrack_status.py',
233- perms=0o755
234- ),
235- helpers.render_template(
236 source='conntrack_nrpe.cfg.j2',
237 target='/etc/nagios/nrpe.d/check_conntrack.cfg',
238 perms=0o644
239@@ -79,9 +74,18 @@
240 )
241 ),
242 helpers.render_template(
243- source='ksplice_status.py',
244- target='/usr/lib/nagios/plugins/ksplice_status.py',
245- perms=0o755
246+ source='interfaces_nrpe.cfg.j2',
247+ target='/etc/nagios/nrpe.d/check_interfaces.cfg',
248+ perms=0o644
249+ ),
250+ helpers.render_template(
251+ source='interfaces_nagios.cfg.j2',
252+ target=EXPORTDIR+'service__{}-{}_{}.cfg'.format(
253+ config['nagios_context'],
254+ nagios_helpers.parent_unit,
255+ "interfaces_status",
256+ perms=0o644
257+ )
258 ),
259 helpers.render_template(
260 source='ksplice_nrpe.cfg.j2',
261
262=== modified file 'metadata.yaml'
263--- metadata.yaml 2015-11-23 18:55:44 +0000
264+++ metadata.yaml 2016-04-07 05:19:48 +0000
265@@ -9,11 +9,11 @@
266 - ops
267 subordinate: true
268 requires:
269-# general-info:
270-# interface: juju-info
271-# scope: container
272-#provides:
273-#
274+ general-info:
275+ interface: juju-info
276+ scope: container
277+provides:
278+
279 nrpe-external-master:
280 interface: nrpe-external-master
281 scope: container
282
283=== added file 'templates/interfaces_nagios.cfg.j2'
284--- templates/interfaces_nagios.cfg.j2 1970-01-01 00:00:00 +0000
285+++ templates/interfaces_nagios.cfg.j2 2016-04-07 05:19:48 +0000
286@@ -0,0 +1,22 @@
287+#---------------------------------------------------
288+# This file is Juju managed
289+#---------------------------------------------------
290+#
291+{% macro servicegroup(default='juju') -%}
292+ {%- if config['nagios_servicegroups'] -%}
293+{{ config['nagios_servicegroups'] }}
294+ {%- elif config['nagios_context'] -%}
295+{{ config['nagios_context'] }}
296+ {%- else -%}
297+{{ default }}
298+ {%- endif -%}
299+{%- endmacro %}
300+{% for rel in nrpe_external_master -%}
301+define service {
302+ use active-service
303+ host_name {{ servicegroup() }}-{{ parent_unit }}
304+ service_description {{ servicegroup() }}-{{ parent_unit }}[check_interfaces] Check Network Interfaces
305+ check_command check_nrpe!check_interfaces
306+ servicegroups {{ servicegroup() }}
307+}
308+{%- endfor %}
309
310=== added file 'templates/interfaces_nrpe.cfg.j2'
311--- templates/interfaces_nrpe.cfg.j2 1970-01-01 00:00:00 +0000
312+++ templates/interfaces_nrpe.cfg.j2 2016-04-07 05:19:48 +0000
313@@ -0,0 +1,6 @@
314+#---------------------------------------------------
315+# This file is Juju managed
316+#---------------------------------------------------
317+#
318+# Check interfaces
319+command[check_interfaces]=/usr/lib/nagios/plugins/interfaces_status.py --speed 10000MB/s

Subscribers

People subscribed via source and target branches

to all changes: