From 5a7e44cd049310ce8874f045dd9404c919f9bf24 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Dutta Date: Thu, 20 Mar 2025 18:11:18 +0530 Subject: [PATCH] logmngr: include kernel logs --- logmngr/Makefile | 2 +- logmngr/files/lib/logmngr/fluent-bit.sh | 41 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/logmngr/Makefile b/logmngr/Makefile index 3c0e514a4..5e40cc6c4 100644 --- a/logmngr/Makefile +++ b/logmngr/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=logmngr -PKG_VERSION:=1.0.10 +PKG_VERSION:=1.0.11 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) diff --git a/logmngr/files/lib/logmngr/fluent-bit.sh b/logmngr/files/lib/logmngr/fluent-bit.sh index 7d07086e1..6d436a23d 100644 --- a/logmngr/files/lib/logmngr/fluent-bit.sh +++ b/logmngr/files/lib/logmngr/fluent-bit.sh @@ -20,10 +20,26 @@ create_service_section() { echo " daemon off" >> ${TMP_CONF_FILE} echo " log_level info" >> ${TMP_CONF_FILE} echo " parsers_file /etc/fluent-bit/parsers.conf" >> ${TMP_CONF_FILE} + echo "" >> ${TMP_CONF_FILE} + + # Generate default input for kmsg + echo "[INPUT]" >> ${TMP_CONF_FILE} + echo " name kmsg" >> ${TMP_CONF_FILE} + echo " Tag KMSG" >> ${TMP_CONF_FILE} + echo "" >> ${TMP_CONF_FILE} + + echo "[OUTPUT]" >> ${TMP_CONF_FILE} + echo " name file" >> ${TMP_CONF_FILE} + echo " match KMSG" >> ${TMP_CONF_FILE} + echo " file /var/log/messages" >> ${TMP_CONF_FILE} + echo " format template" >> ${TMP_CONF_FILE} + echo " template {sec}.{usec} {hostname} : {msg}" >> ${TMP_CONF_FILE} + echo "" >> ${TMP_CONF_FILE} } create_input_section() { local tag="$1" + # the input in our case is always syslog, hence, this section of the # fluent-bit.conf file has hardcoded values as well that do not depend # on any uci value @@ -31,6 +47,7 @@ create_input_section() { echo " name syslog" >> ${TMP_CONF_FILE} echo " tag $tag" >> ${TMP_CONF_FILE} echo " path /dev/log" >> ${TMP_CONF_FILE} + echo "" >> ${TMP_CONF_FILE} } generate_facility_regex() { @@ -281,8 +298,6 @@ handle_action() { # with this and action and setup output accordingly. config_foreach handle_log_file log_file "$tag" config_foreach handle_log_remote log_remote "$tag" - - } handle_action_section() { @@ -295,27 +310,29 @@ apply_config_file() { PROG=/usr/sbin/fluent-bit logmngr_init() { - create_config_file + local enabled config_load logmngr - local enabled - config_get enabled globals enable - - if [ "$enabled" == "0" ]; then - return - fi + config_get enabled globals enable "1" + create_config_file create_service_section handle_action_section - apply_config_file if [ -f /lib/logmngr/logrotate.sh ]; then logrotate_init fi procd_open_instance logmngr - procd_set_param command $PROG -c $CONF_FILE - procd_set_param file $CONF_FILE + if [ "$enabled" == "1" ]; then + if [ -s "${TMP_CONF_FILE}" ]; then + procd_set_param command $PROG -c ${TMP_CONF_FILE} + procd_set_param file ${TMP_CONF_FILE} + elif [ -s "${CONF_FILE}" ]; then + procd_set_param command $PROG -c ${CONF_FILE} + procd_set_param file ${CONF_FILE} + fi + fi procd_set_param respawn procd_close_instance }