Merge lp:~mthaddon/charms/precise/memcached/basenode-and-nrpe-external into lp:charms/memcached

Proposed by Tom Haddon
Status: Merged
Merged at revision: 52
Proposed branch: lp:~mthaddon/charms/precise/memcached/basenode-and-nrpe-external
Merge into: lp:charms/memcached
Diff against target: 183 lines (+132/-1)
7 files modified
config.yaml (+10/-0)
files/nrpe-external-master/check_memcache.py (+74/-0)
hooks/install (+12/-1)
hooks/nrpe-external-master-relation-changed (+19/-0)
metadata.yaml (+3/-0)
templates/nrpe_check_memcached.cfg.tmpl (+4/-0)
templates/nrpe_export.cfg.tmpl (+10/-0)
To merge this branch: bzr merge lp:~mthaddon/charms/precise/memcached/basenode-and-nrpe-external
Reviewer Review Type Date Requested Status
Matthew Wedgwood (community) Approve
Tom Haddon (community) Needs Fixing
Review via email: mp+156609@code.launchpad.net

Description of the change

This adds support for pre-install hook structure, as supported in a number of other charms, which allows you to do things like set timezone, install custom apt repositories, etc.. It also adds support for the nrpe-external-master charm

To post a comment you must log in.
Revision history for this message
Matthew Wedgwood (mew) wrote :

I see the interface for nrpe-external-master in config.yaml, but there's no implementation.

review: Needs Fixing
55. By Tom Haddon

Add in a nagios check when we have a relation with nrpe-external-master

56. By Tom Haddon

Make the nrpe-external-master-relation-changed hook executable

57. By Tom Haddon

We need to export the variables for them to be recognisable to cheetah --env

Revision history for this message
Tom Haddon (mthaddon) wrote :

Ok, I think this should now fix the lack of nagios check on being joined to the nrpe-external-master charm.

Revision history for this message
Matthew Wedgwood (mew) wrote :

Looks like you're still missing a copy of the nrpe check, /usr/lib/nagios/plugins/check_memcache.py

review: Needs Fixing
Revision history for this message
Tom Haddon (mthaddon) wrote :

Still need to actually ship the /usr/lib/nagios/plugins/check_memcache.py file, and probably put it in /usr/local/lib/nagios/plugins so it's clear this is a custom plugin.

review: Needs Fixing
58. By Tom Haddon

Ship the nagios plugin for checking memcache as well

59. By Tom Haddon

We need python-memcache for the nagios check in nrpe-external-master

Revision history for this message
Matthew Wedgwood (mew) wrote :

These changes do the trick.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2012-01-28 01:11:44 +0000
3+++ config.yaml 2013-04-17 17:06:24 +0000
4@@ -78,3 +78,13 @@
5 description: memcached has many other options documented in its man page. You may pass them here as a string which will be appended to memcached's execution.
6 type: string
7 default: ""
8+ nagios_context:
9+ default: "juju"
10+ type: string
11+ description: >
12+ Used by the nrpe-external-master subordinate charm.
13+ A string that will be prepended to instance name to set the host name
14+ in nagios. So for instance the hostname would be something like:
15+ juju-memcached-0
16+ If you're running multiple environments with the same services in them
17+ this allows you to differentiate between them.
18
19=== added directory 'files'
20=== added directory 'files/nrpe-external-master'
21=== added file 'files/nrpe-external-master/check_memcache.py'
22--- files/nrpe-external-master/check_memcache.py 1970-01-01 00:00:00 +0000
23+++ files/nrpe-external-master/check_memcache.py 2013-04-17 17:06:24 +0000
24@@ -0,0 +1,74 @@
25+#!/usr/bin/python
26+
27+#---------------------------------------------------
28+# This file is Juju managed
29+#---------------------------------------------------
30+
31+import memcache
32+import nagios_plugin
33+import sys
34+from optparse import OptionParser
35+
36+
37+def check_version(hosts_ports):
38+ output, errors = [], []
39+ mc = memcache.Client(hosts_ports)
40+ for host in mc.servers:
41+ host.connect()
42+ try:
43+ host.send_cmd("version")
44+ output.append(host.readline())
45+ except:
46+ errors.append(str(host))
47+ if errors:
48+ raise nagios_plugin.CriticalError("Problems with: %s" % ", ".join(errors))
49+ print ", ".join(output)
50+
51+
52+def main():
53+ usage = "%s [-H HOST] [-p PORT] -c check_type\n\n" \
54+ "For options, run '%s --help'" % (sys.argv[0], sys.argv[0])
55+ parser = OptionParser(usage)
56+
57+ parser.add_option(
58+ '-H', '--hosts', type="string", nargs=1,
59+ dest="hosts", help="Comma separated list of hosts to check - defaults to 'localhost'"
60+ )
61+ parser.add_option(
62+ '-p', '--ports', type="string", nargs=1,
63+ dest="ports", help="Comma separated list of ports to check - defaults to 11211"
64+ )
65+ parser.add_option(
66+ '-c', '--check-type', type="string", nargs=1,
67+ dest="check_type", help="The type of check - Mandatory!"
68+ )
69+
70+ (options, args) = parser.parse_args()
71+
72+ if not options.hosts:
73+ options.hosts = 'localhost'
74+ if not options.ports:
75+ options.ports = '11211'
76+
77+ hosts = options.hosts.split(",")
78+ ports = options.ports.split(",")
79+
80+ if len(hosts) != len(ports):
81+ parser.error("You haven't specified the same number of hosts and ports")
82+ else:
83+ hosts_ports = []
84+ for num in range(len(hosts)):
85+ hosts_ports.append('%s:%s' % (hosts[num], ports[num]))
86+
87+ if not options.check_type:
88+ parser.error("You must specify a type of check to perform")
89+ else:
90+ if options.check_type == 'version':
91+ nagios_plugin.try_check(check_version, hosts_ports)
92+ else:
93+ # Add to this list as other check types are implemented
94+ parser.error("Check types currently accepted: version")
95+
96+
97+if __name__ == "__main__":
98+ main()
99
100=== modified file 'hooks/install'
101--- hooks/install 2011-12-05 22:55:46 +0000
102+++ hooks/install 2013-04-17 17:06:24 +0000
103@@ -1,8 +1,19 @@
104 #!/bin/bash
105
106 set -e
107+if [[ -d exec.d ]]; then
108+ shopt -s nullglob
109+ for f in exec.d/*/charm-pre-install; do
110+ [[ -x "$f" ]] || continue
111+ ${SHELL} -c "$f"|| {
112+ ## bail out if anyone fails
113+ juju-log -l ERROR "$f: returned exit_status=$? "
114+ exit 1
115+ }
116+ done
117+fi
118
119-DEBIAN_FRONTEND=noninteractive apt-get -y install -qq memcached
120+DEBIAN_FRONTEND=noninteractive apt-get -y install -qq memcached python-cheetah python-memcache
121
122 cat > /etc/default/memcached <<EOF
123 ENABLE_MEMCACHED=yes
124
125=== added file 'hooks/nrpe-external-master-relation-changed'
126--- hooks/nrpe-external-master-relation-changed 1970-01-01 00:00:00 +0000
127+++ hooks/nrpe-external-master-relation-changed 2013-04-17 17:06:24 +0000
128@@ -0,0 +1,19 @@
129+#!/bin/bash
130+set -eux
131+
132+if [ ! -d /usr/local/lib/nagios/plugins ]; then
133+ mkdir -p /usr/local/lib/nagios/plugins
134+fi
135+if [ ! -f /usr/local/lib/nagios/plugins/check_memcache.py ]; then
136+ cp files/nrpe-external-master/check_memcache.py /usr/local/lib/nagios/plugins/check_memcache.py
137+ chmod 555 /usr/local/lib/nagios/plugins/check_memcache.py
138+fi
139+
140+export NAGIOS_HOSTNAME="$(config-get nagios_context)-${JUJU_UNIT_NAME//\//-}"
141+export NAGIOS_SERVICEGROUP="$(config-get nagios-context)"
142+export TCP_PORT="$(config-get tcp-port)"
143+
144+cheetah fill --env -p templates/nrpe_check_memcached.cfg.tmpl > /etc/nagios/nrpe.d/check_memcached.cfg
145+cheetah fill --env -p templates/nrpe_export.cfg.tmpl > /var/lib/nagios/export/service__${NAGIOS_HOSTNAME}_check_memcached.cfg
146+
147+/etc/init.d/nagios-nrpe-server reload
148
149=== modified file 'metadata.yaml'
150--- metadata.yaml 2012-05-22 22:30:52 +0000
151+++ metadata.yaml 2013-04-17 17:06:24 +0000
152@@ -20,3 +20,6 @@
153 interface: memcache
154 munin:
155 interface: munin-node
156+ nrpe-external-master:
157+ interface: nrpe-external-master
158+ scope: container
159
160=== added directory 'templates'
161=== added file 'templates/nrpe_check_memcached.cfg.tmpl'
162--- templates/nrpe_check_memcached.cfg.tmpl 1970-01-01 00:00:00 +0000
163+++ templates/nrpe_check_memcached.cfg.tmpl 2013-04-17 17:06:24 +0000
164@@ -0,0 +1,4 @@
165+#---------------------------------------------------
166+# This file is Juju managed
167+#---------------------------------------------------
168+command[check_memcached]=/usr/local/lib/nagios/plugins/check_memcache.py -H 127.0.0.1 -p ${TCP_PORT} -c version
169
170=== added file 'templates/nrpe_export.cfg.tmpl'
171--- templates/nrpe_export.cfg.tmpl 1970-01-01 00:00:00 +0000
172+++ templates/nrpe_export.cfg.tmpl 2013-04-17 17:06:24 +0000
173@@ -0,0 +1,10 @@
174+#---------------------------------------------------
175+# This file is Juju managed
176+#---------------------------------------------------
177+define service {
178+ use active-service
179+ host_name ${NAGIOS_HOSTNAME}
180+ service_description ${NAGIOS_HOSTNAME} memcached
181+ check_command check_nrpe!check_memcached
182+ servicegroups ${NAGIOS_SERVICEGROUP},
183+}

Subscribers

People subscribed via source and target branches

to all changes: