Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
There seemed to be 1 or 2 problems with the regexes, plus a few other Perlisms that needed tidying up.
Its not quite how I would do it, but this seems to work
Code:
#!/usr/bin/perl -w
########################################################################
# Title: CISCOFW2CSV
# File: ciscofw2csv.pl
# Version: 1.0
#
# Description: Takes specific cisco firewall (asa, fwsm, pix) messages (see below) and
# parses the events into comma separated values. Specific fields wanted in the output are
# provided at execution.
#
# %PIX|ASA-3-710003: {TCP|UDP} access denied by ACL from source_address/source_port to interface_name:dest_address/service
# %PIX|ASA-4-106023: Deny protocol src [interface_name:source_address/source_port] dst interface_name:dest_address/dest_port [type
#{string}, code {code}] by access_group #acl_ID
#
# Usage: cat /var/log/enterprise.log | ./ciscofw2csv.pl ["field list"]
#
# Possible fields:
# timestamp sip dip sport dport type level src_int dst_int access_group
# rest proto report_ip
########################################################################
#
#
use strict "vars";
my @tokens = @ARGV;
our ($timestamp,$report_ip,$level,$type,$src_int,$sip,$sport,$dst_int,$dip,$dport,$access_group,$rest,$proto);
# Print hdr csv
my $cflag = 0;
for my $token (@tokens)
{
if( $cflag == 0 )
{
print $token;
$cflag = 1;
}
else
{
print ','.$token;
}
}
print "\n";
while (<STDIN>)
{
chomp;
my $input = $_;
next if( $input =~ /icmp/ );
if ($input =~ /106023/ )
{
($timestamp, $report_ip, $type, $level, $proto, $src_int, $sip, $sport, $dst_int, $dip, $dport, $access_group,$rest) =
$input =~ /^([A-Za-z]+\s+[0-9]{1,2} \d{2}:\d{2}:\d{2}) (\d+\.\d+\.\d+\.\d+) \%(ASA|FWSM|PIX)\-(4)\-106023\: Deny (tcp|udp) src (\D+)\:(\d+\.\d+\.\d+\.\d+)\/(\d+) dst (\D+)\:(\d+\.\d+\.\d+\.\d+)\/(\d+) by access-group \"(\D+)\"/ ;
}
if ($input =~ /710003/)
{
($timestamp, $report_ip, $type, $level, $proto, $sip, $sport, $dst_int, $dip, $dport) =
$input =~ /^([A-Za-z]+\s+[0-9]{1,2} \d{2}:\d{2}:\d{2}).*? (\d+\.\d+\.\d+\.\d+) \%(ASA|FWSM|PIX)\-(3)\-710003\:(TCP|UDP) access denied by ACL from (\d+\.\d+\.\d+\.\d+)\/(\d+) to (\D+)\:(\d+\.\d+\.\d+\.\d+)\/(\d+)/;
}
$dport = $dport."-".$proto;
# Print data csv
$cflag = 0;
for my $token (@tokens)
{
if( $cflag == 0 )
{
print $$token;
$cflag = 1;
}
else
{
print ','.$$token;
}
}
print "\n";
}
Obviously I don't have a 710003 type rec to test.
Note that the original code didn't output icmp pkts, so I've told it to skip those; I'm sure you can handle that if reqd
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.