Skip to Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

9.37. Defining a logwatch Filter

Problem

You want logwatch to print reports for a service it does not support.

Solution

Create your own logwatch filter for that service or log file. Suppose you have a service called foobar that writes to the log file /var/log/foobar.log.

  1. Create /etc/log.d/conf/logfiles/foobar.conf containing:

    LogFile = /var/log/foobar.log
    Archive = foobar.log.*
    ...
  2. Create /etc/log.d/conf/services/foobar.conf containing:

    LogFile = foobar
  3. Create /etc/log.d/scripts/services/foobar.

    This is a script (Perl, shell, etc.) that matches the desired lines in foobar.log and produces your desired output. logwatch automatically strips the datestamps from syslog-format output, so your script needn’t do this.

Discussion

logwatch is more a framework than a log parser. In fact, all parsing is done by auxiliary scripts in /etc/log.d/scripts/services, so for unsupported services, you must write your own scripts. You might think, “Hey, if I have to write these scripts myself, what’s the value of logwatch?” The answer is convenience, as well as consistency of organization. It’s helpful to have all your log groveling scripts together under one roof. Plus logwatch supplies tons of scripts; use them as examples for writing your own.

To integrate a given service into logwatch , you must define three files:

A logfile group configuration file

Found in /etc/log.d/conf/logfiles, it defines where the service’s logs are stored.

A service filter executable

Found in /etc/log.d/scripts/services, it must read ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Practical Linux Security Cookbook - Second Edition

Practical Linux Security Cookbook - Second Edition

Tajinder Kalsi
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar
Network Security with OpenSSL

Network Security with OpenSSL

John Viega, Matt Messier, Pravir Chandra

Publisher Resources

ISBN: 0596003919Errata Page