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
1=== modified file 'config.yaml'
2--- config.yaml 2015-11-04 00:26:13 +0000
3+++ config.yaml 2015-11-12 23:47:27 +0000
4@@ -22,7 +22,24 @@
5 extra-config:
6 type: string
7 default: ''
8- description: "Base64-encoded custom configuration content."
9+ description: |
10+ Base64-encoded custom configuration content. If you have a directory of
11+ logstash filters, you can set this with:
12+ juju set logstash extra-config="$(cat filters/* | base64)"
13+ extra-patterns:
14+ type: string
15+ default: ''
16+ description: |
17+ Base64-encoded custom grok patterns for your logstash filters. If you
18+ have a directory of patterns, you can set this with:
19+ juju set logstash extra-patterns="$(cat patterns/* | base64)"
20+ These will be placed into the /opt/logstash/patterns directory and so can be
21+ referenced in a grok filter with:
22+ grok {
23+ patterns_dir => "./patterns"
24+ match => { ... }
25+ }
26+ More info at https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html#_custom_patterns
27 nagios_context:
28 default: "juju"
29 type: string
30
31=== modified file 'hooks/config-changed'
32--- hooks/config-changed 2015-10-22 05:29:50 +0000
33+++ hooks/config-changed 2015-11-12 23:47:27 +0000
34@@ -39,7 +39,19 @@
35 # This only actually opens the port if we've exposed the service in juju
36 hookenv.open_port(5043)
37
38- # Restart the service when configuration has changed.
39+ # Verify the config to get a decent error message for bad configuration.
40+ try:
41+ subprocess.check_output([
42+ '/opt/logstash/bin/logstash', 'agent', '-f',
43+ '/opt/logstash/conf.d/', '--configtest'
44+ ])
45+ except subprocess.CalledProcessError, e:
46+ # The exception doesn't print the output, by default.
47+ print(e.output)
48+ raise
49+
50+ # Restart the service when configuration has changed
51+ # and the config is valid.
52 subprocess.check_output(shlex.split('hooks/start'))
53
54 subprocess.check_output(shlex.split('hooks/nrpe-external-master-relation-changed'))
55@@ -68,6 +80,12 @@
56 if config_data['extra-config']:
57 with open(os.path.join(BASEPATH, 'conf.d', 'extra.conf'), 'w') as f:
58 f.write(str(base64.b64decode(config_data['extra-config'])))
59+ if config_data['extra-patterns']:
60+ patterns_dir = os.path.join(BASEPATH, 'patterns')
61+ if not os.path.exists(patterns_dir):
62+ os.mkdir(patterns_dir)
63+ with open(os.path.join(patterns_dir, 'extra-patterns'), 'w') as f:
64+ f.write(str(base64.b64decode(config_data['extra-patterns'])))
65
66 # Only setup lumberjack protocol if ssl cert and key are configured
67 if config_data['ssl_cert'] and config_data['ssl_key']:

Subscribers

People subscribed via source and target branches