mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
logmngr: add logread and default uci config
* all logging packages have a custom implmentation for logread, which is a command that can be invoked to view the logs. Hence, it makes sense for logmngr to have a logread to accompany it as well. Support for the same is added via this commit. * the approach is simplistic and follows syslog-ng with the slight enhancement of reading the logfile from logmngr uci * support to generate default uci config for logmngr which is to write logs to /var/log/messages
This commit is contained in:
parent
1b1598273d
commit
91e9278cba
3 changed files with 138 additions and 2 deletions
|
|
@ -49,10 +49,16 @@ define Build/Compile
|
|||
endef
|
||||
|
||||
define Package/logmngr/install
|
||||
$(INSTALL_DIR) $(1)/lib/logmngr
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
|
||||
$(INSTALL_BIN) ./files/logmngr.init $(1)/etc/init.d/logmngr
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) ./files/logread $(1)/usr/sbin
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/10-logmngr_config_generate $(1)/etc/uci-defaults/
|
||||
|
||||
$(INSTALL_DIR) $(1)/lib/logmngr
|
||||
ifeq ($(CONFIG_LOGMNGR_BACKEND_FLUENTBIT),y)
|
||||
$(INSTALL_DATA) ./files/lib/logmngr/fluent-bit.sh $(1)/lib/logmngr/.
|
||||
endif
|
||||
|
|
|
|||
22
logmngr/files/10-logmngr_config_generate
Normal file
22
logmngr/files/10-logmngr_config_generate
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ -s "/etc/config/logmngr" ]; then
|
||||
if uci -q get logmngr.@globals[0] >/dev/null; then
|
||||
# return if there is any valid content
|
||||
exit
|
||||
else
|
||||
rm -f /etc/config/logmngr
|
||||
fi
|
||||
fi
|
||||
touch /etc/config/logmngr
|
||||
|
||||
uci set logmngr.globals=globals
|
||||
uci set logmngr.globals.enable=1
|
||||
|
||||
uci set logmngr.a1=action
|
||||
uci set logmngr.a1.name="ac1"
|
||||
|
||||
uci set logmngr.lf1=log_file
|
||||
uci set logmngr.lf1.enable=1
|
||||
uci set logmngr.lf1.action="ac1"
|
||||
uci set logmngr.lf1.file="/var/log/messages"
|
||||
108
logmngr/files/logread
Normal file
108
logmngr/files/logread
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#!/bin/sh
|
||||
# Shell script compatibility wrapper for /sbin/logread
|
||||
#
|
||||
# Copyright (C) 2019 Dirk Brenken <dev@brenken.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
# use /var/log/messages as default
|
||||
logfile="/var/log/messages"
|
||||
|
||||
|
||||
handle_log_file() {
|
||||
local section="$1"
|
||||
|
||||
local enabled
|
||||
config_get enabled $section enable
|
||||
if [ "$enabled" == 0 ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local file
|
||||
config_get file $section file
|
||||
if [ -z "$file" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
logfile="$file"
|
||||
}
|
||||
|
||||
config_load logmngr
|
||||
config_get logmngr_enabled globals enable
|
||||
if [ "$logmngr_enabled" == "0" ]; then
|
||||
printf "%s\n" "Error: logmngr is not enabled!"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# treat the last enabled log_file as logfile
|
||||
config_foreach handle_log_file log_file
|
||||
|
||||
if [ ! -f "${logfile}" ]
|
||||
then
|
||||
printf "%s\n" "Error: logfile $logfile not found!"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
usage()
|
||||
{
|
||||
printf "%s\n" "Usage: logread [options]"
|
||||
printf "%s\n" "Options:"
|
||||
printf "%5s %-10s%s\n" "-l" "<count>" "Got only the last 'count' messages"
|
||||
printf "%5s %-10s%s\n" "-e" "<pattern>" "Filter messages with a regexp"
|
||||
printf "%5s %-10s%s\n" "-f" "" "Follow log messages"
|
||||
printf "%5s %-10s%s\n" "-h" "" "Print this help message"
|
||||
}
|
||||
|
||||
if [ -z "${1}" ]
|
||||
then
|
||||
cat "${logfile}"
|
||||
exit 0
|
||||
else
|
||||
while [ "${1}" ]
|
||||
do
|
||||
case "${1}" in
|
||||
-l)
|
||||
shift
|
||||
count="${1//[^0-9]/}"
|
||||
tail -n "${count:-50}" "${logfile}"
|
||||
exit 0
|
||||
;;
|
||||
-e)
|
||||
shift
|
||||
pattern="${1}"
|
||||
grep -E "${pattern}" "${logfile}"
|
||||
exit 0
|
||||
;;
|
||||
-f)
|
||||
tail -f "${logfile}"
|
||||
exit 0
|
||||
;;
|
||||
-fe)
|
||||
shift
|
||||
pattern="${1}"
|
||||
tail -f "${logfile}" | grep -E "${pattern}"
|
||||
exit 0
|
||||
;;
|
||||
-h|*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
fi
|
||||
Loading…
Add table
Reference in a new issue