Home > Archive > PERL Beginners > November 2007 > Format the raw log.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Format the raw log.
|
|
| Avinash S 2007-11-23, 10:01 pm |
| Hi,
I need to format the below logs.
Following is the real world example.
Input File.
---INPUT DATA---
---------------------------------
--> Checking Server Hostname <--
---------------------------------
Server Hostname: xxxxxxxxx
---------------------------------------
--> Checking Authentication Domain <--
---------------------------------------
Server is authenticating against: xxxxxxxxx
--------------------------------------
--> Validating DNS Server Entries <--
--------------------------------------
Servers should conform to global ANYCast Standard
DNS Name : xxxxxx [WARNING]
Please check the DNS name.
--------------------------------------
--> Validating APP Server Entries <--
--------------------------------------
Buffer size: [WARNING]
Invalid Log count. Required buffer size is 20.
Output File
--REQUIRED OUTPUT DATA---
Validating DNS Server Entries
--------------------------------------
DNS Name : xxxxxx [WARNING]
Please check the DNS name.
Validating APP Server Entries
--------------------------------------
Buffer size: [WARNING]
Invalid Log count. Required buffer size is 20.
We need capture only the WARNING messages along with the
Heading.
after this I want to send a mail.
Thank You.
| |
| Tom Phoenix 2007-11-23, 10:01 pm |
| On 11/23/07, Avinash S <avinash.suratkal@gmail.com> wrote:
> I need to format the below logs.
....
> after this I want to send a mail.
Sounds like you know what you want to do. Are you having trouble
implemening any part of it in Perl?
Cheers!
--Tom Phoenix
Stonehenge Perl Training
| |
| Avinash S 2007-11-24, 7:00 pm |
| Hi,
Yes, I have a trouble in parsing through the raw log. I am using the
"-->" symbol to parse through the log.
From
--------------------------------------
--> Validating DNS Server Entries <--
--------------------------------------
Servers should conform to global ANYCast Standard
DNS Name : xxxxxx [WARNING]
Please check the DNS name.
To
--------------------------------------
--> Validating APP Server Entries <--
--------------------------------------
I want to extract only the block which has the key word [WARNING]
I have the following code
my ($field_type);
my (%warning, $warning_count);
my $server_name = "baeed on file name";
while (<FILE> )
chomp;chomp;
my ($line) = $_;
if ($line =~ /-->.*<--/) {
$field_type = $line;
$field_type =~ s/-->(.*)--</$1/;
}
if ($line =~ /WARNING/) {
my ($match) = $server_name ." - ".$field_type." - ".$line;
$warning{$match} = 1; #not great, but works
$warning_count++;
}
}
But this doesn't give me the required output.
Thanks.
On Nov 24, 8:04 am, t...@stonehenge.com (Tom Phoenix) wrote:
> On 11/23/07, Avinash S <avinash.surat...@gmail.com> wrote:
>
>
>
> ...
>
> Sounds like you know what you want to do. Are you having trouble
> implemening any part of it in Perl?
>
> Cheers!
>
> --Tom Phoenix
> Stonehenge Perl Training
| |
| Tom Phoenix 2007-11-24, 7:00 pm |
| On 11/24/07, Avinash S <avinash.suratkal@gmail.com> wrote:
> I want to extract only the block which has the key word [WARNING]
It sounds as if you wish to process many lines at once, rather than
one line at a time. Is that right?
> while (<FILE> )
> chomp;chomp;
Why two chomps? The first one removed the newline. The second one will
accomplish nothing. (But it's good Perl poetry. :-)
> my ($line) = $_;
> if ($line =~ /-->.*<--/) {
> $field_type = $line;
> $field_type =~ s/-->(.*)--</$1/;
> }
Your second pattern has a different arrow on the right than the first.
Is that your problem? That if-block could be simplified, I think:
if ($line =~ /-->(.*)<--/) {
$field_type = $1;
}
If your data comes in multiple-line chunks, it may be easiest to
gather it up a chunk at a time for processing, instead of viewing it a
line at a time. Whenever you read the end of a chunk, you would send
the whole chunk off for processing, perhaps in a subroutine. Perl's
patterns can work with multiple-line chunks without much trouble.
Hope this helps!
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|