• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Web based LOG PARSING Software needed

I have an application that creates a log file.
The log file contains entries as follows :
<xmlA>somecode...XXXXXXX...somecode</xmlA>

What I need is a web based application that can do the following I need to enter a number for example XXXXXXX and it checks the log file for the occurence of that number and displays it starting from <xmlA> that precedes it till </xmlA> that follows it.

Can anyone tell me about such a log parsing software for linux or do I have to write my own scripts and php web page ?
0
http:// thevpn.guru
Asked:
http:// thevpn.guru
  • 3
  • 2
1 Solution
 
crustymonkeyCommented:
I think this is overkill for your application, but check out Splunk (http://www.splunk.com/).  This is an everything and the kitchen sink type of app, but it really rocks for log consolidation.

Really though, a quick PHP page would probably suit you much better for this specific an application.  If you need help with writing that, let me know.
0
 
http:// thevpn.guruAuthor Commented:
Hmm...I mean u are right..it might be easier to do it..what do have in mind.?
0
 
crustymonkeyCommented:
3 quick questions.  How big does the log file get?  Is the log file line based?  Meaning, are there entries like so:

<xmlA>blah blah</xmlA>
<xmlA>blah blah blah</xmlA>

or do they look more like:

<xmlA>blah blah
stuff after a line break
more blah</xmlA>

And lastly, is it a valid XML document?
0
 
http:// thevpn.guruAuthor Commented:
no it is not a valid xml document...and it looks more like


<xmlA>blah blah
stuff after a line break
more blah</xmlA>

I can control the size of the log file as needed
0
 
crustymonkeyCommented:
Here is a quick script to get you started:

/*----------- CODE -----------------*/
<?php

$file = '/path/to/logfile';
$file = 'logfile';

function form () {
    ?>
<h3>Number Search</h3>
<p>
    <form name="search" method="post" action="<?=$_SERVER['PHP_SELF']?>">
    Number: <input type="text" name="number" size="15" />
    <input type="submit" />
    </form>
</p>
    <?php
}

function processForm ($file , $regex) {
    $fh = fopen($file , 'r');
    $contents = fread($fh , filesize($file));
    $ms = array();
    preg_match_all($regex , $contents , $ms);
    print("<pre>\n");
    foreach ($ms[0] as $m) {
        print(htmlspecialchars($m) . "\n");
    }
    print("</pre>\n");
}

?>
<html>
<head>
    <title>Number Search</title>
</head>
<body>
<?php

if ($_POST) {
    $search = $_POST['number'];
    $regex = "/<xmlA>[^<]*${search}[^<]*<\/xmlA>/ims";
    processForm($file , $regex);
}
else {
    form();
}

?>
</body>
</html>
/*-------------- END CODE ----------------*/

This is a starting point for you.  One thing to note is that if you want to capture a very specific sequence and you know that there is whitespace on either side of it, you will want to modify the regex to be more like this:

$regex = "/<xmlA>[^<]*\b${search}\b[^<]*<\/xmlA>/ims";

That will make sure you match the EXACT string separated by a word boundary on either side.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now