blog advertising is good for you


blog advertising is good for you
User login

Create RSS feeds from system log files

With the advent of RSS readers that can use so-called “local feeds” for various reasons, it was inevitable that some code monkey would convert his 250K system.log file to RSS.

Hello.

Perl is my language of choice here. I’m sure you have your own opinion of what language to use for tasks like this, and you can stuff it. I chose Perl.

The goal is very simple. We need to take a line, pretty it up into pieces, and then make an RSS item out of it. Then slap an RSS header and footer onto the file and present it to the user to do with as he pleases.

Attached is said file. Read over it, run it, have fun. I’m not here to teach you how to write Perl. What I am going to do is show you how to have fun with it. Given the attached script, run it once and redirect the output to a file:

log2rss.pl /var/log/syslog.log 500 > syslog.xml

Now load the file in your reader. This will vary per reader. Here, I use Pulp Fiction 1.2 because it’s drop-dead simple to add a static RSS file to it. Others require you to re-run the script or serve it locally in your Sites folder (also a possibility for older/other readers that do not support local feeds). To add it to PF 1.2 … drag it into your Subscriptions window. You’re done.

So now that you have a feed going, you want to update it. Well, we’re obviously going to use cron for this. Either get Cronnix or the like or edit your crontab file in Terminal. If you know how, you know how.

For a syslog.log feed you’re going to run into a tradeoff. It gets content fast-ish, but is also large and mildly expensive to parse. Choose a time that won’t burden your system too much. I chose 30 minutes, myself.

Average rating
(0 votes)
AttachmentSize
log2rss.pl.txt1.31 KB
About Adam Knight
Adam Knight's picture

Author Biography

Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c.

In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon.

Bug him over AIM or email [link fixed].

PulpFiction 1.2 is now available. PulpFiction Lite 1.2 will be available later today or tomorrow. Over the past ten days, we've been counting down some of PulpFiction's new features. A quick recap of the ones I like most: Smart FoldersEnclosures...
Put his system logs in RSS, of course. It works pretty well now that I got a good GUID scheme down and parsed out the dates properly. Cap it at 500 lines, run it every ten minutes … I can monitor remote machines in situations where I could not be the syslog delegate. Trés nice.
All praise codepoet for creating this Perl script, which, when run, parses /var/log/system.log in order to beautify it, and ...

What does a bored geek do? Put his system logs in RSS, of course.

It works pretty well now that I got a good GUID scheme down and parsed out th

unixgeek's picture
Of course, there is another way of improving this .... Code your perl script to be a daemon, have it listen on a named pipe on the file system some place and have it listen on the named pipe for new syslog entries and append them to syslog.xml. The trick to make this work automatically is simple: tell syslogd to write a copy of everything to the named pipe. Easy IPC. And you get live log feeds via RSS as a result with no cron jobs. If you want, I could write up a few examples for the syslogd configuration and the perl code to be a daemon and how to set up the named pipe (all of this is pretty easy, however.) Of course, this wouldn't be complete without a startup script. -- unxgeek@unxgeek.us "Smile," they said, "it could be worse." So I did, and it was.