From 935be638bff41046534d8ac500d69b1d9b8adb3d Mon Sep 17 00:00:00 2001
From: Benjamin Graillot <graillot@crans.org>
Date: Sun, 3 Jan 2021 11:01:49 +0100
Subject: [PATCH] [rsyslog-server] rotate logs and install relp module

---
 roles/rsyslog-server/tasks/main.yml           | 18 +++++++
 .../templates/logrotate.d/crans.j2            | 53 +++++++++++++++++++
 .../templates/rsyslog.d/30-cablage.conf.j2    |  2 +
 3 files changed, 73 insertions(+)
 create mode 100644 roles/rsyslog-server/templates/logrotate.d/crans.j2

diff --git a/roles/rsyslog-server/tasks/main.yml b/roles/rsyslog-server/tasks/main.yml
index 5d99654a..8ea84a19 100644
--- a/roles/rsyslog-server/tasks/main.yml
+++ b/roles/rsyslog-server/tasks/main.yml
@@ -1,4 +1,22 @@
 ---
+- name: Install common tools
+  apt:
+    update_cache: true
+    install_recommends: false
+    name:
+      - rsyslog-relp
+  register: apt_result
+  retries: 3
+  until: apt_result is succeeded
+
+- name: Deploy logrotate cablage config
+  template:
+    src: logrotate.d/crans.j2
+    dest: /etc/logrotate.d/crans
+    mode: 0644
+    owner: root
+    group: root
+
 - name: Deploy rsyslog cablage config
   template:
     src: rsyslog.d/30-cablage.conf.j2
diff --git a/roles/rsyslog-server/templates/logrotate.d/crans.j2 b/roles/rsyslog-server/templates/logrotate.d/crans.j2
new file mode 100644
index 00000000..b0b5bd75
--- /dev/null
+++ b/roles/rsyslog-server/templates/logrotate.d/crans.j2
@@ -0,0 +1,53 @@
+{{ ansible_header | comment }}
+
+# Logs Crans
+
+# Logs pour le cablage
+/pool/logs/tealc/cablage/global.log {
+    daily
+    rotate 365
+    compress
+    notifempty
+    missingok
+    create 640 root adm
+    postrotate
+        invoke-rc.d rsyslog rotate > /dev/null
+    endscript
+}
+
+
+# Logs centralisés
+
+# FreeRADIUS
+/pool/logs/tealc/freeradius/*.log {
+    weekly
+    rotate 365
+    compress
+    delaycompress
+    notifempty
+    missingok
+    postrotate
+        invoke-rc.d rsyslog rotate > /dev/null
+    endscript
+}
+
+# Logs des bornes et des switches
+/pool/logs/tealc/wifi/global.log {
+    daily
+    rotate 365
+    compress
+    notifempty
+    postrotate
+        invoke-rc.d rsyslog rotate > /dev/null
+    endscript
+}
+
+/pool/logs/tealc/filaire/global.log {
+    daily
+    rotate 365
+    compress
+    notifempty
+    postrotate
+        invoke-rc.d rsyslog rotate > /dev/null
+    endscript
+}
diff --git a/roles/rsyslog-server/templates/rsyslog.d/30-cablage.conf.j2 b/roles/rsyslog-server/templates/rsyslog.d/30-cablage.conf.j2
index 7d1c9f44..582b71a7 100644
--- a/roles/rsyslog-server/templates/rsyslog.d/30-cablage.conf.j2
+++ b/roles/rsyslog-server/templates/rsyslog.d/30-cablage.conf.j2
@@ -1,5 +1,7 @@
 {{ ansible_header | comment }}
 
+$template CablageFileFormat,"%TIMESTAMP:::date-rfc3339% %fromhost% %syslogtag%%msg%\\n"
+
 # Logs des switches
 
 if $fromhost-ip startswith '172.16.33.' then /pool/logs/tealc/cablage/global.log; CablageFileFormat
-- 
GitLab