Merge lp:~gnuoy/charms/trusty/swift-storage/add-nrpe-checks-fix-rsyncd-conf into lp:~openstack-charmers-archive/charms/trusty/swift-storage/next
- Trusty Tahr (14.04)
- add-nrpe-checks-fix-rsyncd-conf
- Merge into next
Proposed by
Liam Young
Status: | Merged |
---|---|
Merged at revision: | 55 |
Proposed branch: | lp:~gnuoy/charms/trusty/swift-storage/add-nrpe-checks-fix-rsyncd-conf |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/swift-storage/next |
Diff against target: |
451 lines (+160/-69) 10 files modified
hooks/charmhelpers/contrib/charmsupport/nrpe.py (+94/-5) hooks/charmhelpers/contrib/charmsupport/rsync.py (+0/-32) hooks/charmhelpers/contrib/charmsupport/volumes.py (+5/-2) hooks/charmhelpers/contrib/openstack/context.py (+1/-0) hooks/charmhelpers/contrib/openstack/neutron.py (+8/-2) hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg (+2/-0) hooks/charmhelpers/contrib/openstack/utils.py (+6/-0) hooks/charmhelpers/fetch/__init__.py (+8/-1) hooks/swift_storage_hooks.py (+12/-27) hooks/swift_storage_utils.py (+24/-0) |
To merge this branch: | bzr merge lp:~gnuoy/charms/trusty/swift-storage/add-nrpe-checks-fix-rsyncd-conf |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Liam Young (community) | Approve | ||
Review via email: mp+246161@code.launchpad.net |
Commit message
Description of the change
Add nrpe support. Based on branch from bradm with a few tweaks
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #699 swift-storage-next for gnuoy mp246161
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #855 swift-storage-next for gnuoy mp246161
AMULET OK: passed
Revision history for this message
Liam Young (gnuoy) wrote : | # |
<jamespage> gnuoy, as they are re-syncs + tweaks to the nrpe stuff in the charms, I'm happy to give a conditional +1 across the board based on osci checking things out OK
<gnuoy> jamespage, I'll take that! thanks
...
<gnuoy> jamespage, osci is still working through. But on the subject of those mps, does your +1 stand for branches with no amulet tests?
<jamespage> gnuoy, yes
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'hooks/charmhelpers/contrib/charmsupport/nrpe.py' |
2 | --- hooks/charmhelpers/contrib/charmsupport/nrpe.py 2014-10-30 05:52:15 +0000 |
3 | +++ hooks/charmhelpers/contrib/charmsupport/nrpe.py 2015-01-12 14:03:13 +0000 |
4 | @@ -18,6 +18,7 @@ |
5 | log, |
6 | relation_ids, |
7 | relation_set, |
8 | + relations_of_type, |
9 | ) |
10 | |
11 | from charmhelpers.core.host import service |
12 | @@ -54,6 +55,12 @@ |
13 | # juju-myservice-0 |
14 | # If you're running multiple environments with the same services in them |
15 | # this allows you to differentiate between them. |
16 | +# nagios_servicegroups: |
17 | +# default: "" |
18 | +# type: string |
19 | +# description: | |
20 | +# A comma-separated list of nagios servicegroups. |
21 | +# If left empty, the nagios_context will be used as the servicegroup |
22 | # |
23 | # 3. Add custom checks (Nagios plugins) to files/nrpe-external-master |
24 | # |
25 | @@ -138,7 +145,7 @@ |
26 | log('Check command not found: {}'.format(parts[0])) |
27 | return '' |
28 | |
29 | - def write(self, nagios_context, hostname): |
30 | + def write(self, nagios_context, hostname, nagios_servicegroups=None): |
31 | nrpe_check_file = '/etc/nagios/nrpe.d/{}.cfg'.format( |
32 | self.command) |
33 | with open(nrpe_check_file, 'w') as nrpe_check_config: |
34 | @@ -150,16 +157,21 @@ |
35 | log('Not writing service config as {} is not accessible'.format( |
36 | NRPE.nagios_exportdir)) |
37 | else: |
38 | - self.write_service_config(nagios_context, hostname) |
39 | + self.write_service_config(nagios_context, hostname, |
40 | + nagios_servicegroups) |
41 | |
42 | - def write_service_config(self, nagios_context, hostname): |
43 | + def write_service_config(self, nagios_context, hostname, |
44 | + nagios_servicegroups=None): |
45 | for f in os.listdir(NRPE.nagios_exportdir): |
46 | if re.search('.*{}.cfg'.format(self.command), f): |
47 | os.remove(os.path.join(NRPE.nagios_exportdir, f)) |
48 | |
49 | + if not nagios_servicegroups: |
50 | + nagios_servicegroups = nagios_context |
51 | + |
52 | templ_vars = { |
53 | 'nagios_hostname': hostname, |
54 | - 'nagios_servicegroup': nagios_context, |
55 | + 'nagios_servicegroup': nagios_servicegroups, |
56 | 'description': self.description, |
57 | 'shortname': self.shortname, |
58 | 'command': self.command, |
59 | @@ -183,6 +195,10 @@ |
60 | super(NRPE, self).__init__() |
61 | self.config = config() |
62 | self.nagios_context = self.config['nagios_context'] |
63 | + if 'nagios_servicegroups' in self.config: |
64 | + self.nagios_servicegroups = self.config['nagios_servicegroups'] |
65 | + else: |
66 | + self.nagios_servicegroups = 'juju' |
67 | self.unit_name = local_unit().replace('/', '-') |
68 | if hostname: |
69 | self.hostname = hostname |
70 | @@ -208,7 +224,8 @@ |
71 | nrpe_monitors = {} |
72 | monitors = {"monitors": {"remote": {"nrpe": nrpe_monitors}}} |
73 | for nrpecheck in self.checks: |
74 | - nrpecheck.write(self.nagios_context, self.hostname) |
75 | + nrpecheck.write(self.nagios_context, self.hostname, |
76 | + self.nagios_servicegroups) |
77 | nrpe_monitors[nrpecheck.shortname] = { |
78 | "command": nrpecheck.command, |
79 | } |
80 | @@ -217,3 +234,75 @@ |
81 | |
82 | for rid in relation_ids("local-monitors"): |
83 | relation_set(relation_id=rid, monitors=yaml.dump(monitors)) |
84 | + |
85 | + |
86 | +def get_nagios_hostcontext(relation_name='nrpe-external-master'): |
87 | + """ |
88 | + Query relation with nrpe subordinate, return the nagios_host_context |
89 | + |
90 | + :param str relation_name: Name of relation nrpe sub joined to |
91 | + """ |
92 | + for rel in relations_of_type(relation_name): |
93 | + if 'nagios_hostname' in rel: |
94 | + return rel['nagios_host_context'] |
95 | + |
96 | + |
97 | +def get_nagios_hostname(relation_name='nrpe-external-master'): |
98 | + """ |
99 | + Query relation with nrpe subordinate, return the nagios_hostname |
100 | + |
101 | + :param str relation_name: Name of relation nrpe sub joined to |
102 | + """ |
103 | + for rel in relations_of_type(relation_name): |
104 | + if 'nagios_hostname' in rel: |
105 | + return rel['nagios_hostname'] |
106 | + |
107 | + |
108 | +def get_nagios_unit_name(relation_name='nrpe-external-master'): |
109 | + """ |
110 | + Return the nagios unit name prepended with host_context if needed |
111 | + |
112 | + :param str relation_name: Name of relation nrpe sub joined to |
113 | + """ |
114 | + host_context = get_nagios_hostcontext(relation_name) |
115 | + if host_context: |
116 | + unit = "%s:%s" % (host_context, local_unit()) |
117 | + else: |
118 | + unit = local_unit() |
119 | + return unit |
120 | + |
121 | + |
122 | +def add_init_service_checks(nrpe, services, unit_name): |
123 | + """ |
124 | + Add checks for each service in list |
125 | + |
126 | + :param NRPE nrpe: NRPE object to add check to |
127 | + :param list services: List of services to check |
128 | + :param str unit_name: Unit name to use in check description |
129 | + """ |
130 | + for svc in services: |
131 | + upstart_init = '/etc/init/%s.conf' % svc |
132 | + sysv_init = '/etc/init.d/%s' % svc |
133 | + if os.path.exists(upstart_init): |
134 | + nrpe.add_check( |
135 | + shortname=svc, |
136 | + description='process check {%s}' % unit_name, |
137 | + check_cmd='check_upstart_job %s' % svc |
138 | + ) |
139 | + elif os.path.exists(sysv_init): |
140 | + cronpath = '/etc/cron.d/nagios-service-check-%s' % svc |
141 | + cron_file = ('*/5 * * * * root ' |
142 | + '/usr/local/lib/nagios/plugins/check_exit_status.pl ' |
143 | + '-s /etc/init.d/%s status > ' |
144 | + '/var/lib/nagios/service-check-%s.txt\n' % (svc, |
145 | + svc) |
146 | + ) |
147 | + f = open(cronpath, 'w') |
148 | + f.write(cron_file) |
149 | + f.close() |
150 | + nrpe.add_check( |
151 | + shortname=svc, |
152 | + description='process check {%s}' % unit_name, |
153 | + check_cmd='check_status_file.py -f ' |
154 | + '/var/lib/nagios/service-check-%s.txt' % svc, |
155 | + ) |
156 | |
157 | === removed file 'hooks/charmhelpers/contrib/charmsupport/rsync.py' |
158 | --- hooks/charmhelpers/contrib/charmsupport/rsync.py 2014-11-06 07:38:43 +0000 |
159 | +++ hooks/charmhelpers/contrib/charmsupport/rsync.py 1970-01-01 00:00:00 +0000 |
160 | @@ -1,32 +0,0 @@ |
161 | -""" |
162 | -Support for rsyncd.conf and using fragments dropped inside /etc/rsync-juju.d |
163 | -""" |
164 | -import os |
165 | - |
166 | -from charmhelpers.core.host import ( |
167 | - mkdir, |
168 | -) |
169 | - |
170 | -def setup_rsync(): |
171 | - ''' |
172 | - Ensure all directories required for rsync exist with correct permissions. |
173 | - ''' |
174 | - root_dirs = [ |
175 | - '/etc/rsync-juju.d', |
176 | - ] |
177 | - [mkdir(d, owner='root', group='root') for d in root_dirs |
178 | - if not os.path.isdir(d)] |
179 | - |
180 | - rsyncd_base = """uid = nobody |
181 | -gid = nogroup |
182 | -pid file = /var/run/rsyncd.pid |
183 | -syslog facility = daemon |
184 | -socket options = SO_KEEPALIVE |
185 | - |
186 | -&include /etc/rsync-juju.d |
187 | -""" |
188 | - |
189 | - f = open('/etc/rsyncd.conf','w') |
190 | - f.write(rsyncd_base) |
191 | - f.close() |
192 | - |
193 | |
194 | === modified file 'hooks/charmhelpers/contrib/charmsupport/volumes.py' |
195 | --- hooks/charmhelpers/contrib/charmsupport/volumes.py 2014-10-30 05:52:15 +0000 |
196 | +++ hooks/charmhelpers/contrib/charmsupport/volumes.py 2015-01-12 14:03:13 +0000 |
197 | @@ -2,7 +2,8 @@ |
198 | Functions for managing volumes in juju units. One volume is supported per unit. |
199 | Subordinates may have their own storage, provided it is on its own partition. |
200 | |
201 | -Configuration stanzas: |
202 | +Configuration stanzas:: |
203 | + |
204 | volume-ephemeral: |
205 | type: boolean |
206 | default: true |
207 | @@ -20,7 +21,8 @@ |
208 | is 'true' and no volume-map value is set. Use 'juju set' to set a |
209 | value and 'juju resolved' to complete configuration. |
210 | |
211 | -Usage: |
212 | +Usage:: |
213 | + |
214 | from charmsupport.volumes import configure_volume, VolumeConfigurationError |
215 | from charmsupport.hookenv import log, ERROR |
216 | def post_mount_hook(): |
217 | @@ -34,6 +36,7 @@ |
218 | after_change=post_mount_hook) |
219 | except VolumeConfigurationError: |
220 | log('Storage could not be configured', ERROR) |
221 | + |
222 | ''' |
223 | |
224 | # XXX: Known limitations |
225 | |
226 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' |
227 | --- hooks/charmhelpers/contrib/openstack/context.py 2014-12-15 09:35:34 +0000 |
228 | +++ hooks/charmhelpers/contrib/openstack/context.py 2015-01-12 14:03:13 +0000 |
229 | @@ -491,6 +491,7 @@ |
230 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') |
231 | |
232 | if config('prefer-ipv6'): |
233 | + ctxt['ipv6'] = True |
234 | ctxt['local_host'] = 'ip6-localhost' |
235 | ctxt['haproxy_host'] = '::' |
236 | ctxt['stat_port'] = ':::8888' |
237 | |
238 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' |
239 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2014-12-10 20:28:59 +0000 |
240 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2015-01-12 14:03:13 +0000 |
241 | @@ -152,9 +152,15 @@ |
242 | database=config('neutron-database'), |
243 | relation_prefix='neutron', |
244 | ssl_dir=NEUTRON_CONF_DIR)], |
245 | - 'services': ['calico-compute', 'bird', 'neutron-dhcp-agent'], |
246 | + 'services': ['calico-felix', |
247 | + 'bird', |
248 | + 'neutron-dhcp-agent', |
249 | + 'nova-api-metadata'], |
250 | 'packages': [[headers_package()] + determine_dkms_package(), |
251 | - ['calico-compute', 'bird', 'neutron-dhcp-agent']], |
252 | + ['calico-compute', |
253 | + 'bird', |
254 | + 'neutron-dhcp-agent', |
255 | + 'nova-api-metadata']], |
256 | 'server_packages': ['neutron-server', 'calico-control'], |
257 | 'server_services': ['neutron-server'] |
258 | } |
259 | |
260 | === modified file 'hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg' |
261 | --- hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-12-10 20:28:59 +0000 |
262 | +++ hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2015-01-12 14:03:13 +0000 |
263 | @@ -38,7 +38,9 @@ |
264 | {% for service, ports in service_ports.items() -%} |
265 | frontend tcp-in_{{ service }} |
266 | bind *:{{ ports[0] }} |
267 | + {% if ipv6 -%} |
268 | bind :::{{ ports[0] }} |
269 | + {% endif -%} |
270 | {% for frontend in frontends -%} |
271 | acl net_{{ frontend }} dst {{ frontends[frontend]['network'] }} |
272 | use_backend {{ service }}_{{ frontend }} if net_{{ frontend }} |
273 | |
274 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' |
275 | --- hooks/charmhelpers/contrib/openstack/utils.py 2014-12-10 20:28:59 +0000 |
276 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2015-01-12 14:03:13 +0000 |
277 | @@ -53,6 +53,7 @@ |
278 | ('saucy', 'havana'), |
279 | ('trusty', 'icehouse'), |
280 | ('utopic', 'juno'), |
281 | + ('vivid', 'kilo'), |
282 | ]) |
283 | |
284 | |
285 | @@ -64,6 +65,7 @@ |
286 | ('2013.2', 'havana'), |
287 | ('2014.1', 'icehouse'), |
288 | ('2014.2', 'juno'), |
289 | + ('2015.1', 'kilo'), |
290 | ]) |
291 | |
292 | # The ugly duckling |
293 | @@ -84,6 +86,7 @@ |
294 | ('2.0.0', 'juno'), |
295 | ('2.1.0', 'juno'), |
296 | ('2.2.0', 'juno'), |
297 | + ('2.2.1', 'kilo'), |
298 | ]) |
299 | |
300 | DEFAULT_LOOPBACK_SIZE = '5G' |
301 | @@ -289,6 +292,9 @@ |
302 | 'juno': 'trusty-updates/juno', |
303 | 'juno/updates': 'trusty-updates/juno', |
304 | 'juno/proposed': 'trusty-proposed/juno', |
305 | + 'kilo': 'trusty-updates/kilo', |
306 | + 'kilo/updates': 'trusty-updates/kilo', |
307 | + 'kilo/proposed': 'trusty-proposed/kilo', |
308 | } |
309 | |
310 | try: |
311 | |
312 | === modified file 'hooks/charmhelpers/fetch/__init__.py' |
313 | --- hooks/charmhelpers/fetch/__init__.py 2014-12-10 20:28:59 +0000 |
314 | +++ hooks/charmhelpers/fetch/__init__.py 2015-01-12 14:03:13 +0000 |
315 | @@ -64,9 +64,16 @@ |
316 | 'trusty-juno/updates': 'trusty-updates/juno', |
317 | 'trusty-updates/juno': 'trusty-updates/juno', |
318 | 'juno/proposed': 'trusty-proposed/juno', |
319 | - 'juno/proposed': 'trusty-proposed/juno', |
320 | 'trusty-juno/proposed': 'trusty-proposed/juno', |
321 | 'trusty-proposed/juno': 'trusty-proposed/juno', |
322 | + # Kilo |
323 | + 'kilo': 'trusty-updates/kilo', |
324 | + 'trusty-kilo': 'trusty-updates/kilo', |
325 | + 'trusty-kilo/updates': 'trusty-updates/kilo', |
326 | + 'trusty-updates/kilo': 'trusty-updates/kilo', |
327 | + 'kilo/proposed': 'trusty-proposed/kilo', |
328 | + 'trusty-kilo/proposed': 'trusty-proposed/kilo', |
329 | + 'trusty-proposed/kilo': 'trusty-proposed/kilo', |
330 | } |
331 | |
332 | # The order of this list is very important. Handlers should be listed in from |
333 | |
334 | === modified file 'hooks/swift_storage_hooks.py' |
335 | --- hooks/swift_storage_hooks.py 2015-01-09 10:07:27 +0000 |
336 | +++ hooks/swift_storage_hooks.py 2015-01-12 14:03:13 +0000 |
337 | @@ -14,7 +14,8 @@ |
338 | register_configs, |
339 | save_script_rc, |
340 | setup_storage, |
341 | - assert_charm_supports_ipv6 |
342 | + assert_charm_supports_ipv6, |
343 | + setup_rsync, |
344 | ) |
345 | |
346 | from charmhelpers.core.hookenv import ( |
347 | @@ -24,7 +25,6 @@ |
348 | relation_get, |
349 | relation_set, |
350 | relations_of_type, |
351 | - local_unit, |
352 | ) |
353 | |
354 | from charmhelpers.fetch import ( |
355 | @@ -42,9 +42,7 @@ |
356 | from charmhelpers.contrib.network.ip import ( |
357 | get_ipv6_addr |
358 | ) |
359 | -from charmhelpers.contrib.charmsupport.nrpe import NRPE |
360 | - |
361 | -from charmhelpers.contrib.charmsupport.rsync import setup_rsync |
362 | +from charmhelpers.contrib.charmsupport import nrpe |
363 | |
364 | from distutils.dir_util import mkpath |
365 | |
366 | @@ -120,6 +118,8 @@ |
367 | @hooks.hook('nrpe-external-master-relation-joined') |
368 | @hooks.hook('nrpe-external-master-relation-changed') |
369 | def update_nrpe_config(): |
370 | + # python-dbus is used by check_upstart_job |
371 | + apt_install('python-dbus') |
372 | log('Refreshing nrpe checks') |
373 | if not os.path.exists(NAGIOS_PLUGINS): |
374 | mkpath(NAGIOS_PLUGINS) |
375 | @@ -132,37 +132,22 @@ |
376 | rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'sudo', |
377 | 'swift-storage'), |
378 | os.path.join(SUDOERS_D, 'swift-storage')) |
379 | + |
380 | # Find out if nrpe set nagios_hostname |
381 | - hostname = None |
382 | - host_context = None |
383 | - for rel in relations_of_type('nrpe-external-master'): |
384 | - if 'nagios_hostname' in rel: |
385 | - hostname = rel['nagios_hostname'] |
386 | - host_context = rel['nagios_host_context'] |
387 | - break |
388 | - nrpe = NRPE(hostname=hostname) |
389 | - |
390 | - if host_context: |
391 | - current_unit = "%s:%s" % (host_context, local_unit()) |
392 | - else: |
393 | - current_unit = local_unit() |
394 | + hostname = nrpe.get_nagios_hostname() |
395 | + current_unit = nrpe.get_nagios_unit_name() |
396 | + nrpe_setup = nrpe.NRPE(hostname=hostname) |
397 | |
398 | # check the rings and replication |
399 | - nrpe.add_check( |
400 | + nrpe_setup.add_check( |
401 | shortname='swift_storage', |
402 | description='Check swift storage ring hashes and replication' |
403 | ' {%s}' % current_unit, |
404 | check_cmd='check_swift_storage.py {}'.format( |
405 | config('nagios-check-params')) |
406 | ) |
407 | - # check services are running |
408 | - for service in SWIFT_SVCS: |
409 | - nrpe.add_check( |
410 | - shortname=service, |
411 | - description='service {%s}' % current_unit, |
412 | - check_cmd='check_swift_service %s' % service, |
413 | - ) |
414 | - nrpe.write() |
415 | + nrpe.add_init_service_checks(nrpe_setup, SWIFT_SVCS, current_unit) |
416 | + nrpe_setup.write() |
417 | |
418 | |
419 | def main(): |
420 | |
421 | === modified file 'hooks/swift_storage_utils.py' |
422 | --- hooks/swift_storage_utils.py 2015-01-09 10:07:27 +0000 |
423 | +++ hooks/swift_storage_utils.py 2015-01-12 14:03:13 +0000 |
424 | @@ -293,3 +293,27 @@ |
425 | rsyncd_conf += fragment.read() |
426 | with open('/etc/rsyncd.conf', 'w') as f: |
427 | f.write(rsyncd_conf) |
428 | + |
429 | + |
430 | +def setup_rsync(): |
431 | + ''' |
432 | + Ensure all directories required for rsync exist with correct permissions. |
433 | + ''' |
434 | + root_dirs = [ |
435 | + '/etc/rsync-juju.d', |
436 | + ] |
437 | + [mkdir(d, owner='root', group='root') for d in root_dirs |
438 | + if not os.path.isdir(d)] |
439 | + |
440 | + rsyncd_base = """uid = nobody |
441 | +gid = nogroup |
442 | +pid file = /var/run/rsyncd.pid |
443 | +syslog facility = daemon |
444 | +socket options = SO_KEEPALIVE |
445 | + |
446 | +&include /etc/rsync-juju.d |
447 | +""" |
448 | + |
449 | + f = open('/etc/rsyncd.conf', 'w') |
450 | + f.write(rsyncd_base) |
451 | + f.close() |
charm_lint_check #670 swift-storage-next for gnuoy mp246161
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/670/