note
reasonablekeith
Your data seems a bit too ambiguous to parse easily. You can't, as in your example, just split on white space, as your 'msg' data field is an unquoted string (so you'll get a seperate field for each word in the string). Your best option is to get the log file tab delimited (I'm guessing it isn't at the moment), and stop reading this post.
<p>However, if you don't have control of the data, you'll just have to take a stab. With the assumption that the first four fileds don't have spaces in them, and that the key/value data that follows doesn't have any '='s in the data, then you could do something like this...
<code>
#!/usr/bin/perl
use Data::Dumper;
while(<DATA>) {
chomp;
my ($log_date, $log_time, $something, $ip_address, $keyed_data_string ) = split /\s+/, $_, 5;
my %keyed_data_hash;
while( $keyed_data_string =~ s/\s*(\w+)=\s*([^=]*)$/ $keyed_data_hash{$1} = $2; ''/xsge) { 1 }
print Dumper($log_date, $log_time, $something, $ip_address, \%keyed_data_hash);
}
__DATA__
2007-11-16 16:05:40 Local1.Alert 128.2.2.40 id=firewall time="2007-11-16 16:03:37" fw=WS2000-Store 02 pri=1 proto=6(tcp) src=128.2.2.200 dst=128.2.100.106 mid= 1013 mtp= 2 msg=TCP connection request received is invalid, dropping packet Src 23 Dst 4631 from EXT n/w agent=Firewall
</code>
OUTPUT
<code>
$VAR1 = '2007-11-16';
$VAR2 = '16:05:40';
$VAR3 = 'Local1.Alert';
$VAR4 = '128.2.2.40';
$VAR5 = {
'msg' => 'TCP connection request received is invalid, dropping packet Src 23 Dst 4631 from EXT n/w',
'proto' => '6(tcp)',
'time' => '"2007-11-16 16:03:37"',
'src' => '128.2.2.200',
'mtp' => '2',
'mid' => '1013',
'fw' => 'WS2000-Store 02',
'agent' => 'Firewall',
'id' => 'firewall',
'pri' => '1',
'dst' => '128.2.100.106'
};
</code>
... which works by pulling off the easy four first fields, and then works from the end of the rest of the data, creating a key pair hash.
<p>
It's pretty ugly, but with your data, I don't see a way around it.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-425417">
<font size="-2">
---<br/>
<i>my name's not Keith, and I'm not reasonable.</i>
</font>
</div></div>
653300
653300