Merge lp:~michael.nelson/charms/trusty/logstash/enable-custom-patterns into lp:~canonical-is-sa/charms/trusty/logstash/logstash2

Proposed by Michael Nelson
Status: Merged
Merged at revision: 58
Proposed branch: lp:~michael.nelson/charms/trusty/logstash/enable-custom-patterns
Merge into: lp:~canonical-is-sa/charms/trusty/logstash/logstash2
Diff against target: 67 lines (+37/-2)
2 files modified
config.yaml (+18/-1)
hooks/config-changed (+19/-1)
To merge this branch: bzr merge lp:~michael.nelson/charms/trusty/logstash/enable-custom-patterns
Reviewer Review Type Date Requested Status
Michael Foley (community) Approve
Review via email: mp+277313@code.launchpad.net

Commit message

Add extra-patterns option.
Test config before restarting (for better error message in logs).

Description of the change

Using the logstash charm, I'm finding for any semi-useful filters I need to define my own grok patterns.

Also took the chance to improve the config descriptions.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

Setting back to WIP after local spec run using this charm shows an issue.

62. By Michael Nelson

Un-shorten URI

63. By Michael Nelson

Reformat comment

Revision history for this message
Michael Foley (foli) wrote :

Great to see the ability to add custom grok patterns.

And great to see it catching config errors, which would otherwise stop it from processing logs.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2015-11-04 00:26:13 +0000
+++ config.yaml 2015-11-12 23:47:27 +0000
@@ -22,7 +22,24 @@
22 extra-config:22 extra-config:
23 type: string23 type: string
24 default: ''24 default: ''
25 description: "Base64-encoded custom configuration content."25 description: |
26 Base64-encoded custom configuration content. If you have a directory of
27 logstash filters, you can set this with:
28 juju set logstash extra-config="$(cat filters/* | base64)"
29 extra-patterns:
30 type: string
31 default: ''
32 description: |
33 Base64-encoded custom grok patterns for your logstash filters. If you
34 have a directory of patterns, you can set this with:
35 juju set logstash extra-patterns="$(cat patterns/* | base64)"
36 These will be placed into the /opt/logstash/patterns directory and so can be
37 referenced in a grok filter with:
38 grok {
39 patterns_dir => "./patterns"
40 match => { ... }
41 }
42 More info at https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html#_custom_patterns
26 nagios_context:43 nagios_context:
27 default: "juju"44 default: "juju"
28 type: string45 type: string
2946
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2015-10-22 05:29:50 +0000
+++ hooks/config-changed 2015-11-12 23:47:27 +0000
@@ -39,7 +39,19 @@
39 # This only actually opens the port if we've exposed the service in juju39 # This only actually opens the port if we've exposed the service in juju
40 hookenv.open_port(5043)40 hookenv.open_port(5043)
4141
42 # Restart the service when configuration has changed.42 # Verify the config to get a decent error message for bad configuration.
43 try:
44 subprocess.check_output([
45 '/opt/logstash/bin/logstash', 'agent', '-f',
46 '/opt/logstash/conf.d/', '--configtest'
47 ])
48 except subprocess.CalledProcessError, e:
49 # The exception doesn't print the output, by default.
50 print(e.output)
51 raise
52
53 # Restart the service when configuration has changed
54 # and the config is valid.
43 subprocess.check_output(shlex.split('hooks/start'))55 subprocess.check_output(shlex.split('hooks/start'))
4456
45 subprocess.check_output(shlex.split('hooks/nrpe-external-master-relation-changed'))57 subprocess.check_output(shlex.split('hooks/nrpe-external-master-relation-changed'))
@@ -68,6 +80,12 @@
68 if config_data['extra-config']:80 if config_data['extra-config']:
69 with open(os.path.join(BASEPATH, 'conf.d', 'extra.conf'), 'w') as f:81 with open(os.path.join(BASEPATH, 'conf.d', 'extra.conf'), 'w') as f:
70 f.write(str(base64.b64decode(config_data['extra-config'])))82 f.write(str(base64.b64decode(config_data['extra-config'])))
83 if config_data['extra-patterns']:
84 patterns_dir = os.path.join(BASEPATH, 'patterns')
85 if not os.path.exists(patterns_dir):
86 os.mkdir(patterns_dir)
87 with open(os.path.join(patterns_dir, 'extra-patterns'), 'w') as f:
88 f.write(str(base64.b64decode(config_data['extra-patterns'])))
7189
72 # Only setup lumberjack protocol if ssl cert and key are configured90 # Only setup lumberjack protocol if ssl cert and key are configured
73 if config_data['ssl_cert'] and config_data['ssl_key']:91 if config_data['ssl_cert'] and config_data['ssl_key']:

Subscribers

People subscribed via source and target branches