/[sysplogd]/sysplogd
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sysplogd

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Fri Apr 10 19:12:17 2009 UTC revision 3 by dpavlin, Fri Apr 10 21:22:01 2009 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  use IO::Socket;  use IO::Socket;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8  #use StoreToMongoDB;  use DBI;
9    
10  my $port = 514;  my $port = 514;
11    
12  my $MAXLEN = 1524;  my $MAXLEN = 1524;
13    
14    my $dsn = 'DBI:Pg:dbname=syslog';
15    my $user = 'dpavlin';
16    my $debug = 0;
17    
18  my @facilities = ( qw/  my @facilities = ( qw/
19  kernel user mail system security internal printer news uucp clock security2  kernel user mail system security internal printer news uucp clock security2
20  FTP NTP audit alert clock2 local0 local1 local2 local3 local4 local5 local6 local7  FTP NTP audit alert clock2 local0 local1 local2 local3 local4 local5 local6 local7
# Line 23  my $sock = IO::Socket::INET->new( Line 27  my $sock = IO::Socket::INET->new(
27  #       ReuseAddr => 1,  #       ReuseAddr => 1,
28  ) || die "can't listen to $port: $!";  ) || die "can't listen to $port: $!";
29    
30    my $dbh = DBI->connect( $dsn, $user, '', { RaiseError => 1 } ) || die $DBI::errstr;
31    
32    my $sth = $dbh->prepare(qq{
33            insert into log
34            (ip,hostname,facility,priority,level,program,message) values
35            (? ,?       ,?       ,?       ,?    ,?      ,?      )
36    });
37    
38  print "INFO: listen on $port",$/;  print "INFO: listen on $port",$/;
39    
40  my $rin = '';  my $rin = '';
# Line 35  while(1) { Line 47  while(1) {
47          warn "# ",dump( $port, $ipaddr, $hostname, $buf );          warn "# ",dump( $port, $ipaddr, $hostname, $buf );
48    
49          if ( $buf=~/<(\d+)>(.*?):(.*)/ ) {          if ( $buf=~/<(\d+)>(.*?):(.*)/ ) {
50                  my $sev=$1 % 8;                  my $level=$1 % 8;
51                  my $fac=($1-$sev) / 8;                  my $fac=($1-$level) / 8;
52                    $sth->execute( $ip, $hostname, $fac, $1, $level, $2, $3 );
                 my $log = {  
                         ip => $ip,  
                         port => $port,  
                         hostname => $hostname,  
   
                         priority => $1,  
                         severity => $sev,  
                         facility => $fac,  
                         header => $2,  
                         message => $3,  
                 };  
                 print dump( $log ),$/;  
                 #StoreToMongoDB->insert( $log );  
53          }          }
54  }  }

Legend:
Removed from v.2  
changed lines
  Added in v.3

  ViewVC Help
Powered by ViewVC 1.1.26