Change email HTML output for Linux Logwatch

Author:
phil
Created:
Tuesday, October 27th, 2020
Last Updated:
Tuesday, October 27th, 2020

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


Do you use logwatch for your favorite linux distro?

Have you ever enabled the html option to get emails in html format?

Have you ever looked at the email and wished the output was easier to read and just looked more modern?

I set out to deal with these very issues and surprisingly after a bit of searching, didn't find anyone else talking about how to change the html styling for the email output of logwatch.

At the time of this writing, logwatch.org doesn't appear to be functioning or actively maintained by the original author. The latest version of logwatch available to my package manager is 7.4.0, though I managed to find what I believe is a currently maintained branch out on sourceforge: https://sourceforge.net/projects/logwatch/

Looking at the way logwatch is structured, there are two .html files you can edit: header.html and footer.html neither of which allow you to directly edit any of the body of the email. This sucks for micro inline styling, but I managed to add some css styling to spruce it up and make it easier to read.

My one wish, is that someone would rewrite the logwatch.pl to remove all of the body html code and create an actual template for it with references to all of the dynamic info that make it work. This would allow us to tweak the styling of the template to our hearts desire without having to muck with the actual script that makes it all work... I'm no programmer, so I'll leave it at that.

The Steps

So what do you have to do to style the email output?

Step 1) Backup header.html

Navigate to /usr/share/logwatch/default.conf/html and rename the header.html as a backup

mv header.html header.html.default

Step 2) Create a new header.html file

touch header.html

Step 3) Copy the following code and use my tweaks, or edit the code and come up with your own tweaks

<!DOCTYPE HTML>
<html>
<head>
<title>Logwatch  $Version  ( $VDate )</title>
<meta name="generator" content="Logwatch  $Version ( $VDate )">
<style type="text/css">
body {font-size: 1rem;}
h1 { color: gray; font-family: roboto, sans-serif; }
h2 { font-family: roboto, sans-serif; margin: 0 0 .25rem 0; }
h3 { color: white; font-family: roboto, sans-serif; }
table { display: table; border-spacing: 0; border: none; }
th { border: none; text-align: left; font-family: roboto,sans-serif; padding: 0;}
th h2 a { background: #348dbc; color: #fff; text-align: left; font-family: roboto,sans-serif; border-radius: 4px 4px 0 0; display: block; padding: 1.1rem; }
td {background: #f4f4f4; border: none; border-bottom: 1px solid #ccc; text-align: left; padding: .35rem; font-family: roboto,sans-serif; }
li { font-family: roboto, sans-serif; }
.ref {padding-left: 1%; }
.service {padding-left: 1%; }
.return_link {border-top: 1px; border-bottom: 1px; padding: 1%; margin-top: 1%; margin-bottom: 1%; font-family: sans-serif; }
.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" class="logwatch">
<hr>
<!-- End header.html -->

Step 4) Save the file and done!


Known Issues

This works best when your Detail = 0 (low) or the output of the email is small enough not to get clipped by your email provider. For example, I believe Gmail clips the message at 1024KB where it shows a link to [View entire message]. When this happens, Gmail throws away all of the styling when you open the message in the new window and all formatting goes out the window. If we had the ability to inline the code, I think this could be resolved or at least add some basic options to the elements themselves. At least the main part of the message will look decent.

Images

Some example images

Post Comment

Comments

Thanks very much for this. My eyes were aching from the horrible default styling.