#!/usr/bin/perl # sqlsyslogd.wrapper by Scott R. Chrestman (src@uix.com) # This is a simple perl script that was written to solve a problem with # syslogd distributed with Red Hat 7.3 (and probably others). The probelm # with the supplied syslogd is that it only allows you to send syslogd # messages to a named pipe, and not simply pipe it's output to a program. # This script acts as the middle-man. It runs and creates a FIFO socket. # When messages are sent to that FIFO socket, it grabs them and redirects # them to the sqlsyslogd program to insert it in to a MySQL database. # # To install, add the following line to /etc/syslog.conf: # *.* |/path/to/sqlsyslogd.wrapper # And be sure to remove the line that points to /path/to/sqlsyslogd # # You may also need/want to modify the variables below to configure # it to your specific configuration. You will also need to make sure # that this is running at all times. I simply added it to my rc.local file. # Once the FIFO is created the first time, upon reboot it will store all # the boot messages, and upon running sqlsyslogd.wrapper, it will insert # the lines in to the database. # # This code is open source; Do with it what you wish. Standard # disclaimers apply: I'm not responsible for anything! :) $FIFO = "/var/log/sqlsyslogd"; $SQLSYSLOGD = "/usr/local/sbin/sqlsyslogd"; $HOST = "localhost"; $USER = "sqlsyslogd"; $TABLE = "logs"; $DB = "sqlsyslogd"; while(1) { unless (-p $FIFO) { unlink $FIFO; system("mknod", $FIFO, "p") && die("$!"); } open(FIFO, "$FIFO") || die("$!"); while(){ open(PROG, "|$SQLSYSLOGD -h $HOST -u $USER -p -t $TABLE $DB"); $_ =~ s/\'/\'\'/g; print PROG $_; close(PROG); } close(FIFO); }