/[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

Contents of /sysplogd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Fri Apr 10 19:12:17 2009 UTC (12 years, 6 months ago) by dpavlin
File size: 1110 byte(s)
decode to hash
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use IO::Socket;
7 use Data::Dump qw/dump/;
8 #use StoreToMongoDB;
9
10 my $port = 514;
11
12 my $MAXLEN = 1524;
13
14 my @facilities = ( qw/
15 kernel user mail system security internal printer news uucp clock security2
16 FTP NTP audit alert clock2 local0 local1 local2 local3 local4 local5 local6 local7
17 / );
18
19 # Start Listening on UDP port 514
20 my $sock = IO::Socket::INET->new(
21 LocalPort => $port,
22 Proto => 'udp'
23 # ReuseAddr => 1,
24 ) || die "can't listen to $port: $!";
25
26 print "INFO: listen on $port",$/;
27
28 my $rin = '';
29 my $buf;
30 while(1) {
31 $sock->recv($buf, $MAXLEN);
32 my ($port, $ipaddr) = sockaddr_in($sock->peername);
33 my $hostname = gethostbyaddr($ipaddr, AF_INET);
34 my $ip = join('.', unpack('C4',$ipaddr));
35 warn "# ",dump( $port, $ipaddr, $hostname, $buf );
36
37 if ( $buf=~/<(\d+)>(.*?):(.*)/ ) {
38 my $sev=$1 % 8;
39 my $fac=($1-$sev) / 8;
40
41 my $log = {
42 ip => $ip,
43 port => $port,
44 hostname => $hostname,
45
46 priority => $1,
47 severity => $sev,
48 facility => $fac,
49 header => $2,
50 message => $3,
51 };
52 print dump( $log ),$/;
53 #StoreToMongoDB->insert( $log );
54 }
55 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26