[mrtg] include without require

Daniel J McDonald dan.mcdonald at austinenergy.com
Fri Jun 3 14:16:18 MEST 2005

I have a fairly complex mrtg configuration, generated by a script, with
about 500 devices monitored.  Each device is in a separate file, and
there is a master file with hundreds of Include: lines.

On occasion, I'll get a little out of sync, and there will be an
Include: statement for a file I have not yet generated.  The MRTG_lib.pm
file issues a "die" in this case, and no stats are collected for the
other 499 devices.

What I'd like is the option to specify an optional include.  Some of my
includes are mandatory - the one that contains the list of mibs to load,
for example - but for most of them, if the file is missing or
un-readable, spitting out a log-message that I can go back and look at
later is sufficient - I'd like the remainder to continue to function.

It seems to me that this patch to 2.12.1 would accomplish most of that:
--- MRTG_lib.pm~        2005-05-16 15:45:26.000000000 -0500
+++ MRTG_lib.pm 2005-06-03 06:56:41.922264334 -0500
@@ -382,14 +382,16 @@
         my $line = $.;
         if (/^include:\s*(.*?\S)\s*$/i){
+                $nextfile = $1;
+               if (-r $nextfile) {
                 push @filestack, $file;
                 push @handstack, $hand;
-                $nextfile = $1;
                 local *FH;
                 open (FH, $nextfile)
                  || open (FH, ($cfgfile =~ m#(.+)${MRTG_lib::SL}[^
${MRTG_lib::SL}]+$#)[0] . ${MRTG_lib::SL} . $nextfile)
                  || do { die "ERROR: unable to open include file:
                 $hand = *FH;
+                } else {
+		 	 warn "WARNING: unable to open include file: $nextfile\n";
+		 }

It doesn't provide for a mandatory include, but that would involve a
syntax change.


Daniel J McDonald, CCIE # 2495, CNX
Austin Energy

dan.mcdonald at austinenergy.com

Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://lists.ee.ethz.ch/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi

More information about the mrtg mailing list