Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: trouble parsing log file...

by SheridanCat (Pilgrim)
on Nov 20, 2006 at 22:05 UTC ( #585155=note: print w/ replies, xml ) Need Help??


in reply to Re^3: trouble parsing log file...
in thread trouble parsing log file...

Okay, let's see what we can do here.

First off, your assignments to $error and $warn probably aren't doing what you think they're doing. If you "use warnings" and "use strict" at the top of your code, you'll see an error that is telling:

Use of uninitialized value in pattern match (m//)

Just set $error = 'down' and $warn = 'problem'. Worry about the regular expression stuff later in the code.

As someone already mentioned, why not go ahead and set the $got_button variable to $greenbutton before you enter the loop? It's nice to have a default state already setup. Then there's no need to do any gymnastics at the end to set it.

Inside the loop, you have the right idea. Try using a regular expression there. So the "if" clause would look something like:

if( $line =~ m/$error/i ){

I used the "i" modifier to make it case insensitive, just in case someone changes log messages on you some day.

As someone already pointed out, reading the whole log into memory may not be a very good idea since you're bailing out as soon as you find a red/yellow state, so consider just processing the file a line at a time using <LOG>.


Comment on Re^4: trouble parsing log file...
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://585155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-08-20 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls