Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Created January 4, 2011 17:30
Show Gist options
  • Save jaytaph/765070 to your computer and use it in GitHub Desktop.
Save jaytaph/765070 to your computer and use it in GitHub Desktop.
Small example using syslog()
#!/usr/bin/perl -n
# thanks to Brian Dowling for an example with security in mind.
$TO = ‘root@localhost’;
$FROM = $TO;
s/^<\d{1,2}>//;
open(MAIL, “|/usr/sbin/sendmail -t”);
print MAIL <<”EOT”;
To: $TO
From: $FROM
Subject: Log Alert: $_
$_
EOT
<?php
openlog('myapplication', LOG_NDELAY, LOG_USER);
syslog(LOG_NOTICE, "Something has happened");
syslog(LOG_ERR, "Something bad has happened");
?>
destination df_userapp { file("/var/log/userapp.log"); };
filter f_userapp { program("myapplication"); };
log {
source(s_all);
filter(f_userapp);
destination(df_userapp);
};
destination dm_userapp { program("/usr/local/sbin/maillog.pl"); };
filter f_userapp { program("myapplication"); };
log {
source(s_all);
filter(f_userapp);
filter(f_at_least_err);
destination(dm_userapp);
};
destination d_loghost { udp("192.168.1.100" port(514)); };
filter f_userapp { program("myapplication"); };
log {
source(s_all);
filter(f_userapp);
destination(d_loghost);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment