[syslog-ng]Sending Email via syslog-ng

Aaron Jackson syslog-ng@lists.balabit.hu
Wed, 11 Feb 2004 12:56:13 -0500


Your script needs to be in a loop like:

while (<>) {
	if (match) {
		sendmail;
	}
}

Wilhelm.Greiner@vaps.de wrote:
> 
> Hi,
> 
> im trying to send email with syslog-ng, i have configurations
> like this:
> 
> destination ruf_mich_an { program("/usr/local/sbin/log_to_mail.pl"); };
> filter ruf_mich_an2 { facility(cron); };
> log { source(net); filter(ruf_mich_an2); destination(ruf_mich_an); };
> 
> or things like:
> 
> destination d_cachos_dns_ldap_errors2 {
>         program("/usr/local/sbin/log_to_mail.pl");
> };
> 
> filter f_cachos_dns_error { match("Connection refused on DNS lookup 
> to"); };
> 
> log { source(net); filter(f_cachos_dns_error); 
> destination(d_cachos_dns_ldap_errors2); };
> 
> 
> But there comes no mail, that perl script (see below) works correkt
> on the Console (takes input for the body from stdin).
> 
> But, when i restart syslog-ng, i become 4 Mails, but with only
> "761" inside...
> 
> Is there any "buffer" available? Means: will i receive a Mail
> for _every_ LogEntry, or can i say, all logentries in a defined
> time (minute or so). But i also can do that in the Mail Script.
> 
> #####################################################
> 
> #!/usr/bin/perl
> #s/^<[\d]{1,2}>//;
> use Socket;
> $proto   = getprotobyname('tcp');
> $port    = 25;
> $address = 192.168.3.12;
> socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);
> 
> $sin = sockaddr_in($port,$address);
> connect(Socket_Handle,$sin) || die ("Failed $!:");
> select(Socket_Handle);
> $|=1;
> select(STDOUT);
> 
> print Socket_Handle "ehlo test\n";
> print Socket_Handle "mail from: me\@myhouse.net\n";
> print Socket_Handle "rcpt to: irgendwer\@myhouse.net\n";
> print Socket_Handle "data\n";
> print Socket_Handle "subject: $_\n\n";
> 
> print Socket_Handle "$_\r\n";
> print Socket_Handle ".\r\n";
> print Socket_Handle "quit\n";
> 
> while(<Socket_Handle>) {
>         print $_;
> }
> 
> close(Socket_Handle);