[Logcheck-devel] Bug#630721: logcheck: improve support for non-POSIX charsets in generated report
Nenad Cimerman
ncimerman at googlemail.com
Thu Jun 16 14:38:49 UTC 2011
Package: logcheck
Version: 1.2.69
Severity: normal
Tags: l10n
My system is setup with non-POSIX default locale (see below), using UTF-8
character encoding.
This leads to many lines inside various log files (e.g. /var/log/syslog)
containing 'german umlaut' characters (äöüÄÖÜß). During normal system usage
in bash, less, vi etc. everything works as expected - all characters are shown
correctly.
However, logcheck behaves different: report sent by e-mail contain unreadable
characters instead of 'german umlaut' characters.
Before sending this bug report, I investigated thoroughly what is causing the
problem and was able to find the culprit. I was also able to solve the problem
for me - but it did cost me a couple of hours, which is driving me to report
this as a bug.
To be clear about this issue: I'm totally aware, that system log files may
contain all kind of encoded characters, making this problem really unsolvable
in a 100% complete manner.
On the other hand, in real life things can be improved significantly, using a
more lax approach. In fact I believe, that most systems are using only one
locale for system administration, which makes the solution of this problem (at
least in my case) quite simple.
........Details.......
The script /usr/sbin/logcheck is usually run by the cron deamon, based on
/etc/cron.d/logcheck. This process runs in POSIX locale (LC_ALL=POSIX,
LANG=POSIX), despite /etc/default/locale being possibly set to a different
locale.
Inside /usr/sbin/logcheck, the function sendreport() uses mail(1) or nail(1)
to deliver the report via e-mail. Additionally, sending report as an
attachment depends on nail(1) beeing installed.
By default, reports are sent 'inline' (not as an attachment), which results
in mail(1) beeing used.
Unfortunately mail(1) is responsible for the characterset issue, as it does
ignore the locale settings completely.
All of this could be simplified and improved, when using mutt(1) instead:
+ produces correct encoding of e-mails, depending on locale settings
+ is able to send attachments using '-a' option
In my case, I did the following to solve the problem:
1. added the following line to /etc/cron.d/logcheck
LC_ALL=de_DE.UTF-8
2. changed sendreport() funtion in /usr/sbin/logcheck:
sendreport() {
MAILER=${MAILER:-mutt}
if [ $REBOOT -eq 1 ]; then
subject="Reboot: $HOSTNAME $DATE $*"
else
subject="$HOSTNAME $DATE $*"
fi
if [ $ADDTAG = "yes" ]; then
subject="[logcheck] $subject"
fi
if [ $MAILOUT -eq 1 ]; then
debug "Sending report to STDOUT"
cat $TMPDIR/report
debug "Sent report to STDOUT"
else
debug "Sending report: '$subject' to $SENDMAILTO"
if [ $MAILASATTACH -eq 1 ]; then
debug "Sending report as attachment"
if command -v $MAILER >/dev/null; then
echo -e "Report attached" | $MAILER -s "$subject" -a "$TMPDIR/report" "$SENDMAILTO"
return $?
else
echo >> $TMPDIR/report
echo Could not send report as attachment, $MAILER not installed >> $TMPDIR/report
fi
fi
cat $TMPDIR/report | $MAILER -s "$subject" "$SENDMAILTO"
fi
}
Here is the diff-output showing my changes:
# diff /usr/sbin/logcheck logcheck
284d283
< MAILER=${MAILER:-mutt}
302,303c301,302
< if command -v $MAILER >/dev/null; then
< echo -e "Report attached" | $MAILER -s "$subject" -a "$TMPDIR/report" "$SENDMAILTO"
---
> if command -v nail >/dev/null; then
> echo -e "Report attached" | nail -s "$subject" -a "$TMPDIR/report" "$SENDMAILTO"
307c306
< echo Could not send report as attachment, $MAILER not installed >> $TMPDIR/report
---
> echo Could not send report as attachment, nail not installed >> $TMPDIR/report
310c309
< cat $TMPDIR/report | $MAILER -s "$subject" "$SENDMAILTO"
---
> cat $TMPDIR/report | mail -s "$subject" "$SENDMAILTO"
319a319
>
Regards,
Nenad.
-- System Information:
Debian Release: 5.0.8
APT prefers oldstable
APT policy: (500, 'oldstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.26-2-686 (SMP w/1 CPU core)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages logcheck depends on:
ii adduser 3.110 add and remove users and groups
ii bsd-mailx [mailx] 8.1.2-0.20071201cvs-3 A simple mail user agent
ii cron 3.0pl1-105 management of regular background p
ii exim4 4.69-9+lenny4 metapackage to ease Exim MTA (v4)
ii exim4-daemon-heavy 4.69-9+lenny4 Exim MTA (v4) daemon with extended
ii lockfile-progs 0.1.11-0.1 Programs for locking and unlocking
ii logtail 1.2.69 Print log file lines that have not
ii mailx 1:20071201-3 Transitional package for mailx ren
ii rsyslog [system-lo 3.18.6-4 enhanced multi-threaded syslogd
Versions of packages logcheck recommends:
ii logcheck-database 1.2.69 database of system log rules for t
Versions of packages logcheck suggests:
pn syslog-summary <none> (no description available)
-- no debconf information
More information about the Logcheck-devel
mailing list