Merge ~hloeung/charm-graylog:master into ~graylog-charmers/charm-graylog:master

Proposed by Haw Loeung
Status: Merged
Merged at revision: 5721b047d3891063b6a2a882e4139027cde487c5
Proposed branch: ~hloeung/charm-graylog:master
Merge into: ~graylog-charmers/charm-graylog:master
Diff against target: 69 lines (+16/-5)
2 files modified
lib/graylogapi.py (+6/-4)
reactive/graylog.py (+10/-1)
Reviewer Review Type Date Requested Status
Junien F Approve
Review via email: mp+329883@code.launchpad.net

Description of the change

Fix set_conf() add config option when not present

At present, if the config shipped out doesn't have the required
config, nothing happens. This adds the config to the end if it
doesn't.

Also fixed to reduce tracebacks when we can't query the API.

To post a comment you must log in.
Revision history for this message
Junien F (axino) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/graylogapi.py b/lib/graylogapi.py
2index e7a7ef3..8fb191b 100644
3--- a/lib/graylogapi.py
4+++ b/lib/graylogapi.py
5@@ -79,8 +79,9 @@ class GraylogAPI:
6 url = 'system/indices/index_sets'
7 if index_id:
8 return self._request('{}/{}'.format(url, index_id))
9- else:
10- return self._request(url)['index_sets'] or None
11+ resp = self._request(url)
12+ if resp:
13+ return resp.get('index_sets', None)
14
15 def index_set_update(self, index_id, data):
16 if not self.token:
17@@ -94,8 +95,9 @@ class GraylogAPI:
18 url = 'system/inputs'
19 if input_id:
20 return self._request('{}/{}'.format(url, input_id))
21- else:
22- return self._request(url)['inputs'] or None
23+ resp = self._request(url)
24+ if resp:
25+ return resp.get('inputs', None)
26
27 def log_input_update(self, input_id=None, data=None):
28 if not self.token:
29diff --git a/reactive/graylog.py b/reactive/graylog.py
30index 49902a1..5f5ad71 100644
31--- a/reactive/graylog.py
32+++ b/reactive/graylog.py
33@@ -348,12 +348,13 @@ def set_conf(key, value, conf_path=CONF_FILE):
34 changed = False
35 replaced = False
36 with open(conf_path, 'rb') as conf_file:
37+ found = False
38 for line in conf_file:
39 line = line.decode().rstrip()
40 if not key_re.match(line):
41 conf.append(line)
42 continue
43-
44+ found = True
45 if not replaced:
46 new = '{} = {}'.format(key, value)
47 if line != new:
48@@ -365,6 +366,10 @@ def set_conf(key, value, conf_path=CONF_FILE):
49 conf.append('#' + line)
50 else:
51 conf.append(line)
52+ if not found:
53+ hookenv.log('Updating configuration file new option "{}".'.format(key))
54+ changed = True
55+ conf.append('{} = {}'.format(key, value))
56
57 if changed:
58 set_state('graylog.needs_restart')
59@@ -419,6 +424,10 @@ def configure_nagios(nagios):
60 password=nagios_password,
61 token_name='nagios')
62 nagios_token = g.token_get()
63+ if not nagios_token:
64+ # API not ready, let's write out what we have anyways.
65+ nrpe_setup.write()
66+ return
67 host.write_file('/var/lib/nagios/graylog-api-token', nagios_token.encode(),
68 group='nagios', perms=0o640)
69 for f in ('files/check_graylog_health.py', 'lib/graylogapi.py'):

Subscribers

People subscribed via source and target branches

to all changes: