mardi 2 octobre 2012

Logwatch sous debian: Cas particulier avec Atmailserver et Zimbra

C'est un article inspiré de ceci:

Pré-requis:
Il faut que Zimbra ou Atmailserver soit installé et est opérationnel.

Mise à jour du système

apt-get update
apt-get upgrade

Installation de Logwatch

apt-get install logwatch


Configuration de Logwatch

Editer le fichier de configuration de Logwatch
vim /usr/share/logwatch/default.conf/logwatch.conf

Changer les lignes suivantes:

Output = file
Format = html
Filename = /tmp/logwatch
Detail = 10

Pour le format html

Il manque les fichiers pour le format html.Il parrait que c'est un bug.
Il faut créer les fichiers suivants:

vim /usr/share/logwatch/default.conf/html/header.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Logwatch $Version ( $VDate )</title>
<meta name="generator" content="Logwatch $Version ( $VDate )">
<style type="text/css">
h1 {color: gray; border-bottom: 3px double silver}
h2,h3 {color: gray; border-bottom: 1px solid silver}
.ref {padding-left: 1%}
.service {padding-left: 1%; font-family: Monospace}
.return_link {border-top: 1px; border-bottom: 1px;
padding: 1%; margin-top: 1%; margin-bottom: 1%;}
.copyright {color: black; border-top: 1px solid grey;
border-bottom: 1px solid grey;
padding: 1%; margin-top: 1%; margin-bottom: 1%;}
</style>
</head>
<body style="width:90%; margin-left: 5%; margin-right: 5%" bgcolor="#FFFFFF">
<hr>
<!-- End header.html -->


vim /usr/share/logwatch/default.conf/html/footer.html
<!-- Start footer.html -->
<div class=\"copyright\">
<hr>
<p>Logwatch &copy;Copyright 2002-2006 Kirk Bauer</p>
<p>
L'autorisation est accordée, à titre gratuit, à toute personne obtenant une copie de
ce logiciel et des fichiers de documentation associés (le «Logiciel»), pour faire face au
Logiciel sans restriction, y compris, sans s'y limiter, les droits à 
utiliser, copier, modifier, fusionner, publier, distribuer, sous-licencier et / ou vendre des copies
du Logiciel, et d'autoriser les personnes auxquelles le Logiciel est fourni de faire de
donc, sous réserve des conditions suivantes:

</p>
<p>
L'avis de copyright ci-dessus et la présente autorisation doivent être inclus dans tous les
les copies ou parties substantielles du Logiciel.

<p>
LE LOGICIEL EST FOURNI «TEL QUEL», SANS GARANTIE D'AUCUNE SORTE, EXPRESSE OU
IMPLICITE, Y COMPRIS, MAIS SANS S'Y LIMITER, LES GARANTIES DE QUALITÉ MARCHANDE,
D'ADEQUATION A UN USAGE PARTICULIER ET D'ABSENCE DE CONTREFAÇON. EN AUCUN CAS, LES
AUTEURS OU LES TITULAIRES DU DROIT D'AUTEUR NE SERA RESPONSABLE DE TOUT DOMMAGE, RÉCLAMATION OU AUTRE
RESPONSABILITÉ, QUE CE SOIT DANS LE CADRE D'UN CONTRAT, UN DÉLIT OU AUTRE, PROVENANT DE,
DE OU EN RELATION AVEC LE LOGICIEL OU L'UTILISATION OU D'AUTRES ELEMENTS DU
LOGICIEL.

</p></div>
</body></html>
 

Tache journalière (envoie mail)

C'est dans cette partie qui diffère les deux systèmes (Zimbra et Atmailserver) de la configuration par défaut:

Editer le fichier:
vim /etc/cron.daily/00logwatch

Pour Atmailserver:

Voici ce qu'il faut mettre:
#!/bin/bash
#
/usr/sbin/logwatch
chmod o+r /tmp/logwatch
echo "From: logwatch@mydomain.tld" > /tmp/logwatch.mail
echo "To: admin@mydomain.tld" >> /tmp/logwatch.mail
echo "Subject: Logwatch for Server (Linux)" >> /tmp/logwatch.mail
echo "MIME-Version: 1.0" >> /tmp/logwatch.mail
echo "Content-Transfer-Encoding: 7bit" >> /tmp/logwatch.mail
echo "Content-Type: text/html; charset=\"iso-8859-1\"" >> /tmp/logwatch.mail
cat /tmp/logwatch >> /tmp/logwatch.mail
/usr/local/atmail/mailserver/bin/exim -v 'admin@mydomain.tld' < /tmp/logwatch.mail
#

Pour Zimbra:

#!/bin/bash
#
/usr/sbin/logwatch
chmod o+r /tmp/logwatch
echo "From: logwatch@mydomain.tld" > /tmp/logwatch.mail
echo "To: admin@mydomain.tld" >> /tmp/logwatch.mail
echo "Subject: Logwatch for Server (Linux)" >> /tmp/logwatch.mail
echo "MIME-Version: 1.0" >> /tmp/logwatch.mail
echo "Content-Transfer-Encoding: 7bit" >> /tmp/logwatch.mail
echo "Content-Type: text/html; charset=\"iso-8859-1\"" >> /tmp/logwatch.mail
cat /tmp/logwatch >> /tmp/logwatch.mail
cat /tmp/logwatch.mail |/opt/zimbra/postfix/sbin/sendmail admin@mydomain.tld

Vérifiez le fonctionnement

Lancer la commande:

/etc/cron.daily/00logwatch

Pour voir le résultat, consultez vos mails.