Tags: patch Hello,
I have attempted to implement logcheck.logfiles.d directory support, patch is attached.
>From 63c41f4748730d99effec68492a7b23fa55a5d90 Mon Sep 17 00:00:00 2001 From: Vincas Dargis <vin...@gmail.com> Date: Sun, 14 Feb 2016 19:44:36 +0200 Subject: [PATCH] Add logcheck.logfiles.d support Signed-off-by: Vincas Dargis <vin...@gmail.com> --- Makefile | 2 ++ docs/logcheck.sgml | 8 ++++++++ src/logcheck | 23 ++++++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 7acec16..acd5bb6 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ install: install -m 2750 -d $(DESTDIR)/$(CONFDIR)/cracking.ignore.d install -m 2750 -d $(DESTDIR)/$(CONFDIR)/violations.d install -m 2750 -d $(DESTDIR)/$(CONFDIR)/violations.ignore.d + install -m 2750 -d $(DESTDIR)/$(CONFDIR)/logcheck.logfiles.d # Install the scripts install -m 755 src/logcheck $(DESTDIR)/$(SBINDIR)/ @@ -68,6 +69,7 @@ clean: -rm -rf $(DESTDIR)/$(CONFDIR)/violations.d/ -rm -rf $(DESTDIR)/$(CONFDIR)/violations.ignore.d/ -rm -rf $(DESTDIR)/$(CONFDIR)/cracking.d/ + -rm -rf $(DESTDIR)/$(CONFDIR)/logcheck.logfiles.d/ # Remove the statedir and it's contents -rm -rf $(DESTDIR)/var/lib/logcheck diff --git a/docs/logcheck.sgml b/docs/logcheck.sgml index 27a3429..b15a31f 100644 --- a/docs/logcheck.sgml +++ b/docs/logcheck.sgml @@ -149,6 +149,13 @@ manpage.1: manpage.sgml </listitem> </varlistentry> <varlistentry> + <term><option>-D DIR</option> + </term> + <listitem> + <para>Overrule default logfiles lists directory</para> + </listitem> + </varlistentry> + <varlistentry> <term><option>-m</option> </term> <listitem> @@ -239,6 +246,7 @@ manpage.1: manpage.sgml <para>/etc/logcheck/logcheck.conf is the main configuration file.</para> <para>/etc/logcheck/logcheck.logfiles is the list of files to monitor.</para> + <para>/etc/logcheck/logcheck.logfiles.d is the directory of lists of files to monitor.</para> <para>/usr/share/doc/logcheck-database/README.logcheck-database.gz for hints on how to write, test and maintain rules.</para> </refsect1> <refsect1> diff --git a/src/logcheck b/src/logcheck index a8d2d02..7fa36f5 100755 --- a/src/logcheck +++ b/src/logcheck @@ -73,6 +73,7 @@ RULEDIR="/etc/logcheck" CONFFILE="/etc/logcheck/logcheck.conf" STATEDIR="/var/lib/logcheck" LOGFILES_LIST="/etc/logcheck/logcheck.logfiles" +LOGFILES_LIST_D="/etc/logcheck/logcheck.logfiles.d" LOGFILE_FALLBACK="/var/log/syslog" LOGTAIL="/usr/sbin/logtail2" CAT="/bin/cat" @@ -444,7 +445,7 @@ logoutput() { usage() { debug "usage: Printing usage and exiting" cat<<EOF -usage: logcheck [-c CFG] [-d] [-h] [-H HOST] [-l LOG] [-L CFG] [-m MAIL] [-o] +usage: logcheck [-c CFG] [-d] [-h] [-H HOST] [-l LOG] [-L CFG] [-D DIR] [-m MAIL] [-o] [-r DIR] [-s|-p|-w] [-R] [-S DIR] [-t] [-T] [-u] -c CFG = override default configuration file -d = debug mode @@ -452,6 +453,7 @@ usage: logcheck [-c CFG] [-d] [-h] [-H HOST] [-l LOG] [-L CFG] [-m MAIL] [-o] -H HOST = use this hostname in the subject of any generated mail -l LOG = check the specified logfile -L CFG = override default logfiles list + -D DIR = override default logfiles lists directory -m MAIL = send the report to the specified recipient -o = send the report to stdout, no mail will be sent -p = use the "paranoid" runlevel @@ -553,6 +555,10 @@ while getopts "$GETOPTS" opt; do debug "Setting LOGFILES_LIST to $OPTARG" LOGFILES_LIST="$OPTARG" ;; + D) + debug "Setting LOGFILES_LIST_D to $OPTARG" + LOGFILES_LIST_D="$OPTARG" + ;; m) debug "Setting SENDMAILTO to $OPTARG" SENDMAILTO="$OPTARG" @@ -661,11 +667,18 @@ fi # Handle log rotation correctly, idea taken from Wiktor Niesiobedzki. mkdir "$TMPDIR/logoutput" \ || error "Could not mkdir for log files" -if [ ! "$LOGFILE" ] && [ -r "$LOGFILES_LIST" ]; then +if [ ! "$LOGFILE" ]; then SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); - for file in $(egrep --text -v "(^#|^[[:space:]]*$)" "$LOGFILES_LIST"); do - logoutput "$file" - done + if [ -r "$LOGFILES_LIST" ]; then + for file in $(egrep --text -v "(^#|^[[:space:]]*$)" "$LOGFILES_LIST"); do + logoutput "$file" + done + fi + if [ -d "$LOGFILES_LIST_D" ] && [ -r "$LOGFILES_LIST_D" ]; then + for file in $(egrep --text -v -h "(^#|^[[:space:]]*$)" "$LOGFILES_LIST_D"/*.logfiles); do + logoutput "$file" + done + fi IFS=$SAVEIFS elif [ "$LOGFILE" ]; then if [ -f "$LOGFILE" ] && [ -r "$LOGFILE" ]; then -- 1.9.1
_______________________________________________ Logcheck-devel mailing list Logcheck-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/logcheck-devel