[mrtg] Re: Index generation

Justin Shore listuser at vinnie.ksu.ksu.edu
Fri Mar 3 09:12:16 MET 2000


Richard,
	Actually there is but it isn't really pretty and is somewhat 
of a hack.  First off, do you know perl?  You have to hack the mrtg 
app itself.  Its not a big deal.  Its rather simple what I changed. 
Toby said he'd integrate the changes into the next release too.  What 
the changes are is purely content changes.  Nothing cosmetically or 
functionaly change.  What I added was comment lines before and after 
every major part of the outputted HTML page.  As an example, look at 
the source of this page:

http://ipgate.sktc.net/stats/sktc/io-cisco5300.clr.html

With those comments in place I could then use a perl script to 
archive the daily images with the numbers below it nightly without 
having to archive the weekly/monthly/yearly images too (or have 3 
broken images sitting in the backed up HTML file--not very pretty). 
Here's the final output for that same image:

http://ipgate.sktc.net/stats/sktc/archive/daily/000302/io-cisco5300.clr.html

Now, using those comments and some simple logic and scripting, you 
could easily make a script (or alter the one below) that follows the 
same guidelines for parsing your outputted MRTG HTML page for 
everything between the relevant comments and dumps that to file.  You 
could simply print out a the HTML header and footer within the script 
yourself.  Here's what I sent Toby (this is long):

<QUOTE>
Toby,
	I just modifed a copy of MRTG 2.8.12 to make what I'm trying 
to do a little easier.  The changes weren't functional; all I did was 
add a few comments to the HTML output to make it easier to parse 
after the fact.  Here's an example of the page (visually its 
identical, the source is what's slightly altered):

<snipped old site>

I added a comment before and after the header, each graph section 
d/w/m/y, the legend, and the MRTG info block at the end.  The reason 
I did that was so I could make the mrtg-archiver script.  backup.pl 
worked great once I fixed a few typos.  The only problem was its 
output included the 3 dead images since I was only backing up the 
daily image at each running.  I altered the script to include 
everything between point A and point B. To do that, I had to add 
those points to the MRTG output.  Here's the diff of my new MRTG and 
the old one:

[www at Vinnie mrtg]$ diff mrtg mrtg-old
1426d1425
<   print HTML "<!-- Begin Head -->\n";
1491c1490
< <!-- End Head -->";
---
>  ";
1545d1543
< ".&$LOC("<!-- Begin $sample{$peri} -->")."
1580c1578
<  </TR>" if $OutCo;
---
>   </TR> " if $OutCo;
1596,1598c1594
< </TABLE>\n
< ".&$LOC("<!-- End $sample{$peri} -->")."
< ";
---
>  </TABLE>\n";
1601d1596
< <!-- Begin Legend -->
1621,1622c1616
<        <TD><FONT SIZE=-1>$leg4</FONT></TD></TR>
<        "if $OutCo;
---
>         <TD><FONT SIZE=-1>$leg4</FONT></TD></TR> "if $OutCo;
1650,1651d1643
< <!-- End Legend -->
< <!-- Begin MRTG Block -->
1729d1720
< <!-- End MRTG Block -->

	I may not have used the $sample{$peri} correctly but it 
worked like a champ never the less (I'm not a great perl programmer 
yet).  Here's the modified subblock of backup.pl:

foreach $node ( @nodes_to_backup ) {
     printf("Executing backup for node %s.\n",$node);
     system(sprintf("cp -a %s/%s*-day.gif %s",$MRTG_DIR,$node,$TO_DIR));
     $Summary_Source = "$MRTG_DIR/$node.html";
     $Summary_Destination = "$TO_DIR/$node.html";
     $output = "OFF";
     open(SRC,"<$Summary_Source");
     open(DST,">$Summary_Destination");
     while (<SRC>) {
       $output = "ON" if m:^<!-- Begin Head -->:;
       $output = "ON" if m:^<!-- Begin `Daily':;
       $output = "ON" if m:^<!-- Begin Legend -->:;
       $output = "ON" if m:^<!-- Begin MRTG Block -->:;
       $output = "OFF" if m:^<!-- End Head -->:;
       $output = "OFF" if m:^<!-- End `Daily':;
       $output = "OFF" if m:^<!-- End Legend -->:;
       $output = "OFF" if m:^<!-- End MRTG Block -->:;
       s/<META HTTP-EQUIV=\"Refresh\" CONTENT=\"300\">//;
       if ( $output eq "ON" ) { print DST; }
     }
     close(SRC);
     close(DST);
     chmod(0644,$Summary_Destination);
}

	Now it outputs the header, the daily content, the legend, and 
the MRTG info block without bad references to images.  Here's the 
final page:

<snipped old site>

	Would you consider adding these (or similar but definitive) 
comments to the next MRTG?  If you can, that would be great.  Like I 
said, its not a functional change but more of a nice parsing 
addition.  I'm going to send my modified script and MRTG back to the 
original author in case he wants to update his version.  Thanks!
</QUOTE>

Now there may be a better way but I don't know of one.  With these 
changes in place, indexmaker could be altered to include those 
relevant numbers with a certain switch and run from a cronjob.  Too 
bad there wasn't a directive within MRTG to run a command on 
completion of running a particular conf or specific target.  That 
would be a lot cleaner.  Does this make sense?  Its a lot of info at 
once but hopefully it'll help.

Justin




At 11:21 AM -0500 3/2/00, Billingsley, Richard, CON, OASD(HA)/TMA wrote:
>Is there a way of creating an index.htm with the daily graph the  way it is
>already doing using indexmaker, but with the  charts(% utilization) on it
>too.
>

-- 

--
Justin Shore
K-State Linux Distro Mirror, Sysadmin
macdaddy at vinnie.ksu.ksu.edu
<http://vinnie.ksu.ksu.edu/mirror/rpm2html>
<ftp://vinnie.ksu.ksu.edu/pub/mirror/linux>

*Internet2 Users*
<ftp://quest.ksu.ksu.edu/pub/mirror/linux>

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:mrtg-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/mrtg



More information about the mrtg mailing list