Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Syslog conversion to HTML

by parkprimus (Sexton)
on Jan 04, 2004 at 18:51 UTC ( [id://318676]=perlquestion: print w/replies, xml ) Need Help??

parkprimus has asked for the wisdom of the Perl Monks concerning the following question:

I am a newbie but I am getting better at coding everyday. Here is my challenge. What I am doing is logging from a cisco router to my Linux box. Now I want to create a Perl/CGI script that will convert the syslog into HTML so that people do not have to console into my box to view the logs. Can anyone give me some direction. This is a big project for me and the hardest part is getting started and knowing what perl modules (if any) would be the most useful. Thanks in advance.

Replies are listed 'Best First'.
Re: Syslog conversion to HTML
by b10m (Vicar) on Jan 04, 2004 at 19:05 UTC

    Parse::Syslog looks like a good start. Unfortunately, I have no experience with this. So I couldn't tell you how well it works.

    --
    b10m
Re: Syslog conversion to HTML
by Zed_Lopez (Chaplain) on Jan 04, 2004 at 19:09 UTC

    It's not clear what you're asking for help with. What part do you not know how to proceed with? Converting a text file to HTML? Having a CGI script perform the conversion? Automating the conversion?

    As to the first, if you're satisfied with the logs being displayed as plain text in a fixed width font, just slap a <pre> at the beginning and a </pre> at the end, with the usual HTML boilerplate around it, and it's converted into HTML and you're done. There are also a bazillion ways to parse the lines' contents and reformat them.

      I believe you also need to encode at least &, <, and >. You can do this with a simple s///g or with something like HTML::Entities (part of HTML-Parser).
      As was already pointed out, with pre you need to escape characters.

      Alternately you can declare the page to be of type text/plain and include the syslogs directly.

Re: Syslog conversion to HTML
by dominix (Deacon) on Jan 04, 2004 at 22:10 UTC
    if your problem is the HTML generation you can use AnyData::Format::HTMLtable for that, it write HTMLTable for you from a single Hash. It would works perfectly in conjunction with Parse::Syslog as mention by b10m which return Hash ref.
    HTH
    --
    dominix
Re: Syslog conversion to HTML
by Roger (Parson) on Jan 05, 2004 at 00:46 UTC
    You need to remember that the CGI script is run with the uid of the apache, not as yourself. You will need to make sure that the cisco log is accessible to the apache user id (normally httpd, apache, etc).

    Save the following script to the cgi-bin directory of your webserver as view_cisco_log.cgi, and modify the path to point to the actual location of the cisco log on your machine.
    #!/usr/bin/perl -w use strict; use CGI; use IO::File; my $f = new IO::File "/opt/cisco/cisco.log", "r" or die; my $cgi = new CGI; print $cgi->header, "<HTML><TITLE>CISCO LOG</TITLE><BODY><PRE>"; while (defined (my $line = <$f>)) { $line =~ s/&/&amp;/g; $line =~ s/</&lt;/g; $line =~ s/>/&gt;/g; print $line } print "</PRE></BODY></HTML>";
    And create a link on your webpage to point to the following location: http://your.website.com/cgi-bin/view_cisco_log.cgi. So that when a user clicks on the link, he/she will invoke the CGI script and see the cisco log.

      Thank you. This is the way I did it and it works beutimuslly. Thanks again.
Re: Syslog conversion to HTML
by TomDLux (Vicar) on Jan 04, 2004 at 23:54 UTC
    # Available as URL http://www.your.domain/cisco_log.txt # cp $CISCODIR/log.log $WWWDIR/cisco_log.txt

    Of course, there remains the questioin of whether you want everyone to know what is on your machine, or might it be better to have some security control over who can see the file.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Re: Syslog conversion to HTML
by NetWallah (Canon) on Jan 05, 2004 at 03:50 UTC
    You may want to look at SQLSyslogd - store the syslog in a MySQL database, then use a web-based qeuery - this gives you all kinds of sorting and display capabilities.

    "When you are faced with a dilemma, might as well make dilemmanade. "

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://318676]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found