8 |
use DBI; |
use DBI; |
9 |
use Getopt::Long; |
use Getopt::Long; |
10 |
|
|
11 |
my $port = 514; |
our $port = 514; |
12 |
|
our $MAXLEN = 1524; |
13 |
|
|
14 |
my $MAXLEN = 1524; |
our $dsn = 'DBI:Pg:dbname=syslog'; |
15 |
|
our $user = 'dpavlin'; |
16 |
|
our $log = '/tmp/sysplog.log'; |
17 |
|
|
18 |
|
my $config = $0; |
19 |
|
$config =~ s{/[^/]+$}{/conf.pl}; |
20 |
|
if ( -e $config ) { |
21 |
|
require $config; |
22 |
|
warn "# using $config ", -s $config, $/; |
23 |
|
} |
24 |
|
|
|
my $dsn = 'DBI:Pg:dbname=syslog;host=llin.lan'; |
|
|
my $user = 'dpavlin'; |
|
25 |
my $debug = 0; |
my $debug = 0; |
26 |
my $schema = 0; |
my $schema = 0; |
|
my $log = '/tmp/sysplog.log'; |
|
27 |
|
|
28 |
GetOptions( |
GetOptions( |
29 |
'debug+' => \$debug, |
'debug+' => \$debug, |
30 |
'schema!' => \$schema, |
'schema!' => \$schema, |
31 |
'log=s' => \$log, |
'log=s' => \$log, |
32 |
|
'port=i' => \$port, |
33 |
) || die "usage: $0 --debug --schema\n"; |
) || die "usage: $0 --debug --schema\n"; |
34 |
|
|
35 |
my @facilities = ( qw/ |
our $VERSION = '0.00'; |
|
/ ); |
|
36 |
|
|
37 |
my $sql_schema = q{ |
my $sql_schema = q{ |
38 |
|
|
103 |
# ReuseAddr => 1, |
# ReuseAddr => 1, |
104 |
) || die "can't listen to $port: $!"; |
) || die "can't listen to $port: $!"; |
105 |
|
|
|
print "INFO: listen on $port",$/; |
|
|
|
|
106 |
open(my $log_fh, '>>', $log) || die "can't open log $log: $!"; |
open(my $log_fh, '>>', $log) || die "can't open log $log: $!"; |
107 |
$log_fh->autoflush(1); |
$log_fh->autoflush(1); |
108 |
sub _log { |
sub _log { |
110 |
print $log_fh time() . '|' . join('|', @_), $/; |
print $log_fh time() . '|' . join('|', @_), $/; |
111 |
} |
} |
112 |
|
|
113 |
my $rin = ''; |
_log "INFO: listen on $port"; |
114 |
|
|
115 |
my $buf; |
my $buf; |
116 |
while(1) { |
while(1) { |
117 |
$sock->recv($buf, $MAXLEN); |
$sock->recv($buf, $MAXLEN); |