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
=== added file 'hooks/beats-relation-changed'
--- hooks/beats-relation-changed 1970-01-01 00:00:00 +0000
+++ hooks/beats-relation-changed 2017-11-30 14:24:04 +0000
@@ -0,0 +1,7 @@
1#!/bin/bash
2
3set -eux
4
5hostname=$(unit-get private-address)
6juju-log "Setting beats URL to $hostname:5044"
7relation-set port=5044 hostname=$hostname
08
=== added symlink 'hooks/beats-relation-joined'
=== target is u'beats-relation-changed'
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2016-11-23 22:25:02 +0000
+++ hooks/config-changed 2017-11-30 14:24:04 +0000
@@ -37,7 +37,10 @@
37 place_upstart_template()37 place_upstart_template()
3838
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 # open port for lumberjack
40 hookenv.open_port(5043)41 hookenv.open_port(5043)
42 # open port for beats
43 hookenv.open_port(5044)
4144
42 # Verify the config to get a decent error message for bad configuration.45 # Verify the config to get a decent error message for bad configuration.
43 try:46 try:
@@ -61,6 +64,7 @@
61 files = os.listdir('templates')64 files = os.listdir('templates')
62 opts = {'BASEPATH': BASEPATH}65 opts = {'BASEPATH': BASEPATH}
63 lumberjack_template = "input-lumberjack.conf"66 lumberjack_template = "input-lumberjack.conf"
67 beats_template = "input-beats.conf"
64 cert_dir = os.path.join(BASEPATH, 'ssl')68 cert_dir = os.path.join(BASEPATH, 'ssl')
65 cert_file = os.path.join(cert_dir, 'logstash.crt')69 cert_file = os.path.join(cert_dir, 'logstash.crt')
66 key_file = os.path.join(cert_dir, 'logstash.key')70 key_file = os.path.join(cert_dir, 'logstash.key')
@@ -72,7 +76,7 @@
72 # hooks/client-relation-changed76 # hooks/client-relation-changed
73 if os.path.basename(f) == "output-elasticsearch.conf":77 if os.path.basename(f) == "output-elasticsearch.conf":
74 continue78 continue
75 if os.path.basename(f) != lumberjack_template:79 if os.path.basename(f) not in (lumberjack_template, beats_template):
76 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:80 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:
77 p.write(render(os.path.basename(f), opts))81 p.write(render(os.path.basename(f), opts))
7882
@@ -89,7 +93,7 @@
89 with open(os.path.join(patterns_dir, 'extra-patterns'), 'w') as f:93 with open(os.path.join(patterns_dir, 'extra-patterns'), 'w') as f:
90 f.write(str(base64.b64decode(config_data['extra-patterns'])))94 f.write(str(base64.b64decode(config_data['extra-patterns'])))
9195
92 # Only setup lumberjack protocol if ssl cert and key are configured96 # Setup ssl cert and key if configured
93 if config_data['ssl_cert'] and config_data['ssl_key']:97 if config_data['ssl_cert'] and config_data['ssl_key']:
94 if not os.path.exists(cert_dir):98 if not os.path.exists(cert_dir):
95 os.mkdir(cert_dir, 0770)99 os.mkdir(cert_dir, 0770)
@@ -106,9 +110,14 @@
106 with open(key_file, 'w') as f:110 with open(key_file, 'w') as f:
107 f.write(str(base64.b64decode(config_data['ssl_key'])))111 f.write(str(base64.b64decode(config_data['ssl_key'])))
108112
113 # Only setup lumberjack protocol if ssl cert and key are configured
109 with open(os.path.join(BASEPATH, 'conf.d', lumberjack_template), 'w') as p:114 with open(os.path.join(BASEPATH, 'conf.d', lumberjack_template), 'w') as p:
110 p.write(render(os.path.basename(lumberjack_template), opts))115 p.write(render(os.path.basename(lumberjack_template), opts))
111116
117 # Only setup beats protocol if ssl cert and key are configured
118 with open(os.path.join(BASEPATH, 'conf.d', beats_template), 'w') as p:
119 p.write(render(os.path.basename(beats_template), opts))
120
112121
113def place_upstart_template():122def place_upstart_template():
114 out = os.path.join(os.path.sep, 'etc', 'init', '{}.conf'.format(SERVICE))123 out = os.path.join(os.path.sep, 'etc', 'init', '{}.conf'.format(SERVICE))
115124
=== modified file 'hooks/nrpe-external-master-relation-changed'
--- hooks/nrpe-external-master-relation-changed 2016-01-25 13:09:45 +0000
+++ hooks/nrpe-external-master-relation-changed 2017-11-30 14:24:04 +0000
@@ -120,6 +120,24 @@
120 )120 )
121 else:121 else:
122 log('No client relations. Not adding e2e check.')122 log('No client relations. Not adding e2e check.')
123 # Only setup beats protocol if ssl cert and key are configured
124 if config_data['ssl_cert'] and config_data['ssl_key']:
125 if check_tcp_params:
126 nrpe_compat.add_check(
127 shortname='beats_tcp',
128 description='Check logstash beats input tcp port',
129 check_cmd='check_tcp %s' % check_tcp_params
130 )
131 if check_cert_params:
132 # check certificate expiry date, daily and retry every 2 hs
133 cert_check = CustomIntervalCheck(
134 shortname='beats_ssl_check',
135 description='Check logstash ssl certificate expiry date',
136 check_cmd='check_tcp --ssl {}'.format(check_cert_params),
137 normal_check_interval=1440, # minutes
138 retry_check_interval=120, # minutes
139 )
140 nrpe_compat.checks.append(cert_check)
123141
124 nrpe_compat.write()142 nrpe_compat.write()
125143
126144
=== added file 'templates/input-beats.conf'
--- templates/input-beats.conf 1970-01-01 00:00:00 +0000
+++ templates/input-beats.conf 2017-11-30 14:24:04 +0000
@@ -0,0 +1,14 @@
1input {
2 beats {
3 # The port to listen on
4 port => 5044
5
6 ssl => true
7 # The paths to your ssl cert and key
8 ssl_certificate => "{{BASEPATH}}/ssl/logstash.crt"
9 ssl_key => "{{BASEPATH}}/ssl/logstash.key"
10
11 # Set this to whatever you want.
12 type => "beats"
13 }
14}

Subscribers

People subscribed via source and target branches