Readable Nagios Log Timestamps

If you’re like me and most humans, the Nagios logfile timestamp (a unix timestamp) isn’t terribly useful when trying to grep through the logs and correlate events:

# head -2 nagios.log
[1350360000] LOG ROTATION: DAILY
[1350360000] LOG VERSION: 2.0

Here’s a nifty Perl one-liner that you can pipe your logs through:
perl -pe ‘s/(\d+)/localtime($1)/e’
to get nicer output like:

# head -2 nagios.log
[Tue Oct 16 00:00:00 2012] LOG ROTATION: DAILY
[Tue Oct 16 00:00:00 2012] LOG VERSION: 2.0

Quick and Simple Timestamping of Debug Logs

I’ve been having some issues that may be Puppet-related. Unfortunately, Puppet (at least the old 0.25.4 client that I’m running) doesn’t timestamp the debug logs sent to stdout. I know it’s hanging somewhere, but I need concrete numbers to look at. Here’s a wonderfully simple bash script that timestamps everything sent to it on stdin, and echoes it back to stdout:

#!/bin/bash
 
DATECMD='date +%H:%M:%S'
 
while read line; do
    echo -e "$($DATECMD) $line"
done

Call it as simply as: command | ~/bin/ts, or maybe like command 2>&1 | ~/bin/ts | tee foo.log. Dead simple, but very helpful when the developers didn’t think to timestamp debug log output.

My Birthday!

I happened to be working with some timestamps today and noticed that we’re starting to get into territory like 1234094400. So, being the geek that I am, I wondered when we’d finally hit 1234567890. The answer is 2009-02-13T18:31:30-05:00, which happens to be 18:31:30 on my birthday. Yay!