#!/usr/bin/perl # vim: set sw=4 ts=4 tw=78 et si: # use strict; use warnings; use Time::Local; my $wanted = 'zebra'; my $syslogline = qr<^ (\S{3} \s{1,2} \d{1,2} \s [0-9:]{8}) \s # $1: datetime (\S+) \s # $2: host ([^[:]+) # $3: process name (?:\[(\d+)\])? :\s # $4: process id (.+) # $5: log line $>x; my $re_ip4 = qr/(\d{1,3}(?:\.\d{1,3}){3})/; my $re_ip4prefix = qr|(\d{1,3}(?:\.\d{1,3}){3}/\d{1,2})|; my $re_ip6prefix = qr|([0-9a-f:]+/\d+)|; my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$dst) = localtime time; while (<>) { if (/$syslogline/) { if ($3 eq $wanted) { process_line($1,$2,$3,$4,$5); } } } sub process_line { my ($time,$host,$name,$pid,$text) = @_; if ($text =~ /^rib_process: $re_ip4prefix: Removing existing route/) { print "$time $host $name: remove $1\n"; } elsif ($text =~ /^rib_process: $re_ip6prefix: Removing existing route/) { print "$time $host $name: remove $1\n"; } elsif ($text =~ /^rib_process: $re_ip4prefix: Adding route,/) { print "$time $host $name: add $1\n"; } elsif ($text =~ /^rib_process: $re_ip6prefix: Adding route,/) { print "$time $host $name: add $1\n"; } else { # print join(" ",@_,"\n"); } }