Merge lp:~brad-marshall/charms/trusty/nrpe-external-master/fix-rsyncd-conf into lp:charms/nrpe-external-master

Proposed by Brad Marshall
Status: Merged
Approved by: Brad Marshall
Approved revision: 38
Merged at revision: 37
Proposed branch: lp:~brad-marshall/charms/trusty/nrpe-external-master/fix-rsyncd-conf
Merge into: lp:charms/nrpe-external-master
Diff against target: 442 lines (+342/-35)
8 files modified
files/check_exit_status.pl (+189/-0)
files/check_status_file.py (+60/-0)
files/check_upstart_job (+72/-0)
files/nagios_plugin.py (+0/-4)
files/rsyncd.conf (+12/-0)
hooks/config-changed (+2/-11)
hooks/install (+7/-11)
templates/rsyncd.conf.tmpl (+0/-9)
To merge this branch: bzr merge lp:~brad-marshall/charms/trusty/nrpe-external-master/fix-rsyncd-conf
Reviewer Review Type Date Requested Status
Review Queue (community) automated testing Needs Fixing
JuanJo Ciarlante (community) Approve
Review via email: mp+241922@code.launchpad.net

This proposal supersedes a proposal from 2014-11-12.

Description of the change

Add support for a /etc/rsync-juju.d file, to allow charms to drop fragments in place. Required for the swift charm to have a working rsync.

To post a comment you must log in.
Revision history for this message
JuanJo Ciarlante (jjo) wrote : Posted in a previous version of this proposal

See inline comments, LGTM afterwards.

review: Needs Fixing
37. By Brad Marshall

[bradm] Removed puppet header from nagios_plugin module

Revision history for this message
JuanJo Ciarlante (jjo) wrote :

LGTM, thanks for fixing this.

review: Approve
38. By Brad Marshall

[bradm] Added nagios checks for monitoring upstart and sysvinit daemons

Revision history for this message
Review Queue (review-queue) wrote :

This items has failed automated testing! Results available here http://reports.vapour.ws/charm-tests/charm-bundle-test-10338-results

review: Needs Fixing (automated testing)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'files/check_exit_status.pl'
2--- files/check_exit_status.pl 1970-01-01 00:00:00 +0000
3+++ files/check_exit_status.pl 2014-11-18 01:24:18 +0000
4@@ -0,0 +1,189 @@
5+#!/usr/bin/perl
6+################################################################################
7+# #
8+# Copyright (C) 2011 Chad Columbus <ccolumbu@hotmail.com> #
9+# #
10+# This program is free software; you can redistribute it and/or modify #
11+# it under the terms of the GNU General Public License as published by #
12+# the Free Software Foundation; either version 2 of the License, or #
13+# (at your option) any later version. #
14+# #
15+# This program is distributed in the hope that it will be useful, #
16+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
17+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18+# GNU General Public License for more details. #
19+# #
20+# You should have received a copy of the GNU General Public License #
21+# along with this program; if not, write to the Free Software #
22+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
23+# #
24+################################################################################
25+
26+use strict;
27+use Getopt::Std;
28+$| = 1;
29+
30+my %opts;
31+getopts('heronp:s:', \%opts);
32+
33+my $VERSION = "Version 1.0";
34+my $AUTHOR = '(c) 2011 Chad Columbus <ccolumbu@hotmail.com>';
35+
36+# Default values:
37+my $script_to_check;
38+my $pattern = 'is running';
39+my $cmd;
40+my $message;
41+my $error;
42+
43+# Exit codes
44+my $STATE_OK = 0;
45+my $STATE_WARNING = 1;
46+my $STATE_CRITICAL = 2;
47+my $STATE_UNKNOWN = 3;
48+
49+# Parse command line options
50+if ($opts{'h'} || scalar(%opts) == 0) {
51+ &print_help();
52+ exit($STATE_OK);
53+}
54+
55+# Make sure scipt is provided:
56+if ($opts{'s'} eq '') {
57+ # Script to run not provided
58+ print "\nYou must provide a script to run. Example: -s /etc/init.d/httpd\n";
59+ exit($STATE_UNKNOWN);
60+} else {
61+ $script_to_check = $opts{'s'};
62+}
63+
64+# Make sure only a-z, 0-9, /, _, and - are used in the script.
65+if ($script_to_check =~ /[^a-z0-9\_\-\/\.]/) {
66+ # Script contains illegal characters exit.
67+ print "\nScript to check can only contain Letters, Numbers, Periods, Underscores, Hyphens, and/or Slashes\n";
68+ exit($STATE_UNKNOWN);
69+}
70+
71+# See if script is executable
72+if (! -x "$script_to_check") {
73+ print "\nIt appears you can't execute $script_to_check, $!\n";
74+ exit($STATE_UNKNOWN);
75+}
76+
77+# If a pattern is provided use it:
78+if ($opts{'p'} ne '') {
79+ $pattern = $opts{'p'};
80+}
81+
82+# If -r run command via sudo as root:
83+if ($opts{'r'}) {
84+ $cmd = "sudo -n $script_to_check status" . ' 2>&1';
85+} else {
86+ $cmd = "$script_to_check status" . ' 2>&1';
87+}
88+
89+my $cmd_result = `$cmd`;
90+chomp($cmd_result);
91+if ($cmd_result =~ /sudo/i) {
92+ # This means it could not run the sudo command
93+ $message = "$script_to_check CRITICAL - Could not run: 'sudo -n $script_to_check status'. Result is $cmd_result";
94+ $error = $STATE_UNKNOWN;
95+} else {
96+ # Check exitstatus instead of output:
97+ if ($opts{'e'} == 1) {
98+ if ($? != 0) {
99+ # error
100+ $message = "$script_to_check CRITICAL - Exit code: $?\.";
101+ if ($opts{'o'} == 0) {
102+ $message .= " $cmd_result";
103+ }
104+ $error = $STATE_CRITICAL;
105+ } else {
106+ # success
107+ $message = "$script_to_check OK - Exit code: $?\.";
108+ if ($opts{'o'} == 0) {
109+ $message .= " $cmd_result";
110+ }
111+ $error = $STATE_OK;
112+ }
113+ } else {
114+ my $not_check = 1;
115+ if ($opts{'n'} == 1) {
116+ $not_check = 0;
117+ }
118+ if (($cmd_result =~ /$pattern/i) == $not_check) {
119+ $message = "$script_to_check OK";
120+ if ($opts{'o'} == 0) {
121+ $message .= " - $cmd_result";
122+ }
123+ $error = $STATE_OK;
124+ } else {
125+ $message = "$script_to_check CRITICAL";
126+ if ($opts{'o'} == 0) {
127+ $message .= " - $cmd_result";
128+ }
129+ $error = $STATE_CRITICAL;
130+ }
131+ }
132+}
133+
134+if ($message eq '') {
135+ print "Error: program failed in an unknown way\n";
136+ exit($STATE_UNKNOWN);
137+}
138+
139+if ($error) {
140+ print "$message\n";
141+ exit($error);
142+} else {
143+ # If we get here we are OK
144+ print "$message\n";
145+ exit($STATE_OK);
146+}
147+
148+####################################
149+# Start Subs:
150+####################################
151+sub print_help() {
152+ print << "EOF";
153+Check the output or exit status of a script.
154+$VERSION
155+$AUTHOR
156+
157+Options:
158+-h
159+ Print detailed help screen
160+
161+-s
162+ 'FULL PATH TO SCRIPT' (required)
163+ This is the script to run, the script is designed to run scripts in the
164+ /etc/init.d dir (but can run any script) and will call the script with
165+ a 'status' argument. So if you use another script make sure it will
166+ work with /path/script status, example: /etc/init.d/httpd status
167+
168+-e
169+ This is the "exitstaus" flag, it means check the exit status
170+ code instead of looking for a pattern in the output of the script.
171+
172+-p 'REGEX'
173+ This is a pattern to look for in the output of the script to confirm it
174+ is running, default is 'is running', but not all init.d scripts output
175+ (iptables), so you can specify an arbitrary pattern.
176+ All patterns are case insensitive.
177+
178+-n
179+ This is the "NOT" flag, it means not the -p pattern, so if you want to
180+ make sure the output of the script does NOT contain -p 'REGEX'
181+
182+-r
183+ This is the "ROOT" flag, it means run as root via sudo. You will need a
184+ line in your /etc/sudoers file like:
185+ nagios ALL=(root) NOPASSWD: /etc/init.d/* status
186+
187+-o
188+ This is the "SUPPRESS OUTPUT" flag. Some programs have a long output
189+ (like iptables), this flag suppresses that output so it is not printed
190+ as a part of the nagios message.
191+EOF
192+}
193+
194
195=== added file 'files/check_status_file.py'
196--- files/check_status_file.py 1970-01-01 00:00:00 +0000
197+++ files/check_status_file.py 2014-11-18 01:24:18 +0000
198@@ -0,0 +1,60 @@
199+#!/usr/bin/python
200+
201+# m
202+# mmmm m m mmmm mmmm mmm mm#mm
203+# #" "# # # #" "# #" "# #" # #
204+# # # # # # # # # #"""" #
205+# ##m#" "mm"# ##m#" ##m#" "#mm" "mm
206+# # # #
207+# " " "
208+# This file is managed by puppet. Do not make local changes.
209+
210+#
211+# Copyright 2014 Canonical Ltd.
212+#
213+# Author: Jacek Nykis <jacek.nykis@canonical.com>
214+#
215+
216+import re
217+import nagios_plugin
218+
219+
220+def parse_args():
221+ import argparse
222+
223+ parser = argparse.ArgumentParser(
224+ description='Read file and return nagios status based on its content',
225+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
226+ parser.add_argument('-f', '--status-file', required=True,
227+ help='Status file path')
228+ parser.add_argument('-c', '--critical-text', default='CRITICAL',
229+ help='String indicating critical status')
230+ parser.add_argument('-w', '--warning-text', default='WARNING',
231+ help='String indicating warning status')
232+ parser.add_argument('-o', '--ok-text', default='OK',
233+ help='String indicating OK status')
234+ parser.add_argument('-u', '--unknown-text', default='UNKNOWN',
235+ help='String indicating unknown status')
236+ return parser.parse_args()
237+
238+
239+def check_status(args):
240+ nagios_plugin.check_file_freshness(args.status_file, 43200)
241+
242+ with open(args.status_file, "r") as f:
243+ content = [l.strip() for l in f.readlines()]
244+
245+ for line in content:
246+ if re.search(args.critical_text, line):
247+ raise nagios_plugin.CriticalError(line)
248+ elif re.search(args.warning_text, line):
249+ raise nagios_plugin.WarnError(line)
250+ elif re.search(args.unknown_text, line):
251+ raise nagios_plugin.UnknownError(line)
252+ else:
253+ print line
254+
255+
256+if __name__ == '__main__':
257+ args = parse_args()
258+ nagios_plugin.try_check(check_status, args)
259
260=== added file 'files/check_upstart_job'
261--- files/check_upstart_job 1970-01-01 00:00:00 +0000
262+++ files/check_upstart_job 2014-11-18 01:24:18 +0000
263@@ -0,0 +1,72 @@
264+#!/usr/bin/python
265+
266+#
267+# Copyright 2012, 2013 Canonical Ltd.
268+#
269+# Author: Paul Collins <paul.collins@canonical.com>
270+#
271+# Based on http://www.eurion.net/python-snippets/snippet/Upstart%20service%20status.html
272+#
273+
274+import sys
275+
276+import dbus
277+
278+
279+class Upstart(object):
280+ def __init__(self):
281+ self._bus = dbus.SystemBus()
282+ self._upstart = self._bus.get_object('com.ubuntu.Upstart',
283+ '/com/ubuntu/Upstart')
284+ def get_job(self, job_name):
285+ path = self._upstart.GetJobByName(job_name,
286+ dbus_interface='com.ubuntu.Upstart0_6')
287+ return self._bus.get_object('com.ubuntu.Upstart', path)
288+
289+ def get_properties(self, job):
290+ path = job.GetInstance([], dbus_interface='com.ubuntu.Upstart0_6.Job')
291+ instance = self._bus.get_object('com.ubuntu.Upstart', path)
292+ return instance.GetAll('com.ubuntu.Upstart0_6.Instance',
293+ dbus_interface=dbus.PROPERTIES_IFACE)
294+
295+ def get_job_instances(self, job_name):
296+ job = self.get_job(job_name)
297+ paths = job.GetAllInstances([], dbus_interface='com.ubuntu.Upstart0_6.Job')
298+ return [self._bus.get_object('com.ubuntu.Upstart', path) for path in paths]
299+
300+ def get_job_instance_properties(self, job):
301+ return job.GetAll('com.ubuntu.Upstart0_6.Instance',
302+ dbus_interface=dbus.PROPERTIES_IFACE)
303+
304+try:
305+ upstart = Upstart()
306+ try:
307+ job = upstart.get_job(sys.argv[1])
308+ props = upstart.get_properties(job)
309+
310+ if props['state'] == 'running':
311+ print 'OK: %s is running' % sys.argv[1]
312+ sys.exit(0)
313+ else:
314+ print 'CRITICAL: %s is not running' % sys.argv[1]
315+ sys.exit(2)
316+
317+ except dbus.DBusException as e:
318+ instances = upstart.get_job_instances(sys.argv[1])
319+ propses = [upstart.get_job_instance_properties(instance) for instance in instances]
320+ states = dict([(props['name'], props['state']) for props in propses])
321+ if len(states) != states.values().count('running'):
322+ not_running = []
323+ for name in states.keys():
324+ if states[name] != 'running':
325+ not_running.append(name)
326+ print 'CRITICAL: %d instances of %s not running: %s' % \
327+ (len(not_running), sys.argv[1], not_running.join(', '))
328+ sys.exit(2)
329+ else:
330+ print 'OK: %d instances of %s running' % (len(states), sys.argv[1])
331+
332+except dbus.DBusException as e:
333+ print 'CRITICAL: failed to get properties of \'%s\' from upstart' % sys.argv[1]
334+ sys.exit(2)
335+
336
337=== modified file 'files/nagios_plugin.py'
338--- files/nagios_plugin.py 2013-04-17 17:07:15 +0000
339+++ files/nagios_plugin.py 2014-11-18 01:24:18 +0000
340@@ -1,9 +1,5 @@
341 #!/usr/bin/env python
342
343-#------------------------------------------------------------
344-# This file is managed by Juju. Do not make local changes.
345-#------------------------------------------------------------
346-
347 # Copyright (C) 2005, 2006, 2007, 2012 James Troup <james.troup@canonical.com>
348
349 import os
350
351=== added file 'files/rsyncd.conf'
352--- files/rsyncd.conf 1970-01-01 00:00:00 +0000
353+++ files/rsyncd.conf 2014-11-18 01:24:18 +0000
354@@ -0,0 +1,12 @@
355+#------------------------------------------------
356+# This file is juju managed
357+#------------------------------------------------
358+
359+uid = nobody
360+gid = nogroup
361+pid file = /var/run/rsyncd.pid
362+syslog facility = daemon
363+socket options = SO_KEEPALIVE
364+timeout = 7200
365+
366+&include /etc/rsync-juju.d
367
368=== modified file 'hooks/config-changed'
369--- hooks/config-changed 2014-10-08 05:42:32 +0000
370+++ hooks/config-changed 2014-11-18 01:24:18 +0000
371@@ -26,18 +26,9 @@
372 export NAGIOS_ADDRESS_TYPE=$(config-get nagios_address_type)
373 cheetah fill --env --oext compiled templates/nrpe.cfg.tmpl
374 cp templates/nrpe.cfg.compiled /etc/nagios/nrpe.cfg
375-if [[ -d /etc/rsyncd.d ]]; then
376- export RSYNC_MODULE_ONLY=1
377-else
378- export RSYNC_MODULE_ONLY=0
379-fi
380 cheetah fill --env --oext compiled templates/rsyncd.conf.tmpl
381-if [[ -d /etc/rsyncd.d ]]; then
382- cp templates/rsyncd.conf.compiled /etc/rsyncd.d/010-nrpe-external-master
383- concat_rsync_fragments || true
384-else
385- cp templates/rsyncd.conf.compiled /etc/rsyncd.conf
386-fi
387+mkdir -p /etc/rsync-juju.d
388+cp templates/rsyncd.conf.compiled /etc/rsync-juju.d/010-nrpe-external-master.conf
389
390 #-----------------------------------------------------
391 # Standard Checks
392
393=== modified file 'hooks/install'
394--- hooks/install 2014-03-11 13:57:58 +0000
395+++ hooks/install 2014-11-18 01:24:18 +0000
396@@ -14,18 +14,14 @@
397 cp files/nagios_plugin.py /usr/lib/nagios/plugins/nagios_plugin.py
398 ln -fs /usr/lib/nagios/plugins/nagios_plugin.py /usr/local/lib/nagios/plugins/nagios_plugin.py
399
400+cp files/check_* /usr/local/lib/nagios/plugins/
401+
402 cp files/default_rsync /etc/default/rsync
403-if [[ -d /etc/rsyncd.d ]]; then
404- export RSYNC_MODULE_ONLY=1
405-else
406- export RSYNC_MODULE_ONLY=0
407-fi
408+cp files/rsyncd.conf /etc/rsyncd.conf
409+
410 export NAGIOS_MASTER=$(config-get nagios_master)
411 cheetah fill --env --oext compiled templates/rsyncd.conf.tmpl
412-if [[ -d /etc/rsyncd.d ]]; then
413- cp templates/rsyncd.conf.compiled /etc/rsyncd.d/010-nrpe-external-master
414- concat_rsync_fragments || true
415-else
416- cp templates/rsyncd.conf.compiled /etc/rsyncd.conf
417-fi
418+mkdir -p /etc/rsync-juju.d
419+cp templates/rsyncd.conf.compiled /etc/rsync-juju.d/010-nrpe-external-master
420+
421 service rsync restart
422
423=== modified file 'templates/rsyncd.conf.tmpl'
424--- templates/rsyncd.conf.tmpl 2012-11-26 04:27:06 +0000
425+++ templates/rsyncd.conf.tmpl 2014-11-18 01:24:18 +0000
426@@ -1,16 +1,7 @@
427-#if $RSYNC_MODULE_ONLY == "0"
428 #------------------------------------------------------------
429 # This file is managed by Juju.
430 #------------------------------------------------------------
431
432-uid = nobody
433-gid = nogroup
434-max connections = 25
435-syslog facility = daemon
436-socket options = SO_KEEPALIVE
437-timeout = 7200
438-#end if
439-
440 [external-nagios]
441 path = /var/lib/nagios/export/
442 comment = External Nagios Node configs

Subscribers

People subscribed via source and target branches

to all changes: