diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a475c7..1b78322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 7.7.5 2022-08-11 + + ### Added + - Fluent-bit 1.9.7 + - Customizable compssion types for logrotate, now defaults to using zstd + - Function for zcat to handle bz/xz/gz/zst + + ### Changed + - Fix error when CRON_PERIOD exists as a default or environment variable + + ## 7.7.4 2022-08-06 ### Added diff --git a/README.md b/README.md index 0b98458..d48f205 100644 --- a/README.md +++ b/README.md @@ -248,12 +248,15 @@ This image supports autoregistering configuration as an Active Agent to a Zabbix This is work in progress for a larger logging solution. Presently there is functionality to rotate logs on a daily basis, however as this section matures there will be the capability to also ship the logs to an external data warehouse like Loki, or Elastic Search. At present Log shipping is only supported by `fluent-bit` and x86_64 only. -| Parameter | Description | Default | -| ------------------------------- | ---------------------------------------- | ------------ | -| `CONTAINER_ENABLE_LOGROTATE` | Enable Logrotate (if scheduling enabled) | `TRUE` | -| `CONTAINER_ENABLE_LOGSHIPPING` | Enable Log Shipping | `FALSE` | -| `CONTAINER_LOGSHIPPING_BACKEND` | Log shipping backend `fluent-bit` | `fluent-bit` | -| `LOGROTATE_RETAIN_DAYS` | Rotate and retain logs for x days | `7` | +| Parameter | Description | Default | +| ---------------------------------------- | ----------------------------------------------------------- | ------------ | +| `CONTAINER_ENABLE_LOGROTATE` | Enable Logrotate (if scheduling enabled) | `TRUE` | +| `CONTAINER_ENABLE_LOGSHIPPING` | Enable Log Shipping | `FALSE` | +| `CONTAINER_LOGSHIPPING_BACKEND` | Log shipping backend `fluent-bit` | `fluent-bit` | +| `LOGROTATE_COMPRESSION_TYPE` | Logfile compression algorithm `NONE` `BZIP2` `GZIP` `ZSTD` | `ZSTD` | +| `LOGROTATE_COMPRESSION_VALUE` | What level of compression to use | `8` | +| `LOGROTATE_COMPRESSION_EXTRA_PARAMETERS` | Pass extra parameters to the compression command (optional) | | +| `LOGROTATE_RETAIN_DAYS` | Rotate and retain logs for x days | `7` | ##### Log Shipping Parsing diff --git a/install/assets/defaults/05-logging b/install/assets/defaults/05-logging index fe3df81..1f379a7 100755 --- a/install/assets/defaults/05-logging +++ b/install/assets/defaults/05-logging @@ -41,5 +41,12 @@ FLUENTBIT_TAIL_KEY_PATH_ENABLE=${FLUENTBIT_TAIL_KEY_PATH_ENABLE:-"TRUE"} FLUENTBIT_TAIL_KEY_PATH=${FLUENTBIT_TAIL_KEY_PATH:-"filename"} FLUENTBIT_TAIL_KEY_OFFSET_ENABLE=${FLUENTBIT_TAIL_KEY_OFFSET_ENABLE:-"FALSE"} FLUENTBIT_TAIL_KEY_OFFSET=${FLUENTBIT_TAIL_KEY_OFFSET:-"offset"} + +case "$(cat /etc/os-release | grep VERSION_ID | cut -d = -f 2 | cut -d . -f 1,2)" in + "3.5" ) LOGROTATE_COMPRESSION_TYPE="gzip" ;; + *) LOGROTATE_COMPRESSION_TYPE=${LOGROTATE_COMPRESSION_TYPE:-"zstd"} ;; +esac + +LOGROTATE_COMPRESSION_VALUE=${LOGROTATE_COMPRESSION_VALUE:-"8"} LOGROTATE_RETAIN_DAYS=${LOGROTATE_RETAIN_DAYS:-"7"} -LOGSHIPPING_AUTO_CONFIG_LOGROTATE=${LOGSHIPPING_AUTO_CONFIG_LOGROTATE:-"TRUE"} \ No newline at end of file +LOGSHIPPING_AUTO_CONFIG_LOGROTATE=${LOGSHIPPING_AUTO_CONFIG_LOGROTATE:-"TRUE"} diff --git a/install/assets/functions/00-container b/install/assets/functions/00-container index 1eea75e..aa09ca6 100755 --- a/install/assets/functions/00-container +++ b/install/assets/functions/00-container @@ -88,13 +88,7 @@ create_logrotate() { cat < /assets/logrotate/"${1}" ${lrlsparser} $2 { - daily - ifempty - rotate ${LOGROTATE_RETAIN_DAYS} missingok - compress - dateext - copytruncate ${lruser} } EOF diff --git a/install/etc/cont-init.d/00-startup b/install/etc/cont-init.d/00-startup index fe8602f..e42ddf3 100755 --- a/install/etc/cont-init.d/00-startup +++ b/install/etc/cont-init.d/00-startup @@ -70,6 +70,22 @@ fi echo "export PS1=\"${bash_prompt/ /}\"" >> /root/.bashrc +cat <> /root/.bashrc + +zcat () { + if [ -f "\$@" ] ; then + case "\$@" in + *.zst* ) $(which zstdcat) "\$@" ;; + *.bz*) $(which zcat) "\$@" ;; + *.gz*) $(which zcat) "\$@" ;; + *.xz) $(which zcat) "\$@" ;; + esac + else + echo "'\$@' is not a valid file!" + fi +} +EOF + ## Add Support to list all Changelogs known of all base images if [ -d "/assets/.changelogs" ] ; then echo "image_version() { for clname in /assets/.changelogs/* ; do version=\$(head -n 1 \$clname | awk '{print \$2}') ; echo \"Image: $(basename \$clname) \$version\" ; done ;}" >> /root/.bashrc diff --git a/install/etc/cont-init.d/04-scheduling b/install/etc/cont-init.d/04-scheduling index ef33f16..d9307ac 100755 --- a/install/etc/cont-init.d/04-scheduling +++ b/install/etc/cont-init.d/04-scheduling @@ -34,6 +34,7 @@ else ## Docker Build and Runtime overrides cronenv=$(mktemp) set -o posix; set -f ; set | grep -E '^CRON_'| sed "s|CRON_||g" > ${cronenv} + sed -i "/^PERIOD/d" "${cronenv}" while IFS= read -r cron_entry; do schedule_title="$(echo ${cron_entry} | cut -d = -f1 | tr '[:upper:]' '[:lower:]' )" schedule_value="$(echo ${cron_entry} | cut -d = -f2 )" @@ -67,12 +68,12 @@ EOF # shellcheck source=/assets/defaults/ source $d cronenv=$(mktemp) - set -o posix; set -f ; set | grep -E '^CRON_'| sed "s|CRON_||g" > ${cronenv} + set -o posix; set -f ; set | grep -E '^CRON_'| sed "s|CRON_||g" > "${cronenv}" + sed -i "/^PERIOD/d" "${cronenv}" while IFS= read -r cron_entry; do schedule_title="$(echo ${cron_entry} | cut -d = -f1 | tr '[:upper:]' '[:lower:]')" schedule_value="$(echo ${cron_entry} | cut -d = -f2 )" schedule_value="$(echo ${schedule_value:1:-1})" - if [ ! -f "${CONTAINER_SCHEDULING_LOCATION}/${schedule_title,,}" ] ; then print_debug "Adding $schedule_title with value $schedule_value to crontab" cat < "${CONTAINER_SCHEDULING_LOCATION}/${schedule_title,,}" diff --git a/install/etc/cont-init.d/05-logging b/install/etc/cont-init.d/05-logging index 0fa5af0..b1f14a5 100755 --- a/install/etc/cont-init.d/05-logging +++ b/install/etc/cont-init.d/05-logging @@ -8,6 +8,51 @@ output_off if var_true "${CONTAINER_ENABLE_LOGROTATE}" ; then print_debug "Enabling log rotation" + case "${LOGROTATE_COMPRESSION_TYPE,,}" in + bz* ) + logrotate_compression=$(cat< /etc/logrotate.conf +daily +rotate ${LOGROTATE_RETAIN_DAYS} +copytruncate +dateext +nomail +notifempty +${logrotate_compression} +include /etc/logrotate.d +EOF + + chmod 0744 /etc/logrotate.conf mkdir -p "${CONTAINER_SCHEDULING_LOCATION}" cat < "${CONTAINER_SCHEDULING_LOCATION}"/logrotate # Hardcoded in image in /etc/cont-init.d/$(basename "$0")