From 63545dc4a38b45b8aec3187a18ed05c162ba8e8b Mon Sep 17 00:00:00 2001 From: charlyforot Date: Fri, 3 Mar 2023 15:24:20 +0100 Subject: [PATCH 1/8] add logrotate for librenms log files --- CHANGELOG.md | 5 +++ Dockerfile | 1 + README.md | 18 ++++++++++ rootfs/etc/cont-init.d/09-config-logrotate.sh | 36 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 rootfs/etc/cont-init.d/09-config-logrotate.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index c08eaec3..37ea3b83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 23.1.1-r1 (2023/03/03) + +* Add `logrotate` package +* Add env variables for `logrotate` + ## 23.1.1-r0 (2023/02/09) * LibreNMS 23.1.1 (#335) diff --git a/Dockerfile b/Dockerfile index 42808ba7..245e8fcf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ RUN apk --update --no-cache add \ imagemagick \ ipmitool \ iputils \ + logrotate \ libcap-utils \ mariadb-client \ monitoring-plugins \ diff --git a/README.md b/README.md index a411c18a..684e5044 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,24 @@ Image: librenms/librenms:latest * `DISPATCHER_NODE_ID`: Unique node ID for your dispatcher service * `DISPATCHER_ARGS`: Additional args to pass to the [dispatcher service](https://github.com/librenms/librenms/blob/master/librenms-service.py) +### Logrotate + +> **Note** +> +> Logrotate variables could be set on all containers to avoid large log files. + +> **Warning** +> +> When activated, logs exceeding the specified retention period `LOGROTATE_RETENTION` will be deleted + +* `LOGROTATE_ENABLED`: Set to `true` to enable logrotate for this container (default `false`) +* `LOGROTATE_INTERVAL`: daily, weekly, monthly, or yearly (default `weekly`) +* `LOGROTATE_RETENTION`: lifetime of the log file (default `6`) +* `LOGROTATE_COMPRESSION_ENABLED`: Set to `true` to enable logrotate `compress` option (default `true`) +* `LOGROTATE_DELAYCOMPRESSION_ENABLED`: Set to `true` to enable logrotate `delaycompress` option (default `true`) +* `LOGROTATE_MISSINGOK_ENABLED`: Set to `true` to enable logrotate `missingok` option (default `true`) +* `LOGROTATE_NOTIFEMPTY_ENABLED`: Set to `true` to enable logrotate `notifempty` option (default `true`) + ### Syslog-ng > **Warning** diff --git a/rootfs/etc/cont-init.d/09-config-logrotate.sh b/rootfs/etc/cont-init.d/09-config-logrotate.sh new file mode 100644 index 00000000..a4bc778d --- /dev/null +++ b/rootfs/etc/cont-init.d/09-config-logrotate.sh @@ -0,0 +1,36 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash +set -e + +if [ ${LOGROTATE_ENABLED:-false} = true ] +then + logrotate_filename="/etc/logrotate.d/librenms" + + echo -e "${LIBRENMS_PATH}/logs/*.log {" > ${logrotate_filename} + echo -e "\tsu librenms librenms" >> ${logrotate_filename} + echo -e "\tcreate 664 librenms librenms" >> ${logrotate_filename} + echo -e "\t${LOGROTATE_INTERVAL:-weekly}" >> ${logrotate_filename} + echo -e "\trotate ${LOGROTATE_RETENTION:-6}" >> ${logrotate_filename} + + if [ ${LOGROTATE_COMPRESSION_ENABLED:-true} = true ] + then + echo -e "\tcompress" >> ${logrotate_filename} + fi + + if [ ${LOGROTATE_DELAYCOMPRESSION_ENABLED:-true} = true ] + then + echo -e "\tdelaycompress" >> ${logrotate_filename} + fi + + if [ ${LOGROTATE_MISSINGOK_ENABLED:-true} = true ] + then + echo -e "\tmissingok" >> ${logrotate_filename} + fi + + if [ ${LOGROTATE_NOTIFEMPTY_ENABLED:-true} = true ] + then + echo -e "\tnotifempty" >> ${logrotate_filename} + fi + + echo -e "}" >> ${logrotate_filename} +fi \ No newline at end of file From 921820ccbcc24fd5ffc0fcbda11db74e8335ac8e Mon Sep 17 00:00:00 2001 From: charlyforot Date: Fri, 3 Mar 2023 15:30:19 +0100 Subject: [PATCH 2/8] add empty line at the end of the bash scrit for configure logrotate --- rootfs/etc/cont-init.d/09-config-logrotate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootfs/etc/cont-init.d/09-config-logrotate.sh b/rootfs/etc/cont-init.d/09-config-logrotate.sh index a4bc778d..5614d7a9 100644 --- a/rootfs/etc/cont-init.d/09-config-logrotate.sh +++ b/rootfs/etc/cont-init.d/09-config-logrotate.sh @@ -33,4 +33,4 @@ then fi echo -e "}" >> ${logrotate_filename} -fi \ No newline at end of file +fi From fe1f04f13621e76b5dc4be45ca5d6250ddb540b9 Mon Sep 17 00:00:00 2001 From: charlyforot Date: Fri, 3 Mar 2023 15:30:35 +0100 Subject: [PATCH 3/8] update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 684e5044..a6135533 100644 --- a/README.md +++ b/README.md @@ -170,8 +170,8 @@ Image: librenms/librenms:latest > When activated, logs exceeding the specified retention period `LOGROTATE_RETENTION` will be deleted * `LOGROTATE_ENABLED`: Set to `true` to enable logrotate for this container (default `false`) -* `LOGROTATE_INTERVAL`: daily, weekly, monthly, or yearly (default `weekly`) -* `LOGROTATE_RETENTION`: lifetime of the log file (default `6`) +* `LOGROTATE_INTERVAL`: Set to `daily`, `weekly`, `monthly`, or `yearly` (default `weekly`) +* `LOGROTATE_RETENTION`: Lifetime of the log file (default `6`) * `LOGROTATE_COMPRESSION_ENABLED`: Set to `true` to enable logrotate `compress` option (default `true`) * `LOGROTATE_DELAYCOMPRESSION_ENABLED`: Set to `true` to enable logrotate `delaycompress` option (default `true`) * `LOGROTATE_MISSINGOK_ENABLED`: Set to `true` to enable logrotate `missingok` option (default `true`) From 62e99c186ddb600c23aaecbe31f6d4894281cf49 Mon Sep 17 00:00:00 2001 From: charlyforot Date: Fri, 3 Mar 2023 15:31:34 +0100 Subject: [PATCH 4/8] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a6135533..a9372877 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ Image: librenms/librenms:latest > **Warning** > -> When activated, logs exceeding the specified retention period `LOGROTATE_RETENTION` will be deleted +> When activated, logs exceeding the specified retention period `LOGROTATE_RETENTION` will be deleted. * `LOGROTATE_ENABLED`: Set to `true` to enable logrotate for this container (default `false`) * `LOGROTATE_INTERVAL`: Set to `daily`, `weekly`, `monthly`, or `yearly` (default `weekly`) From a24b3c6d15cf2000273620944d1f32679f892ebf Mon Sep 17 00:00:00 2001 From: charlyforot Date: Mon, 1 May 2023 10:19:12 +0200 Subject: [PATCH 5/8] remove config variable for logrotate --- README.md | 10 ++----- rootfs/etc/cont-init.d/09-config-logrotate.sh | 29 ++++--------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a9372877..472951ba 100644 --- a/README.md +++ b/README.md @@ -163,19 +163,13 @@ Image: librenms/librenms:latest > **Note** > -> Logrotate variables could be set on all containers to avoid large log files. +> Logrotate could be enabled to avoid large log files. > **Warning** > -> When activated, logs exceeding the specified retention period `LOGROTATE_RETENTION` will be deleted. +> When activated, logs exceeding the specified retention period will be deleted. * `LOGROTATE_ENABLED`: Set to `true` to enable logrotate for this container (default `false`) -* `LOGROTATE_INTERVAL`: Set to `daily`, `weekly`, `monthly`, or `yearly` (default `weekly`) -* `LOGROTATE_RETENTION`: Lifetime of the log file (default `6`) -* `LOGROTATE_COMPRESSION_ENABLED`: Set to `true` to enable logrotate `compress` option (default `true`) -* `LOGROTATE_DELAYCOMPRESSION_ENABLED`: Set to `true` to enable logrotate `delaycompress` option (default `true`) -* `LOGROTATE_MISSINGOK_ENABLED`: Set to `true` to enable logrotate `missingok` option (default `true`) -* `LOGROTATE_NOTIFEMPTY_ENABLED`: Set to `true` to enable logrotate `notifempty` option (default `true`) ### Syslog-ng diff --git a/rootfs/etc/cont-init.d/09-config-logrotate.sh b/rootfs/etc/cont-init.d/09-config-logrotate.sh index 5614d7a9..8055740a 100644 --- a/rootfs/etc/cont-init.d/09-config-logrotate.sh +++ b/rootfs/etc/cont-init.d/09-config-logrotate.sh @@ -9,28 +9,11 @@ then echo -e "${LIBRENMS_PATH}/logs/*.log {" > ${logrotate_filename} echo -e "\tsu librenms librenms" >> ${logrotate_filename} echo -e "\tcreate 664 librenms librenms" >> ${logrotate_filename} - echo -e "\t${LOGROTATE_INTERVAL:-weekly}" >> ${logrotate_filename} - echo -e "\trotate ${LOGROTATE_RETENTION:-6}" >> ${logrotate_filename} - - if [ ${LOGROTATE_COMPRESSION_ENABLED:-true} = true ] - then - echo -e "\tcompress" >> ${logrotate_filename} - fi - - if [ ${LOGROTATE_DELAYCOMPRESSION_ENABLED:-true} = true ] - then - echo -e "\tdelaycompress" >> ${logrotate_filename} - fi - - if [ ${LOGROTATE_MISSINGOK_ENABLED:-true} = true ] - then - echo -e "\tmissingok" >> ${logrotate_filename} - fi - - if [ ${LOGROTATE_NOTIFEMPTY_ENABLED:-true} = true ] - then - echo -e "\tnotifempty" >> ${logrotate_filename} - fi - + echo -e "\tweekly" >> ${logrotate_filename} + echo -e "\trotate 6" >> ${logrotate_filename} + echo -e "\tcompress" >> ${logrotate_filename} + echo -e "\tdelaycompress" >> ${logrotate_filename} + echo -e "\tmissingok" >> ${logrotate_filename} + echo -e "\tnotifempty" >> ${logrotate_filename} echo -e "}" >> ${logrotate_filename} fi From 3bfc1ee207324471f88a3f4de90f8b55ab2e58bb Mon Sep 17 00:00:00 2001 From: Charly Forot <97433029+charlyforot@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:35:28 +0100 Subject: [PATCH 6/8] Update README.md Co-authored-by: CrazyMax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 472951ba..cf2ab29a 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ Image: librenms/librenms:latest > > When activated, logs exceeding the specified retention period will be deleted. -* `LOGROTATE_ENABLED`: Set to `true` to enable logrotate for this container (default `false`) +* `LOGROTATE_ENABLED`: Set to `true` to enable logrotate for LibreNMS logs (default `false`) ### Syslog-ng From ec23e8b2d4f6bab3674f8621f6862303c94f285f Mon Sep 17 00:00:00 2001 From: charlyforot Date: Tue, 31 Oct 2023 10:19:30 +0100 Subject: [PATCH 7/8] include logrotate config into 03-config.sh --- rootfs/etc/cont-init.d/03-config.sh | 19 +++++++++++++++++++ rootfs/etc/cont-init.d/09-config-logrotate.sh | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 rootfs/etc/cont-init.d/09-config-logrotate.sh diff --git a/rootfs/etc/cont-init.d/03-config.sh b/rootfs/etc/cont-init.d/03-config.sh index 18402aa5..42991ec2 100644 --- a/rootfs/etc/cont-init.d/03-config.sh +++ b/rootfs/etc/cont-init.d/03-config.sh @@ -257,3 +257,22 @@ for template in ${templates}; do echo " Adding ${template} alert template" ln -sf /data/alert-templates/${template} ${LIBRENMS_PATH}/resources/views/alerts/templates/${template} done + +# Configure logrotate if enabled except for syslogng and snmptrapd sidecars +if [ ${LOGROTATE_ENABLED:-false} = true ] && [ "$SIDECAR_SYSLOGNG" != "1" ] && [ "$SIDECAR_SNMPTRAPD" != "1" ]; +then + cat <<'EOF' > /etc/logrotate.d/librenms + ${LIBRENMS_PATH}/logs/*.log { + su librenms librenms + create 664 librenms librenms + weekly + rotate 6 + compress + delaycompress + missingok + notifempty + copytruncate + } +EOF + +fi \ No newline at end of file diff --git a/rootfs/etc/cont-init.d/09-config-logrotate.sh b/rootfs/etc/cont-init.d/09-config-logrotate.sh deleted file mode 100644 index 8055740a..00000000 --- a/rootfs/etc/cont-init.d/09-config-logrotate.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash -set -e - -if [ ${LOGROTATE_ENABLED:-false} = true ] -then - logrotate_filename="/etc/logrotate.d/librenms" - - echo -e "${LIBRENMS_PATH}/logs/*.log {" > ${logrotate_filename} - echo -e "\tsu librenms librenms" >> ${logrotate_filename} - echo -e "\tcreate 664 librenms librenms" >> ${logrotate_filename} - echo -e "\tweekly" >> ${logrotate_filename} - echo -e "\trotate 6" >> ${logrotate_filename} - echo -e "\tcompress" >> ${logrotate_filename} - echo -e "\tdelaycompress" >> ${logrotate_filename} - echo -e "\tmissingok" >> ${logrotate_filename} - echo -e "\tnotifempty" >> ${logrotate_filename} - echo -e "}" >> ${logrotate_filename} -fi From 6534c6b2b796d64100c223874eb37baebcec541b Mon Sep 17 00:00:00 2001 From: charlyforot Date: Tue, 31 Oct 2023 10:20:29 +0100 Subject: [PATCH 8/8] add empty end line into 03-config.sh --- rootfs/etc/cont-init.d/03-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootfs/etc/cont-init.d/03-config.sh b/rootfs/etc/cont-init.d/03-config.sh index 42991ec2..d5dbb634 100644 --- a/rootfs/etc/cont-init.d/03-config.sh +++ b/rootfs/etc/cont-init.d/03-config.sh @@ -275,4 +275,4 @@ then } EOF -fi \ No newline at end of file +fi