Merge lp:~timkuhlman/charms/trusty/rsyslog/tcp into lp:charms/trusty/rsyslog

Proposed by Tim Kuhlman
Status: Merged
Merge reported by: Adam Israel
Merged at revision: not available
Proposed branch: lp:~timkuhlman/charms/trusty/rsyslog/tcp
Merge into: lp:charms/trusty/rsyslog
Diff against target: 249 lines (+96/-19)
7 files modified
README.md (+13/-4)
config.yaml (+21/-1)
hooks/hooks.py (+17/-7)
setup.cfg (+1/-3)
templates/60-aggregator.conf (+3/-0)
templates/70-forward.conf (+17/-0)
unit_tests/test_hooks.py (+24/-4)
To merge this branch: bzr merge lp:~timkuhlman/charms/trusty/rsyslog/tcp
Reviewer Review Type Date Requested Status
Review Queue (community) automated testing Needs Fixing
Adam Israel (community) Approve
Review via email: mp+289981@code.launchpad.net

Description of the change

Added support for receiving logs in TCP and for forwarding any log entries to an arbitrary aggregator, ie one not in the current Juju environment.

To post a comment you must log in.
23. By Tim Kuhlman

Added a selector config option for the forwarder

24. By Tim Kuhlman

Added forward options for relp

Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/3268/

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-aws/3364/

review: Needs Fixing (automated testing)
25. By Tim Kuhlman

Fixed unit_tests

26. By Tim Kuhlman

Coverage tests are broken in the venv

Revision history for this message
Adam Israel (aisrael) wrote :

Hi Tim,

Thanks for your work on this. Your changes look good. You have my +1

review: Approve
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/3380/

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-aws/3430/

