Since no one piped up with an answer, I decided to spend a bit more time on this. It turned out to be easier than I thought, though a truly elegant solution still requires programming expertise I do not have.
-------------
The goal of this exercise is to have the hddtemp service report hard drive temperature numbers regularly to the system log, then see that information in the daily logwatch emails.
Part 1 - Setting up hddtemp
1) sudo yum install hddtemp
2) sudo gedit /etc/sysconfig/hddtemp
3) The hddtemp config file contains only one line. Make it look something like this. Be sure to use the name(s) of your actual hard drives. Also, the number after --syslog is the number of seconds between reports.
Code:
HDDTEMP_OPTIONS="--syslog=36000 -l 127.0.0.1 /dev/sda /dev/sdb /dev/sdc /dev/sdd"
4) sudo /sbin/chkconfig hddtemp on
5) sudo /etc/init.d/hddtemp start
At this point you can open the system log file /var/log/messages and scroll to the end. It should contain lines reflecting the output of hddtemp.
Part two - Logwatch configuration
1) As far as I know all Redhat distros include logwatch as part of the base system. The rest of these instructions presume that logwatch is configured and running, and that it is sending emails to somewhere you can see them.
2) Add a file /usr/share/logwatch/default.conf/services/hddtemp.conf. Here are the contents:
Code:
###########################################################################
# $Id: hddtemp.conf,v 1.0 2009/01/01
###########################################################################
# You can put comments anywhere you want to. They are effective for the
# rest of the line.
# this is in the format of <name> = <value>. Whitespace at the beginning
# and end of the lines is removed. Whitespace before and after the = sign
# is removed. Everything is case *insensitive*.
# Yes = True = On = 1
# No = False = Off = 0
Title = "hddtemp"
# Which logfile group...
LogFile = messages
# Whether or not to lookup the IPs into hostnames...
# Setting this to Yes will significantly increase runtime
$named_ip_lookup = No
# Only give lines pertaining to the named service...
# *OnlyService = hddtemp
# *RemoveHeaders
*ApplyStdDate
# vi: shiftwidth=3 tabstop=3 et
3) Add a file called /usr/share/logwatch/scripts/services/hddtemp. The contents are:
Code:
#!/bin/bash
# These are the standard environment variables. You can define
# more in your service config file (see above).
echo "Date Range: $LOGWATCH_DATE_RANGE"
echo "Detail Level: $LOGWATCH_DETAIL_LEVEL"
echo "Temp Dir: $LOGWATCH_TEMP_DIR"
echo "Debug Level: $LOGWATCH_DEBUG"
# Now take STDIN and dump it to STDOUT after finding only desired lines.
grep -i hddtemp -
4) That's it! You do not have to restart logwatch. It might be a day before you see anything come back since logwatch (in default configuration) does not report today's data until tomorrow.
The file in step 3 is a simple bash script. It can be Perl, PHP, C++ ... Whatever you want to write in. The key point is that it takes standard input, finds the lines you want and sends them to standard output.
The lines you want come from the messages log file group which is named in the file from step 2. In this case the messages group is already created by the default installation of logwatch, so you don't have to do anything more except use it.