📄 mrtg
字号:
#warn ("\nINFO: NO \"colours\[$rou\]\"\n$$rcfg{'colours'}{$rou}\n"); if ($$rcfg{"colours"}{$rou} =~ /^([^\#]+)(\#[0-9a-f]{6})\s*,\s* ([^\#]+)(\#[0-9a-f]{6})\s*,\s* ([^\#]+)(\#[0-9a-f]{6})\s*,\s* ([^\#]+)(\#[0-9a-f]{6})/ix) { ($$rcfg{'col1'}{$rou}, $$rcfg{'rgb1'}{$rou}, $$rcfg{'col2'}{$rou}, $$rcfg{'rgb2'}{$rou}, $$rcfg{'col3'}{$rou}, $$rcfg{'rgb3'}{$rou}, $$rcfg{'col4'}{$rou}, $$rcfg{'rgb4'}{$rou}) = ($1, $2, $3, $4, $5, $6, $7, $8);# warn ("\nINFO:\n\# $$rcfg{'col1'}{$rou}, $$rcfg{'rgb1'}{$rou},\n\# $$rcfg{'col2'}{$rou}, $$rcfg{'rgb2'}{$rou},\n\# $$rcfg{'col3'}{$rou}, $$rcfg{'rgb3'}{$rou},\n\# $$rcfg{'col4'}{$rou}, $$rcfg{'rgb4'}{$rou}"); } else { warn ("\nERROR: \"colours[$rou]\" for colour definition\n". " use the format: Name#hexcolour, Name#Hexcolour,...\n"); $error="yes"; } } } else { if ($$rcfg{'options'}{'dorelpercent'}{$rou}) { ($$rcfg{'col1'}{$rou}, $$rcfg{'rgb1'}{$rou}, $$rcfg{'col2'}{$rou}, $$rcfg{'rgb2'}{$rou}, $$rcfg{'col3'}{$rou}, $$rcfg{'rgb3'}{$rou}, $$rcfg{'col4'}{$rou}, $$rcfg{'rgb4'}{$rou}, $$rcfg{'col5'}{$rou}, $$rcfg{'rgb5'}{$rou}) = ("GREEN","#00cc00", "BLUE","#0000ff", "DARK GREEN","#006600", "MAGENTA","#ff00ff", "AMBER","#ef9f4f"); } else { ($$rcfg{'col1'}{$rou}, $$rcfg{'rgb1'}{$rou}, $$rcfg{'col2'}{$rou}, $$rcfg{'rgb2'}{$rou}, $$rcfg{'col3'}{$rou}, $$rcfg{'rgb3'}{$rou}, $$rcfg{'col4'}{$rou}, $$rcfg{'rgb4'}{$rou}) = ("GREEN","#00cc00", "BLUE","#0000ff", "DARK GREEN","#006600", "MAGENTA","#ff00ff"); } } # Background color, format: #rrggbb if ($$rcfg{'background'}{$rou}) { if ($$rcfg{'background'}{$rou} =~ /^(\#[0-9a-f]{6})/i) { $$rcfg{'backgc'}{$rou} = "BGCOLOR=\"$1\""; } else { warn ("\nERROR: \"background[$rou]: ". "$$rcfg{'background'}{$rou}\" for colour definition\n". " use the format: #rrggbb\n"); $error="yes"; } } else { $$rcfg{'backgc'}{$rou} = "BGCOLOR=\"#ffffff\""; } if (! $$rcfg{'kilo'}{$rou}) { $$rcfg{'kilo'}{$rou} = 1000 } if ($$rcfg{'kmg'}{$rou}) { $$rcfg{'kmg'}{$rou} =~ s/\s+//g; } if (! $$rcfg{'xzoom'}{$rou}) { $$rcfg{'xzoom'}{$rou} = 1.0 } if (! $$rcfg{'yzoom'}{$rou}) { $$rcfg{'yzoom'}{$rou} = 1.0 } if (! $$rcfg{'xscale'}{$rou}) { $$rcfg{'xscale'}{$rou} = 1.0 } if (! $$rcfg{'yscale'}{$rou}) { $$rcfg{'yscale'}{$rou} = 1.0 } if ($error eq "yes") { die ("\n\nABORT: Please fix the error(s) in your config file\n\n"); } } \%target;} sub getcurrent { my ($target, $rou, $rcfg) = @_; if ($main::DEBUG > 1) { print "getcurrent: dumping rcfg keys\n"; my $key; foreach $key (keys %$rcfg) { print "getcurrent: rcfg $key $$rcfg{$key}\n"; } } my $inlast=0; my $outlast=0; my $uptime; my $name; my $strg; my $time; my $count=0; print "getcurrent: rcfg target router $rou = $$rcfg{'target'}{$rou}\n" if $main::DEBUG; my $mode='in'; if ( eval("(" . $$rcfg{targtest}{$rou}."0 )")) { $inlast = -1; } else { # we must get a plain value $inlast = sprintf("%.0f",eval($$rcfg{target}{$rou})); die "* Problem with '$$rcfg{targorig}{$rou}':\n $@\n" if $@; } $mode='out'; if ( eval("(" . $$rcfg{targtest}{$rou}."0 )")) { $outlast = -1; } else { $outlast = sprintf("%.0f",eval($$rcfg{target}{$rou})); die "* Problem with '$$rcfg{targorig}{$rou}':\n $@\n" if $@; } if ($$rcfg{targcount}{$rou} == 1 and exists $$target{$$rcfg{targorig}{$rou}}) { $uptime = $$target{$$rcfg{targorig}{$rou}}{'uptime'}; $name = $$target{$$rcfg{targorig}{$rou}}{'name'}; $time = $$target{$$rcfg{targorig}{$rou}}{'time'}; } #make sure we have a time set ... $time = time unless defined $time; if ($$rcfg{routeruptime}{$rou} ne '') { ($uptime,$name) = &snmpget( $$rcfg{"community"}{$rou}."@".$$rcfg{"router"}{$rou}, 'sysUptime', 'sysName'); } ($inlast, $outlast, $uptime, $name, $time);}sub writegraphics { my($router, $cfg, $rcfg, $inlast, $outlast, $time) = @_; my($absmax,$maxv, $maxvi, $maxvo, $i, $period, $res); my(@exec, @mxvls, @metas); my(%maxin, %maxout, %maxpercent, %avin, %avout, %avpercent, %cuin, %cuout, %cupercent); @metas = (); $maxvi = $$rcfg{'maxbytes1'}{$router}; $maxvo = $$rcfg{'maxbytes2'}{$router}; if ($maxvi > $maxvo) { $maxv = $maxvi; } else { $maxv = $maxvo; } $absmax = $$rcfg{'absmax'}{$router}; $absmax = $maxv unless $absmax; if ($absmax < $maxv) { die "AbsMax: $absmax is smaller than MaxBytes: $maxv\n";} print "writegraphics: inlast $inlast outlast $outlast\n" if $main::DEBUG; # select whether the datasource gives relative or absolte return values. my $up_abs="u"; $up_abs='a' if $$rcfg{'options'}{'absolute'}{$router}; $up_abs='g' if $$rcfg{'options'}{'gauge'}{$router}; $up_abs='h' if $$rcfg{'options'}{'perhour'}{$router}; $up_abs='m' if $$rcfg{'options'}{'perminute'}{$router}; if ($$cfg{'userrdtool'} || $$rcfg{'userrdtool'}{$router}) { require 'RRDs.pm'; my %dstype = qw/u COUNTER a ABSOLUTE g GAUGE h COUNTER m COUNTER/; $up_abs = $dstype{$up_abs}; # update the database. my $rrd = "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${main::SL}$router.rrd"; if (! -e $rrd) { # create the rrd if it doesn't exist my $now = time; $now = int($now / ($$cfg{interval} * 60) ) * ($$cfg{interval} * 60); RRDs::create($rrd, '-b', $now, '-s', int($$cfg{interval} * 60), "DS:ds0:$up_abs:600:U:U", "DS:ds1:$up_abs:600:U:U", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797"); my $e = $RRDs::error; die "Cannot create logfile: $e\n" if $e; } # update the rrd RRDs::update("$rrd", "$time:$inlast:$outlast"); my $e = $RRDs::error; die "Cannot update logfile: $e" if ($e); # the html pages and the graphics are created at "call time" so that's it! # (the returned hashes are empty, it's just to minimize the changes to mrtg) if ($$rcfg{'options'}{'dorelpercent'}{$router}) { return (\%maxin, \%maxout, \%maxpercent, \%avin, \%avout, \%avpercent, \%cuin, \%cuout, \%cupercent); } else { return (\%maxin, \%maxout, \%avin, \%avout, \%cuin, \%cuout); } } # if ($$cfg{userrdtool}) ((($main::OS eq 'NT') && (-e "$main::binpath${main::SL}rateup.exe")) || (-x "$main::binpath${main::SL}rateup")) || die "Can't Execute '$main::binpath${main::SL}rateup'\n"; # if ($$rcfg{'options'}{'dorelpercent'}{$router}) { @exec = ("$main::binpath${main::SL}rateup", "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}","$router", $time, $$rcfg{'options'}{'unknaszero'}{$router} ? '-z':'-Z', "$up_abs"."p", $inlast, $outlast, $absmax, "C", $$rcfg{'rgb1'}{$router},$$rcfg{'rgb2'}{$router}, $$rcfg{'rgb3'}{$router},$$rcfg{'rgb4'}{$router}, $$rcfg{'rgb5'}{$router});}else { @exec = ("$main::binpath${main::SL}rateup", "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}","$router", $time, $$rcfg{'options'}{'unknaszero'}{$router} ? '-z':'-Z', "$up_abs", $inlast, $outlast, $absmax, "c", $$rcfg{'rgb1'}{$router},$$rcfg{'rgb2'}{$router}, $$rcfg{'rgb3'}{$router},$$rcfg{'rgb4'}{$router});} # VMS: I dont think this is really needed # if ($main::OS eq 'VMS') { # @exec = ("\$verify = \'f\$verify(0)\'\n", # "\$set default $main::binpath\n", # "\$rateup = \"\$$cfg{'workdir'}rateup\"\n", # "\$rateup $router", # "u", $inlast, $outlast, $absmax) } push (@exec, '-t') if defined $$rcfg{'options'}{'transparent'}{$router}; my $maxx = $$rcfg{'xsize'}{$router}; my $maxy = $$rcfg{'ysize'}{$router}; my $xscale = $$rcfg{'xscale'}{$router}; my $yscale = $$rcfg{'yscale'}{$router}; my $growright = 0+$$rcfg{'options'}{'growright'}{$router}; my $bits = 0+$$rcfg{'options'}{'bits'}{$router}; my $integer = 0+$$rcfg{'options'}{'integer'}{$router}; my $step = 5*60; my $rop; my $ytics = $$rcfg{'ytics'}{$router}; my $yticsf= $$rcfg{'yticsfactor'}{$router}; if ($$rcfg{'ylegend'}{$router}) { push (@exec, "l", "[$$rcfg{'ylegend'}{$router}]"); } my $sign = ($$rcfg{'unscaled'}{$router} =~ /d/) ? 1 : -1; if ($$rcfg{'kilo'}{$router}) { push (@exec, "k", $$rcfg{'kilo'}{$router}); } if ($$rcfg{'kmg'}{$router}) { push (@exec, "K", $$rcfg{'kmg'}{$router}); } if ($$rcfg{'weekformat'}{$router}){ push (@exec, "W", $$rcfg{'weekformat'}{$router}); } if ($$rcfg{'suppress'}{$router} !~/d/){ # VMS: should work for both now push (@exec, "i", "${router}-day.gif", $sign*$maxvi, $sign*$maxvo, $maxx, $maxy, ,$xscale, $yscale, $growright, $step, $bits, $ytics, $yticsf); @mxvls = ("d"); push (@metas, "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-day.gif", $$cfg{'interval'} ? $$cfg{'interval'} : 5); } my $SAGE = (time - $main::STARTTIME) / 3600 / 24; # current script age if (((not -e "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-week.gif") || ((-M "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-week.gif") + $SAGE >= 0.5/24)) && ($$rcfg{'suppress'}{$router} !~/w/) ) { $step=30*60; $sign = ($$rcfg{'unscaled'}{$router} =~ /w/) ? 1 : -1; push (@mxvls , "w"); $rop =($$rcfg{'withpeak'}{$router} =~ /w/) ? "p" : "i"; push (@exec, $rop ,"${router}-week.gif", $sign*$maxvi, $sign*$maxvo, $maxx, $maxy, $xscale, $yscale, $growright, $step, $bits, $ytics, $yticsf); push (@metas, "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-week.gif", 30); } if (((not -e "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-month.gif") || (( -M "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-month.gif") + $SAGE >= 2/24)) && ($$rcfg{'suppress'}{$router} !~/m/)) { $step=2*60*60; $sign = ($$rcfg{'unscaled'}{$router} =~ /m/) ? 1 : -1; push (@mxvls , "m"); $rop =($$rcfg{'withpeak'}{$router} =~ /m/) ? "p" : "i"; push (@exec, $rop ,"${router}-month.gif", $sign*$maxvi, $sign*$maxvo, $maxx, $maxy, $xscale, $yscale, $growright, $step, $bits, $ytics, $yticsf); push (@metas, "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-month.gif", 120); } if (((not -e "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-year.gif") || (( -M "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-year.gif") + $SAGE >= 1)) && ($$rcfg{'suppress'}{$router} !~/y/)) { $step=24*60*60; $sign = ($$rcfg{'unscaled'}{$router} =~ /y/) ? 1 : -1; push (@mxvls , "y"); $rop =($$rcfg{'withpeak'}{$router} =~ /y/) ? "p" : "i"; push (@exec, $rop, "${router}-year.gif", $sign*$maxvi, $sign*$maxvo, $maxx, $maxy, $xscale, $yscale, $growright, $step, $bits, $ytics, $yticsf) ; push (@metas, "$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}${router}-year.gif", 1440); } print "EXEC: ",(join " ", @exec),"\n" if $main::DEBUG; # VMS: this might work now ... or does VMS NOT know about pipes? # NT doesn't have fork() so an open(xxx,"-|") won't work if ($main::OS eq 'VMS' || $main::OS eq 'NT') { open (RATEUP, join (" ", @exec)."|"); } else { open (RATEUP,"-|") || exec @exec; } # Original VMS Patch ... ends up with rateup output in a # array ... # open (COMMAND, ">mrtg-temp.com") || # die ("Can't open command file\n"); # print COMMAND "@exec"; # close COMMAND; # @rateup = `\@mrtg-temp.com` if (open (HTML,"<$$cfg{'workdir'}${main::SL}$$rcfg{'directory'}{$router}$router.html")) { for ($i=0 ; $i<40 ; $i++) { $_=<HTML>; if (/<!-- maxin ([dwmy]) (\d*)/) { $maxin{$1}{$router}=0+$2; }; if (/<!-- maxout ([dwmy]) (\d*)/) { $maxout{$1}{$router}=0+$2; }; if (/<!-- maxpercent ([dwmy]) (\d*)/) { $maxpercent{$1}{$router}=0+$2; }; if (/<!-- avin ([dwmy]) (\d*)/) { $avin{$1}{$router}=0+$2; }; if (/<!-- avout ([dwmy]) (\d*)/) { $avout{$1}{$router}=0+$2; }; if (/<!-- avpercent ([dwmy]) (\d*)/) { $avpercent{$1}{$router}=0+$2; }; if (/<!-- cuin ([dwmy]) (\d*)/) { $cuin{$1}{$router}=0+$2; }; if (/<!-- cuout ([dwmy]) (\d+)/) { $cuout{$1}{$router}=0+$2; }; if (/<!-- cupercent ([dwmy]) (\d+)/) { $cupercent{$1}{$router}=0+$2; }; } close HTML; }; foreach $period (@mxvls) { chomp($res = <RATEUP>); print "$period: maxin \"$res\"\n" if $main::DEBUG >2; $maxin{$period}{$router}=sprintf("%.0f",0+$res); chomp($res = <RATEUP>); print "$period: maxout \"$res\"\n" if $main::DEBUG >2; $maxout{$period}{$router}=sprintf("%.0f",0+$res); if ($$rcfg{'options'}{'dorelpercent'}{$router}) { chomp($res = <RATEUP>); print "$period: maxpercent \"$res\"\n" if $main::DEBUG >2; $maxpercent{$period}{$router}=sprintf("%.0f",0+$res); } chomp($res = <RATEUP>); print "$period: avin \"$res\"\n" if $main::DEBUG >2; $avin{$period}{$router}=sprintf("%.0f",0+$res); chomp($res = <RATEUP>); print "$period: avout \"$res\"\n" if $main::DEBUG >2; $avout{$period}{$router}=sprintf("%.0f",0+$res); if ($$rcfg{'options'}{'dorelpercent'}{$router}) { chomp($res = <RATEUP>); print "$period: avpercent \"$res\"\n" if $main::DEBUG >2; $avpercent{$period}{$router}=sprintf("%.0f",0+$res); } chomp($res = <RATEUP>); print "$period: cuin \"$res\"\n" if $main::DEBUG >2; $cuin{$period}{$router}=sprintf("%.0f",0+$res); chomp($res = <RATEUP>); print "$period: cuout \"$res\"\n" if $main::DEBUG >2; $cuout{$period}{$router}=sprintf("%.0f",0+$res); if ($$rcfg{'options'}{'dorelpercent'}{$router}) { chomp($res = <RATEUP>); print "$period: cupercent \"$res\"\n" if $main::DEBUG >2; $cupercent{$period}{$router}=sprintf("%.0f",0+$res); } } close(RATEUP); if ($?) { my $value = $?; my $signal = $? & 127; #ignore the most significant bit #as it is always one when it is a returning #child says dave ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -