Merge lp:~verterok/charms/trusty/tanuki-spec-manager/conn-check-support into lp:~tanuki/charms/trusty/tanuki-spec-manager/trunk

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 25
Merged at revision: 19
Proposed branch: lp:~verterok/charms/trusty/tanuki-spec-manager/conn-check-support
Merge into: lp:~tanuki/charms/trusty/tanuki-spec-manager/trunk
Diff against target: 125 lines (+75/-1)
4 files modified
config.yaml (+4/-0)
hooks/actions.py (+66/-0)
hooks/services.py (+2/-1)
metadata.yaml (+3/-0)
To merge this branch: bzr merge lp:~verterok/charms/trusty/tanuki-spec-manager/conn-check-support
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+267717@code.launchpad.net

Commit message

add initial conn-check support

Description of the change

add initial conn-check support

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

This LGTM - the urlparse stuff is a bit... icky, but I can't think of an easier way to do this.

review: Approve
Revision history for this message
Tanuki Bot (tanuki-bot) wrote :

Attempt to merge into lp:~tanuki/charms/trusty/tanuki-spec-manager/trunk failed due to conflicts:

text conflict in config.yaml

25. By Guillermo Gonzalez

merge trunk

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 2015-08-12 13:14:14 +0000
3+++ config.yaml 2015-08-13 14:17:24 +0000
4@@ -34,3 +34,7 @@
5 description: |
6 A comma-separated list of nagios servicegroups.
7 If left empty, the nagios_context will be used as the servicegroup
8+ conn_check_config:
9+ type: string
10+ default: ""
11+ description: base64 encoded YAML config for conn-check
12
13=== modified file 'hooks/actions.py'
14--- hooks/actions.py 2015-08-11 09:50:16 +0000
15+++ hooks/actions.py 2015-08-13 14:17:24 +0000
16@@ -1,6 +1,7 @@
17 import ConfigParser
18 import base64
19 import os
20+import urlparse
21 import subprocess
22 import yaml
23
24@@ -204,6 +205,71 @@
25 return hookenv.local_unit() in units
26
27
28+class ConnCheckRelation(helpers.RelationContext):
29+
30+ name = 'conn-check'
31+ interface = 'conn-check'
32+ required_keys = []
33+
34+ def provide_data(self):
35+ config = hookenv.config()
36+ conn_check_config = []
37+ base64_config = config.get('conn_check_config')
38+ if base64_config:
39+ conn_check_config.extend(yaml.safe_load(base64.b64decode(base64_config)))
40+ conn_check_config.extend(self._get_postgresql_checks())
41+ conn_check_config.extend(self._get_amqp_checks())
42+ # save the yaml conn-check config file
43+ content = yaml.dump(conn_check_config, default_flow_style=False)
44+ conn_check_config_path = os.path.join(ETC_DIR, 'conn-check-config.yaml')
45+ host.write_file(conn_check_config_path, content,
46+ owner='ubuntu', group='nagios', perms=0o440)
47+ # notify the relation
48+ return dict(config_path=conn_check_config_path,
49+ nagios_servicegroups=config['nagios_context'])
50+
51+ def _get_postgresql_checks(self):
52+ config = hookenv.config()
53+ checks = []
54+ db_rels = hookenv.relations_of_type('db')
55+ required_data = ('port', 'host', 'user', 'password', 'database')
56+ for server in db_rels:
57+ if len(required_data) != len([k for k in required_data if k in server]) \
58+ and server['database'] == config['db_name']:
59+ continue
60+ db_check = {'type': 'postgres',
61+ 'host': server['host'],
62+ 'port': int(server['port']),
63+ 'username': server['user'],
64+ 'password': server['password'],
65+ 'database': server['database']}
66+ checks.append(db_check)
67+ return checks
68+
69+ def _get_amqp_checks(self):
70+ checks = []
71+ # read amqp uris from config file to build amqp check
72+ parser = ConfigParser.ConfigParser()
73+ config_file = os.path.join(SERVICE_DIR, 'service.conf')
74+ parser.read([config_file])
75+ if 'amqp' not in parser.sections():
76+ return checks
77+ # only if amqp section is defined
78+ for amqp_uri in parser.get('amqp', 'uris').split():
79+ parsed = urlparse.urlparse(amqp_uri)
80+ vhost = urlparse.unquote(parsed.path[1:]) or '/'
81+ use_tls = parsed.scheme == "amqps"
82+ amqp_check = dict(type="amqp",
83+ host=parsed.hostname,
84+ port=parsed.port,
85+ username=parsed.username,
86+ password=parsed.password,
87+ use_tls=use_tls,
88+ vhost=vhost)
89+ checks.append(amqp_check)
90+ return checks
91+
92+
93 def nrpe_external_master_relation(service_name):
94 ''' Configure the nrpe-external-master relation '''
95 nrpe_compat = nrpe.NRPE()
96
97=== added symlink 'hooks/conn-check-relation-changed'
98=== target is u'hooks.py'
99=== modified file 'hooks/services.py'
100--- hooks/services.py 2015-08-10 15:22:14 +0000
101+++ hooks/services.py 2015-08-13 14:17:24 +0000
102@@ -13,7 +13,8 @@
103 {
104 'service': 'spec-manager',
105 'provided_data': [actions.WebsiteRelation(),
106- actions.PostgresqlRelation()],
107+ actions.PostgresqlRelation(),
108+ actions.ConnCheckRelation()],
109 'required_data': [config,
110 actions.PostgresqlRelation(required=True)],
111 'data_ready': [
112
113=== modified file 'metadata.yaml'
114--- metadata.yaml 2015-08-04 12:30:43 +0000
115+++ metadata.yaml 2015-08-13 14:17:24 +0000
116@@ -10,6 +10,9 @@
117 nrpe-external-master:
118 interface: nrpe-external-master
119 scope: container
120+ conn-check:
121+ interface: conn-check
122+ scope: container
123
124 requires:
125 db:

Subscribers

People subscribed via source and target branches