aboutsummaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
authorGiacomo Sanchietti <giacomo.sanchietti@nethesis.it>2022-05-12 17:58:25 +0200
committerRosen Penev <rosenp@gmail.com>2022-07-07 10:34:58 -0700
commit443bc5720eced80e7bc32e71c11769d6e3103f81 (patch)
tree9bf26c3659c7d4765e976614b7fb3b1ec90e9fe7 /admin
parent23eb031777e1cf1065dc0fc9824b1a08d263797d (diff)
rsyslog: add uci support
Signed-off-by: Giacomo Sanchietti <giacomo.sanchietti@nethesis.it>
Diffstat (limited to 'admin')
3 files changed, 122 insertions, 0 deletions
diff --git a/admin/rsyslog/Makefile b/admin/rsyslog/Makefile
index 596fb2e25..a93595df1 100644
--- a/admin/rsyslog/Makefile
+++ b/admin/rsyslog/Makefile
@@ -72,6 +72,8 @@ define Package/rsyslog/install
$(INSTALL_CONF) ./files/rsyslog.conf $(1)/etc
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/rsyslog.init $(1)/etc/init.d/rsyslog
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_CONF) ./files/rsyslog $(1)/etc/config
endef
define Package/rsyslog/config
diff --git a/admin/rsyslog/files/rsyslog b/admin/rsyslog/files/rsyslog
new file mode 100644
index 000000000..b4cd422f6
--- /dev/null
+++ b/admin/rsyslog/files/rsyslog
@@ -0,0 +1,28 @@
+config syslog syslog
+ option tcp_input '0'
+ option tcp_input_port '514'
+ option udp_input '1'
+ option udp_input_port '514'
+ option default_template 'RSYSLOG_TraditionalFileFormat'
+ list modules 'imuxsock'
+ list modules 'imklog'
+
+config selector
+ option source '*.info;mail.none;authpriv.none;cron.none'
+ option destination '/var/log/messages'
+
+config selector
+ option source 'authpriv.*'
+ option destination '/var/log/secure'
+
+config selector
+ option source 'mail.*'
+ option destination '/var/log/maillog'
+
+config selector
+ option source 'cron.*'
+ option destination '/var/log/cron'
+
+config selector
+ option source 'local7.*'
+ option destination '/var/log/boot.log'
diff --git a/admin/rsyslog/files/rsyslog.init b/admin/rsyslog/files/rsyslog.init
index 20eb2a41f..496308e03 100644
--- a/admin/rsyslog/files/rsyslog.init
+++ b/admin/rsyslog/files/rsyslog.init
@@ -5,8 +5,100 @@ START=20
USE_PROCD=1
+UCI_CONF="rsyslog"
+CONFIG_FILE="/etc/rsyslog.conf"
+
+modules=""
+selectors=""
+forwarders=""
+
+handle_selector() {
+ local config="$1"
+ local src
+ local dst
+
+ config_get src ${config} source
+ config_get dst ${config} destination
+ if [ ${src} != "" ] && [ "$dst" != "" ]; then
+ selectors="${selectors}\n${src}\t${dst}\n"
+ fi
+}
+
+handle_forwarder() {
+ local config="$1"
+ local src
+ local target
+ local protocol
+ local port
+ local rfc
+ local opts
+
+ config_get src ${config} source
+ config_get target ${config} target
+ config_get protocol ${config} protocol "udp"
+ config_get port ${config} port "514"
+ config_get rfc ${config} rfc "3164"
+
+ if [ "$rfc" == "5424" ]; then
+ opts='Template="RSYSLOG_SyslogProtocol23Format" TCP_Framing="octet-counted"'
+ fi
+
+ if [ ${src} != "" ] && [ "${target}" != "" ]; then
+ action="action(type=\"omfwd\" target=\"$target\" port=\"$port\" protocol=\"$protocol\" $opts action.resumeRetryCount=\"100\" queue.type=\"linkedList\" queue.size=\"10000\")"
+ forwarders="${forwarders}\n${src}\t${action}\n"
+ fi
+}
+
+
+expand_config() {
+ local input_t=""
+ local input_u=""
+
+ config_load ${UCI_CONF}
+ config_list_foreach syslog modules handle_module
+ config_get_bool tcp_input syslog tcp_input
+ if [ ${tcp_input} -eq 1 ]; then
+ modules="${modules} imtcp"
+ config_get tcp_port syslog tcp_input_port
+ input_t="input(type=\"imtcp\" port=\"${tcp_port}\")"
+ fi
+
+ config_get_bool udp_input syslog udp_input
+ if [ ${udp_input} -eq 1 ]; then
+ modules="${modules} imudp"
+ config_get udp_port syslog udp_input_port
+ input_u="input(type=\"imudp\" port=\"${udp_port}\")"
+
+ fi
+ config_get template syslog default_template
+ config_foreach handle_selector selector
+ config_foreach handle_forwarder forwarder
+
+ > ${CONFIG_FILE}
+ for m in ${modules}; do
+ echo "module(load=\"${m}\")" >> ${CONFIG_FILE}
+ done
+ echo ${input_t} >> ${CONFIG_FILE}
+ echo ${input_u} >> ${CONFIG_FILE}
+ echo "\$ActionFileDefaultTemplate ${template}" >> ${CONFIG_FILE}
+ echo -e ${selectors} >> ${CONFIG_FILE}
+ echo -e ${forwarders} >> ${CONFIG_FILE}
+}
+
+handle_module() {
+ local module="$1"
+ modules="${modules} $module"
+}
+
start_service() {
+ expand_config
procd_open_instance
procd_set_param command /usr/sbin/rsyslogd -n
procd_close_instance
}
+
+
+service_triggers()
+{
+ procd_add_reload_trigger ${UCI_CONF}
+}