[mrtg] (no subject)

Aaron D aaronbd at live.com
Thu Jul 14 20:29:58 CEST 2011


Hello,

I realize this is an old post, but it seems like a common problem without many 
public answers.

-------------------------

The problem is that the indexmaker script only knows how to pull out the host 
information from a "Target" tag that an snmp call from your mrtg.cfg file.

In other words, the indexmaker script only knows how to read something like 
this, for grabbing the host:

   Target[192.168.1.1_1]: 1:public at 192.168.1.1:

It grabs what is between the '@' and the next ':' symbols.

In my indexmaker, on line 132, you will find the snippet of code that decides 
this :

   for my $targ (@routers) {
     if ( !defined $rcfg{host}{$targ} and
           !($rcfg{target}{$targ} =~ m/(?<!\\)[ \`]/) ) {
              $rcfg{target}{$targ} =~ m/.*[^\\]@([^:]*)/;
              $rcfg{host}{$targ} = ucfirst $1 if (defined $1);
     }
   }

------------------------

I am using a few custom scripts, but still want to use the indexmaker to build 
my index.html file, with the --perhost flag.

This is my solution simple, but hacky solution.  I wanted something that could 
easily read the host ip from any script, regardless of the parameters.  So I put 
a comment at the end of each script call to store this value.  My targets look 
like this.

   ...
   Target[192.168.1.1_script1]: `/usr/local/sbin/script1.sh -H 192.168.1.1 # 
@192.168.1.1: `
   ...
   Target[192.168.1.1_script2]: `/usr/local/sbin/script2.sh # @192.168.1.1: `
   ...

The key is the "# @192.168.1.1:" in the script.  Since it is commented out, it 
is not used by the script, but still I can store what I need to here.


Next I copied indexmaker to indexmaker2, and change the following in indexmaker2

   for my $targ (@routers) {
     if ( !defined $rcfg{host}{$targ} and
           !($rcfg{target}{$targ} =~ m/(?<!\\)[ \`]/) ) {
              $rcfg{target}{$targ} =~ m/.*[^\\]@([^:]*)/;
              $rcfg{host}{$targ} = ucfirst $1 if (defined $1);
     }
     elsif ( !defined $rcfg{host}{$targ} and
           ($rcfg{target}{$targ} =~ m/[ \`].*# @([^:]*)/) ) {
              $rcfg{target}{$targ} =~ m/.*# @([^:]*)/;
              $rcfg{host}{$targ} = ucfirst $1 if (defined $1);
     }
   }

I hope this will help others make their mrtg setups more readable.
Aaron




More information about the mrtg mailing list