Merge lp:~louis/charms/precise/rsyslog/trunk into lp:charms/rsyslog

Proposed by Louis Bouchard
Status: Merged
Merged at revision: 9
Proposed branch: lp:~louis/charms/precise/rsyslog/trunk
Merge into: lp:charms/rsyslog
Diff against target: 57 lines (+48/-0)
2 files modified
config.yaml (+9/-0)
hooks/config-changed (+39/-0)
To merge this branch: bzr merge lp:~louis/charms/precise/rsyslog/trunk
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+211281@code.launchpad.net

Description of the change

Added config parameters to control logrotate

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'config.yaml'
2--- config.yaml 1970-01-01 00:00:00 +0000
3+++ config.yaml 2014-03-17 10:46:51 +0000
4@@ -0,0 +1,9 @@
5+options:
6+ syslog_rotate:
7+ type: int
8+ default: 7
9+ description: "Number of days to rotate /var/log/syslog file"
10+ messages_rotate:
11+ type: int
12+ default: 4
13+ description: "Number of days to rotate /var/log/messages and other associated files"
14
15=== added file 'hooks/config-changed'
16--- hooks/config-changed 1970-01-01 00:00:00 +0000
17+++ hooks/config-changed 2014-03-17 10:46:51 +0000
18@@ -0,0 +1,39 @@
19+#!/usr/bin/env python
20+
21+import re
22+import subprocess
23+import json
24+
25+
26+def juju_log(message=None):
27+ return (subprocess.call(['juju-log', str(message)]) == 0)
28+
29+log_rotate_conf = '/etc/logrotate.d/rsyslog'
30+
31+config_cmd_line = ['config-get', '--format=json']
32+
33+syslog_rotate_interval = str(json.loads(subprocess.check_output(
34+ config_cmd_line + ['syslog_rotate'])))
35+messages_rotate_interval = str(json.loads(subprocess.check_output(
36+ config_cmd_line + ['messages_rotate'])))
37+
38+with open(log_rotate_conf, mode='r') as config_file:
39+ config = config_file.readlines()
40+ config_file.close()
41+
42+ param_index = config.index('/var/log/syslog\n')
43+ replace_pattern = syslog_rotate_interval + '\n'
44+ config[param_index+2] = re.sub(r'\d*\n$',
45+ replace_pattern, config[param_index+2])
46+ juju_log("syslog_rotate_interval set to %s" % syslog_rotate_interval)
47+
48+ param_index = config.index('/var/log/messages\n')
49+ replace_pattern = messages_rotate_interval + '\n'
50+ config[param_index+2] = re.sub(r'\d*\n$',
51+ replace_pattern, config[param_index+2])
52+ juju_log("messages_rotate_interval set to %s" % messages_rotate_interval)
53+
54+with open(log_rotate_conf, mode='w') as config_file:
55+ for line in config:
56+ config_file.write(line)
57+ config_file.close

Subscribers

People subscribed via source and target branches