review: Needs Fixing (automated testing)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README.md'
--- README.md 2015-01-28 23:11:06 +0000
+++ README.md 2016-03-28 16:21:23 +0000
@@ -44,10 +44,19 @@
4444
45# Setting the protocol45# Setting the protocol
4646
47By default rsyslog charms uses the UDP protocol, but also RELP can be used.47By default rsyslog charms uses the UDP protocol, but also RELP or tcp can be used.
4848
49 juju set rsyslog protocol="relp"49 juju set rsyslog protocol="relp"
50 juju set rsyslog-forwarder-ha protocol="relp"50 juju set rsyslog-forwarder-ha protocol="relp"
51
52# Forwarding logs to a system outside of the Juju environment
53
54For forwarding within the Juju environment use the subordinate charm rsyslog-forwarder-ha but to
55forward the aggregated logs outside of the Juju environment you set the forward_* options.
56
57 juju set rsyslog forward_host="elk.my.domain"
58 juju set rsyslog forward_protocol="tcp"
59 juju set rsyslog forward_port="514"
5160
52# Contact Information61# Contact Information
5362
5463
=== modified file 'config.yaml'
--- config.yaml 2015-01-29 01:31:00 +0000
+++ config.yaml 2016-03-28 16:21:23 +0000
@@ -1,4 +1,24 @@
1options:1options:
2 forward_host:
3 type: string
4 default: ""
5 description: "A host to forward all logs to."
6 forward_options:
7 type: string
8 default: ""
9 description: "Options to add to the forward config, currently only used by RELP"
10 forward_port:
11 type: string
12 default: "514"
13 description: "The port on the forward_host to send logs to."
14 forward_protocol:
15 type: string
16 default: "tcp"
17 description: "Transport protocol to use with the forward_host available options: udp, relp, tcp"
18 forward_selector:
19 type: string
20 default: "*.*"
21 description: "Syslog style selector to specify which logs to forward. For example '*.crit' or 'auth.*'"
2 syslog_rotate:22 syslog_rotate:
3 type: int23 type: int
4 default: 724 default: 7
@@ -14,4 +34,4 @@
14 protocol:34 protocol:
15 type: string35 type: string
16 default: "udp"36 default: "udp"
17 description: "Transport protocol to use available options: udp, relp"37 description: "Transport protocol to use available options: udp, relp, tcp"
1838
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2015-01-28 23:24:24 +0000
+++ hooks/hooks.py 2016-03-28 16:21:23 +0000
@@ -32,6 +32,11 @@
32DEFAULT_LOGROTATE_PATH = os.path.join(os.path.sep, 'etc', 'logrotate.d',32DEFAULT_LOGROTATE_PATH = os.path.join(os.path.sep, 'etc', 'logrotate.d',
33 'rsyslog')33 'rsyslog')
34DEFAULT_CONFIGURATION_PARAMS = (34DEFAULT_CONFIGURATION_PARAMS = (
35 'forward_host',
36 'forward_options',
37 'forward_port',
38 'forward_protocol',
39 'forward_selector',
35 'syslog_rotate',40 'syslog_rotate',
36 'messages_rotate',41 'messages_rotate',
37 'nova_logs',42 'nova_logs',
@@ -85,10 +90,12 @@
85def start():90def start():
86 service_start("rsyslog")91 service_start("rsyslog")
8792
88 if config_get('protocol') == "relp":93 proto = config_get('protocol')
94 if proto == "relp":
89 open_port(DEFAULT_RELP_PORT)95 open_port(DEFAULT_RELP_PORT)
90 else:96 elif proto == "tcp":
91 open_port(DEFAULT_RSYSLOG_PORT)97 open_port(DEFAULT_RSYSLOG_PORT)
98 else:
92 open_port(DEFAULT_RSYSLOG_PORT, protocol="UDP")99 open_port(DEFAULT_RSYSLOG_PORT, protocol="UDP")
93100
94101
@@ -96,10 +103,12 @@
96def stop():103def stop():
97 service_stop("rsyslog")104 service_stop("rsyslog")
98105
99 if config_get('protocol') == "relp":106 proto = config_get('protocol')
107 if proto == "relp":
100 close_port(DEFAULT_RELP_PORT)108 close_port(DEFAULT_RELP_PORT)
101 else:109 elif proto == "tcp":
102 close_port(DEFAULT_RSYSLOG_PORT)110 close_port(DEFAULT_RSYSLOG_PORT)
111 else:
103 close_port(DEFAULT_RSYSLOG_PORT, protocol="UDP")112 close_port(DEFAULT_RSYSLOG_PORT, protocol="UDP")
104113
105114
@@ -111,8 +120,7 @@
111 logrotate_config.write(template.render(**params))120 logrotate_config.write(template.render(**params))
112121
113122
114def update_rsyslog_config(**params):123def update_rsyslog_config(template_name, **params):
115 template_name = "60-aggregator.conf"
116 template = get_config_template(template_name)124 template = get_config_template(template_name)
117125
118 with open(os.path.join(DEFAULT_RSYSLOG_PATH,126 with open(os.path.join(DEFAULT_RSYSLOG_PATH,
@@ -125,7 +133,9 @@
125 config = get_changed_config()133 config = get_changed_config()
126134
127 update_logrotate_config(**config)135 update_logrotate_config(**config)
128 update_rsyslog_config(**config)136 update_rsyslog_config(template_name="60-aggregator.conf", **config)
137 if config_get('forward_host') != "":
138 update_rsyslog_config(template_name="70-forward.conf", **config)
129139
130 juju_log("Configuration changed, restart required")140 juju_log("Configuration changed, restart required")
131141
132142
=== modified file 'setup.cfg'
--- setup.cfg 2014-04-22 19:45:41 +0000
+++ setup.cfg 2016-03-28 16:21:23 +0000
@@ -1,5 +1,3 @@
1[nosetests]1[nosetests]
2verbosity=22verbosity=2
3with-coverage=13with-coverage=0
4cover-erase=1
5cover-package=hooks.hooks
64
=== modified file 'templates/60-aggregator.conf'
--- templates/60-aggregator.conf 2015-01-28 23:11:06 +0000
+++ templates/60-aggregator.conf 2016-03-28 16:21:23 +0000
@@ -2,6 +2,9 @@
2{% if protocol == "udp" %}2{% if protocol == "udp" %}
3$ModLoad imudp3$ModLoad imudp
4$UDPServerRun 5144$UDPServerRun 514
5{% elif protocol == "tcp" %}
6$ModLoad imtcp
7$InputTCPServerRun 514
5{% else %}8{% else %}
6$ModLoad imrelp9$ModLoad imrelp
7$InputRELPServerRun 251410$InputRELPServerRun 2514
811
=== added file 'templates/70-forward.conf'
--- templates/70-forward.conf 1970-01-01 00:00:00 +0000
+++ templates/70-forward.conf 2016-03-28 16:21:23 +0000
@@ -0,0 +1,17 @@
1{% if forward_protocol == "relp" %}
2$ModLoad omrelp
3{% endif %}
4
5$ActionQueueType LinkedList # use asynchronous processing
6$ActionQueueFileName {{ forward_host }} # set file name, also enables disk mode
7$ActionResumeRetryCount -1 # infinite retries on insert failure
8$ActionQueueSaveOnShutdown on # save in-memory data if rsyslog shuts down
9
10# Forward everything
11{% if forward_protocol == "udp" %}
12{{forward_selector}} @{{forward_host}}:{{forward_port}}
13{% elif forward_protocol == "tcp" %}
14{{forward_selector}} @@{{forward_host}}:{{forward_port}}
15{% else %}
16{{forward_selector}} action(type="omrelp" target="{{forward_host}}" port="{{forward_port}}" {{forward_options}})
17{% endif %}
018
=== modified file 'unit_tests/test_hooks.py'
--- unit_tests/test_hooks.py 2015-01-28 23:11:06 +0000
+++ unit_tests/test_hooks.py 2016-03-28 16:21:23 +0000
@@ -69,8 +69,7 @@
69 hooks.hooks.execute(['start'])69 hooks.hooks.execute(['start'])
70 self.service_start.assert_called_with("rsyslog")70 self.service_start.assert_called_with("rsyslog")
7171
72 expected = [mock.call(514),72 expected = [mock.call(514, protocol="UDP")]
73 mock.call(514, protocol="UDP")]
7473
75 self.assertEquals(self.open_port.call_args_list,74 self.assertEquals(self.open_port.call_args_list,
76 expected)75 expected)
@@ -82,8 +81,7 @@
8281
83 self.service_stop.assert_called_with("rsyslog")82 self.service_stop.assert_called_with("rsyslog")
8483
85 expected = [mock.call(514),84 expected = [mock.call(514, protocol="UDP")]
86 mock.call(514, protocol="UDP")]
8785
88 self.assertTrue(self.close_port.call_args_list == expected)86 self.assertTrue(self.close_port.call_args_list == expected)
8987
@@ -99,6 +97,11 @@
99 self.charm_dir.return_value = os.path.join(_HERE, '..')97 self.charm_dir.return_value = os.path.join(_HERE, '..')
10098
101 config = {99 config = {
100 "forward_host": "",
101 "forward_options": "",
102 "forward_port": "514",
103 "forward_protocol": "tcp",
104 "forward_selector": "*.*",
102 "syslog_rotate": 7,105 "syslog_rotate": 7,
103 "messages_rotate": 4,106 "messages_rotate": 4,
104 "nova_logs": False,107 "nova_logs": False,
@@ -119,6 +122,11 @@
119 ( nova_logs: True )122 ( nova_logs: True )
120 """123 """
121 config = {124 config = {
125 "forward_host": "",
126 "forward_options": "",
127 "forward_port": "514",
128 "forward_protocol": "tcp",
129 "forward_selector": "*.*",
122 "syslog_rotate": 7,130 "syslog_rotate": 7,
123 "messages_rotate": 4,131 "messages_rotate": 4,
124 "nova_logs": True,132 "nova_logs": True,
@@ -138,12 +146,24 @@
138 with mock.patch('__builtin__.open', _open, create=True):146 with mock.patch('__builtin__.open', _open, create=True):
139 hooks.config_changed()147 hooks.config_changed()
140148
149 # I'm not quite sure why config_changed appears to be called twice but
150 # it does behave properly and only make changes once
141 expected = [151 expected = [
142 mock.call(os.path.join(hooks.get_template_dir(),152 mock.call(os.path.join(hooks.get_template_dir(),
143 '60-aggregator.conf'), 'rb'),153 '60-aggregator.conf'), 'rb'),
154 mock.call(os.path.join(hooks.get_template_dir(),
155 '60-aggregator.conf'), 'rb'),
144 mock.call(os.path.join(hooks.DEFAULT_RSYSLOG_PATH,156 mock.call(os.path.join(hooks.DEFAULT_RSYSLOG_PATH,
145 '60-aggregator.conf'), 'w'),157 '60-aggregator.conf'), 'w'),
146 mock.call(os.path.join(hooks.get_template_dir(),158 mock.call(os.path.join(hooks.get_template_dir(),
159 '70-forward.conf'), 'rb'),
160 mock.call(os.path.join(hooks.get_template_dir(),
161 '70-forward.conf'), 'rb'),
162 mock.call(os.path.join(hooks.DEFAULT_RSYSLOG_PATH,
163 '70-forward.conf'), 'w'),
164 mock.call(os.path.join(hooks.get_template_dir(),
165 'rsyslog.conf'), 'rb'),
166 mock.call(os.path.join(hooks.get_template_dir(),
147 'rsyslog.conf'), 'rb'),167 'rsyslog.conf'), 'rb'),
148 mock.call(hooks.DEFAULT_LOGROTATE_PATH, 'w')168 mock.call(hooks.DEFAULT_LOGROTATE_PATH, 'w')
149 ]169 ]

Subscribers

People subscribed via source and target branches