Merge lp:~ricardokirkner/charms/trusty/logstash/logstash2-beats into lp:~canonical-is-sa/charms/trusty/logstash/logstash2

Proposed by Ricardo Kirkner
Status: Merged
Merged at revision: 64
Proposed branch: lp:~ricardokirkner/charms/trusty/logstash/logstash2-beats
Merge into: lp:~canonical-is-sa/charms/trusty/logstash/logstash2
Diff against target: 117 lines (+50/-2)
4 files modified
hooks/beats-relation-changed (+7/-0)
hooks/config-changed (+11/-2)
hooks/nrpe-external-master-relation-changed (+18/-0)
templates/input-beats.conf (+14/-0)
To merge this branch: bzr merge lp:~ricardokirkner/charms/trusty/logstash/logstash2-beats
Reviewer Review Type Date Requested Status
Laurent Sesquès Approve
Guillermo Gonzalez (community) Approve
Review via email: mp+334529@code.launchpad.net

Commit message

enable beats protocol as input to logstash

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

please fix comment on line 78?

+1

review: Approve
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

> please fix comment on line 78?

we're only enabling checks for beats protocol if ssl cert is configured (as otherwise beats protocol is not enabled at all).

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

indeed, ignore me :-)

Revision history for this message
Laurent Sesquès (sajoupa) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'hooks/beats-relation-changed'
2--- hooks/beats-relation-changed 1970-01-01 00:00:00 +0000
3+++ hooks/beats-relation-changed 2017-11-30 14:24:04 +0000
4@@ -0,0 +1,7 @@
5+#!/bin/bash
6+
7+set -eux
8+
9+hostname=$(unit-get private-address)
10+juju-log "Setting beats URL to $hostname:5044"
11+relation-set port=5044 hostname=$hostname
12
13=== added symlink 'hooks/beats-relation-joined'
14=== target is u'beats-relation-changed'
15=== modified file 'hooks/config-changed'
16--- hooks/config-changed 2016-11-23 22:25:02 +0000
17+++ hooks/config-changed 2017-11-30 14:24:04 +0000
18@@ -37,7 +37,10 @@
19 place_upstart_template()
20
21 # This only actually opens the port if we've exposed the service in juju
22+ # open port for lumberjack
23 hookenv.open_port(5043)
24+ # open port for beats
25+ hookenv.open_port(5044)
26
27 # Verify the config to get a decent error message for bad configuration.
28 try:
29@@ -61,6 +64,7 @@
30 files = os.listdir('templates')
31 opts = {'BASEPATH': BASEPATH}
32 lumberjack_template = "input-lumberjack.conf"
33+ beats_template = "input-beats.conf"
34 cert_dir = os.path.join(BASEPATH, 'ssl')
35 cert_file = os.path.join(cert_dir, 'logstash.crt')
36 key_file = os.path.join(cert_dir, 'logstash.key')
37@@ -72,7 +76,7 @@
38 # hooks/client-relation-changed
39 if os.path.basename(f) == "output-elasticsearch.conf":
40 continue
41- if os.path.basename(f) != lumberjack_template:
42+ if os.path.basename(f) not in (lumberjack_template, beats_template):
43 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:
44 p.write(render(os.path.basename(f), opts))
45
46@@ -89,7 +93,7 @@
47 with open(os.path.join(patterns_dir, 'extra-patterns'), 'w') as f:
48 f.write(str(base64.b64decode(config_data['extra-patterns'])))
49
50- # Only setup lumberjack protocol if ssl cert and key are configured
51+ # Setup ssl cert and key if configured
52 if config_data['ssl_cert'] and config_data['ssl_key']:
53 if not os.path.exists(cert_dir):
54 os.mkdir(cert_dir, 0770)
55@@ -106,9 +110,14 @@
56 with open(key_file, 'w') as f:
57 f.write(str(base64.b64decode(config_data['ssl_key'])))
58
59+ # Only setup lumberjack protocol if ssl cert and key are configured
60 with open(os.path.join(BASEPATH, 'conf.d', lumberjack_template), 'w') as p:
61 p.write(render(os.path.basename(lumberjack_template), opts))
62
63+ # Only setup beats protocol if ssl cert and key are configured
64+ with open(os.path.join(BASEPATH, 'conf.d', beats_template), 'w') as p:
65+ p.write(render(os.path.basename(beats_template), opts))
66+
67
68 def place_upstart_template():
69 out = os.path.join(os.path.sep, 'etc', 'init', '{}.conf'.format(SERVICE))
70
71=== modified file 'hooks/nrpe-external-master-relation-changed'
72--- hooks/nrpe-external-master-relation-changed 2016-01-25 13:09:45 +0000
73+++ hooks/nrpe-external-master-relation-changed 2017-11-30 14:24:04 +0000
74@@ -120,6 +120,24 @@
75 )
76 else:
77 log('No client relations. Not adding e2e check.')
78+ # Only setup beats protocol if ssl cert and key are configured
79+ if config_data['ssl_cert'] and config_data['ssl_key']:
80+ if check_tcp_params:
81+ nrpe_compat.add_check(
82+ shortname='beats_tcp',
83+ description='Check logstash beats input tcp port',
84+ check_cmd='check_tcp %s' % check_tcp_params
85+ )
86+ if check_cert_params:
87+ # check certificate expiry date, daily and retry every 2 hs
88+ cert_check = CustomIntervalCheck(
89+ shortname='beats_ssl_check',
90+ description='Check logstash ssl certificate expiry date',
91+ check_cmd='check_tcp --ssl {}'.format(check_cert_params),
92+ normal_check_interval=1440, # minutes
93+ retry_check_interval=120, # minutes
94+ )
95+ nrpe_compat.checks.append(cert_check)
96
97 nrpe_compat.write()
98
99
100=== added file 'templates/input-beats.conf'
101--- templates/input-beats.conf 1970-01-01 00:00:00 +0000
102+++ templates/input-beats.conf 2017-11-30 14:24:04 +0000
103@@ -0,0 +1,14 @@
104+input {
105+ beats {
106+ # The port to listen on
107+ port => 5044
108+
109+ ssl => true
110+ # The paths to your ssl cert and key
111+ ssl_certificate => "{{BASEPATH}}/ssl/logstash.crt"
112+ ssl_key => "{{BASEPATH}}/ssl/logstash.key"
113+
114+ # Set this to whatever you want.
115+ type => "beats"
116+ }
117+}

Subscribers

People subscribed via source and target branches