⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mrtg

📁 主要用于监控网络流量并动态产生可视化结果
💻
📖 第 1 页 / 共 5 页
字号:
     ['$arg && (-x $arg)','"Threshold program $arg cannot be executed"'],     'threshprogo[]' =>     ['$arg && (-x $arg)','"Threshold program $arg cannot be executed"'],     'threshprogoki[]' =>     ['$arg && (-x $arg)','"Threshold program $arg cannot be executed"'],     'threshprogoko[]' =>     ['$arg && (-x $arg)','"Threshold program $arg cannot be executed"'],     'userrdtool[]' =>     ['1','"Internal Error"']        );   my $braces = $second ? '[]':'';  if (exists $rules{$first.$braces}) {    if (eval($rules{$first.$braces}[0])) {      return 1;    } else {      if ($second) {	die "\nCFG Error in \"$first\[$second\]\", line $line: ".	  eval($rules{$first.$braces}[1])."\n\n";       } else {	die "\nCFG Error in \"$first\", line $line: ".	  eval($rules{$first.$braces}[1])."\n\n";       }     }  }  die "\nCFG Error: Unknown Option \"$first\" on line $line or above.\n".    "           Check readme.html for Help\n\n";}sub readcfg {  my ($first,$second,$key);  my (%seen);  my (@routers);  my (%rcfg,%cfg,%pre,%post,%deflt,%defaulted);  my ($cfgfile) = pop(@ARGV);  open (CFG, $cfgfile) || do { print "ERROR: unable to open config file: $cfgfile\n\n"; &printusage };  while (<CFG>) {    s/\s+$//g; #remove whitespace at the end of the line    s/\s/ /g;  #replace whitespace by space    next if /^\s*\#/; #ignore comment lines    next if /^\s*$/;  #ignore empty lines    # oops spelling error    s/^supress/suppress/gi;    # append mode    if ($first && /^\s+(.*\S)\s*$/) {      if ($second eq '^') {	$pre{$first} .= " $1";	next;      }      if ($second eq '$' ) {	$post{$first} .= " $1";	next;      }      if ($second eq '_') {	$deflt{$first} .= " $1";	next;      }      if ($second) {	$rcfg{$first}{$second} .= " $1";      } else {	$cfg{$first} .= " $1";      }      next;    }        if ($first && $second && $post{$first} && ($second !~ /^[\$^_]$/)) {      if ($defaulted{$first}{$second}) {        $rcfg{$first}{$second} = $post{$first};        delete $defaulted{$first}{$second};      } else {        $rcfg{$first}{$second} .= ( $post{$first} =~ /(.*)$cfg{'nospacechar'}$/ ? "$1" : " $post{$first}" );      }    }    if ($first && exists $deflt{$first} && ($second eq '_')) {      &quickcheck($first,$second,$deflt{$first},$.)    } elsif ($first && $second && ($second !~ /^[\$^_]$/)) {      &quickcheck($first,$second,$rcfg{$first}{$second},$.)    } elsif ($first && ($second !~ /^[\$^_]$/)) {      &quickcheck($first,0,$cfg{$first},$.)    }    if (/^([A-Za-z0-9]+)\[(\S+)\]\s*:\s*(.*\S?)\s*$/) {      print "readcfg: rcfg $1 $2  = $3\n" if $main::DEBUG > 1;       $first = lc($1);      $second = lc($2);      if ($second eq '^')        { if ($3 ne '') {$pre{$first}=$3} else {delete $pre{$first}}; next; }      if ($second eq '$')        { if ($3 ne '') {$post{$first}=$3} else {delete $post{$first}}; next; }      if ($second eq '_')        { if ($3 ne '') {$deflt{$first}=$3} else {delete $deflt{$first}}; next; }      push (@routers, $second) unless grep (/^$second$/, @routers);             # make sure that default tags spring into existance upon first       # call of a router      foreach $key (keys %deflt) {	if (! exists $rcfg{$key}{$second}) {	  $rcfg{$key}{$second} = $deflt{$key};	  $defaulted{$key}{$second} = 1;	}      }      # make sure that prefix-only tags spring into existance upon first       # call of a router      foreach $key (keys %pre) {	if (! exists $rcfg{$key}{$second}) {          delete $defaulted{$key}{$second} if $defaulted{$key}{$second};	  $rcfg{$key}{$second} = ( $pre{$key} =~ m/(.*)$cfg{'nospacechar'}$/ ? "$1" : "$pre{$key} " );	}      }      if ($seen{$first}{$second}) {	die ("\nLine $. in CFG file contains a duplicate definition for\n".	     "$first\[$second]. First definition is on line $seen{$first}{$second}\n")      } else {	$seen{$first}{$second} = $.;      }      if ($defaulted{$first}{$second}) {        $rcfg{$first}{$second} = '';        delete $defaulted{$first}{$second};      }      $rcfg{$first}{$second} .= $3;      next;    }    if (/^(\S+):\s*(.*\S)\s*$/) {      $first = lc($1);	      $cfg{$first} = $2;      $second = '';      next;    }    die ( "\nLine $. in CFG file does not make sense\n" );  }  # append $ stuff to the very last tag in cfg file if necessary   if ($first && $second && $post{$first} && ($second !~ /^[\$^_]$/)) {    if ($defaulted{$first}{$second}) {      $rcfg{$first}{$second} = $post{$first};      delete $defaulted{$first}{$second};    } else {      $rcfg{$first}{$second} .= ( $post{$first} =~ /(.*)$cfg{'nospacechar'}$/ ? "$1" : " $post{$first}" );          }  }    #check the last input line  if ($first && exists $deflt{$first} && ($second eq '_')) {    &quickcheck($first,$second,$deflt{$first},$.)  } elsif ($first && $second) {    &quickcheck($first,$second,$rcfg{$first}{$second},$.)  } elsif ($first) {    &quickcheck($first,0,$cfg{$first},$.)  }  close (CFG);  (\@routers, \%cfg, \%rcfg, $cfgfile);}sub cfgcheck {  my ($routers, $cfg, $rcfg) = @_;  my ($rou, $confname, $one_option);  my %target;  my $error="no";  my(@known_options) = qw(growright bits noinfo absolute gauge nopercent integer perhour perminute transparent dorelpercent unknaszero transparent);  if (! $$cfg{workdir}) {      warn ("\nERROR: \"WorkDir\" not specified\n");      $error = "yes";  }  $SNMP_util::CacheFile = "$$cfg{'workdir'}${main::SL}oid-mib-cache.txt";    if (defined $$cfg{loadmibs}) {    my($mibFile);    foreach $mibFile (split /[,\s]+/, $$cfg{loadmibs}) {      &snmpQueue_MIB_File($mibFile);    }  }  foreach $rou (@$routers) {    # and now for the testing    if (! $$rcfg{"title"}{$rou}) {      warn ("\nERROR: \"Title[$rou]\" not specified\n");      $error = "yes";    }	if ($$rcfg{'directory'}{$rou})	{		# They specified a directory for this router.  Append the		# pathname seperator to it (so that it can either be present or		# absent, and the rules for including it are the same).		$$rcfg{'directory'}{$rou} .= ${main::SL};		# remove any stray spaces ...		$$rcfg{'directory'}{$rou} =~ s/\s//g;	}    if (! $$rcfg{"pagetop"}{$rou}) {      warn ("\nERROR: \"PageTop[$rou]\" is not specified.\n");      $error = "yes";    } else {      # allow for linebreaks      $$rcfg{"pagetop"}{$rou} =~ s/\\n/\n/g;    }  if (exists $$rcfg{"pagefoot"}{$rou}) {    # allow for linebreaks    $$rcfg{"pagefoot"}{$rou} =~ s/\\n/\n/g;  }     $$rcfg{"maxbytes1"}{$rou} = $$rcfg{"maxbytes"}{$rou} unless $$rcfg{"maxbytes1"}{$rou};    $$rcfg{"maxbytes2"}{$rou} = $$rcfg{"maxbytes"}{$rou} unless $$rcfg{"maxbytes2"}{$rou};    if ($$rcfg{"maxbytes1"}{$rou} eq '') {      warn ("\nERROR: \"MaxBytes1[$rou]\" not specified\n");      $error = "yes";    }    if ($$rcfg{"maxbytes2"}{$rou} eq '') {      warn ("\nERROR: \"MaxBytes2[$rou]\" not specified\n");      $error = "yes";    }    # set default size     if (! exists $$rcfg{"xsize"}{$rou}) {      $$rcfg{"xsize"}{$rou}=400;    }     if (! exists $$rcfg{"ysize"}{$rou}) {      $$rcfg{"ysize"}{$rou}=100;    }    if (! exists $$rcfg{"ytics"}{$rou}) {      $$rcfg{"ytics"}{$rou}=4;    }    if (! exists $$rcfg{"yticsfactor"}{$rou}) {      $$rcfg{"yticsfactor"}{$rou}=1;    }        my $opttemp = lc($$rcfg{"options"}{$rou});    if (exists $$rcfg{"options"}{$rou}) {            my $opttemp = lc($$rcfg{"options"}{$rou});      	      delete $$rcfg{"options"}{$rou};      foreach $one_option (split /[,\s]+/, $opttemp) {	if (grep {$one_option eq $_} @known_options) {	  $$rcfg{'options'}{$one_option}{$rou} = 1;	} else {	  warn ("\nERROR: Option[$rou]: \"$one_option\" is unknown\n");	  $error="yes";	}      }    }    #    # Check out routeruptime definition    #        if ($$rcfg{"routeruptime"}{$rou}) {      ($$rcfg{"community"}{$rou},$$rcfg{"router"}{$rou}) =        split(/@/,$$rcfg{"routeruptime"}{$rou});    }    #    # Check out target definition    #        if ($$rcfg{"target"}{$rou}) {      print "TARGSTART: '".$$rcfg{"target"}{$rou}."'\n" if $main::DEBUG > 1;	          my ($pr) = "\$\$target\{'";      my ($po) = "'\}\{\$mode\}";      $$rcfg{targorig}{$rou} = $$rcfg{target}{$rou};      $$rcfg{target}{$rou}  =~ s/,/ \+ /g;            while ($$rcfg{target}{$rou}  =~ 	s/(-?)([a-z0-9\.&\/!-]+):([^\s]+)\@([-a-z0-9_\.]+(:[0-9.]*)*)(?=[\s\+\/\*]|$)/$pr$&$po/i)	{	my $targ=$&;       	my($oid1, $oid2) = ("","");	my $index = undef;	print "TARGNEW:   '".$$rcfg{"target"}{$rou}."'\n" if $main::DEBUG > 1;	print "TARGMATCH: '".$targ."'\n" if $main::DEBUG > 1;	$$rcfg{targtest}{$rou} .= "($pr$&$po == -1) || ";	$$rcfg{targcount}{$rou}++;	# my($host) = $4;	$target{$targ}{'ioswap'} = $1;	my($port) = $2;	$target{$targ}{'community'} = $3;	$target{$targ}{'router'} = $4;	if ($port =~ /^\d+$/) {   # By default get the input/output octets	  $oid1 = "ifInOctets.$port";	  $oid2 = "ifOutOctets.$port";	} elsif ($port =~ /^![0-9a-fA-F-]+$/)  {   # Physical Address	  $oid1 = "ifInOctets$port";	  $oid2 = "ifOutOctets$port";	} else {	    ($oid1, $oid2) = split(/\&/, $port,2) if ($port =~ /\&/);	}	printf " oid1: %s oid2: %s\n",$oid1,$oid2 if $main::DEBUG > 1;	if ($oid1 =~ /(^.+)\/(.+$)/) {	   if (!$target{$targ}{'ifindex'}{$2}) {printf "Requesting: oid: %s\n","ipAdEntIfIndex.$2" if $main::DEBUG > 1;	  	($target{$targ}{'ifindex'}{$2}) =		&snmpget($target{$targ}{'community'}."@".$target{$targ}{'router'},	     		"ipAdEntIfIndex.$2");printf "Response: oid: %s\n","ipAdEntIfIndex.$target{$targ}{'ifindex'}{$2}" if $main::DEBUG > 1;	   }	   $oid1 = "$1.$target{$targ}{'ifindex'}{$2}";	}	if ($oid2 =~ /(^.+)\/(.+$)/) {	   if (!$target{$targ}{'ifindex'}{$2}) {printf "Requesting: oid: %s\n","ipAdEntIfIndex.$2" if $main::DEBUG > 1;	  	($target{$targ}{'ifindex'}{$2}) =		&snmpget($target{$targ}{'community'}."@".$target{$targ}{'router'},	     		"ipAdEntIfIndex.$2");printf "Response: oid: %s\n","ipAdEntIfIndex.$target{$targ}{'ifindex'}{$2}" if $main::DEBUG > 1;	   }	   $oid2 = "$1.$target{$targ}{'ifindex'}{$2}";	}	#  Look up current ifindex for Physical Address	my ($phys,$var);	for ( \$oid1, \$oid2 ) {	   next if ! ($$_   =~ /(^.*)!(.+$)/);	   $phys = formatphysaddress($2);	   if (!$target{$targ}{'ifindex'}{$phys}) {	      ($target{$targ}{'ifindex'}{$phys}) =	         &getifindex($target{$targ}{'community'}."@".$target{$targ}{'router'},$phys);	      }printf "Physaddress: input <%s> output <%s>\n", $$_, $target{$targ}{'ifindex'}{$phys} if $main::DEBUG > 1;	   $$_ = "$1.$target{$targ}{'ifindex'}{$phys}";	   }	     	if (!$oid1 && !$oid2 && $port) {	   $port =~ s/\///;	   if (!$target{$targ}{'ifindex'}{$port}) {printf "Requesting: oid: %s\n","ipAdEntIfIndex.$port" if $main::DEBUG > 1;	  	($target{$targ}{'ifindex'}{$port}) =		&snmpget($target{$targ}{'community'}."@".$target{$targ}{'router'},	     		"ipAdEntIfIndex.$port");printf "Response: oid: %s\n","ipAdEntIfIndex.$target{$targ}{'ifindex'}{$port}" if $main::DEBUG > 1;	   }	   $oid1 = "ifInOctets.$target{$targ}{'ifindex'}{$port}";           $oid2 = "ifOutOctets.$target{$targ}{'ifindex'}{$port}";	}	printf "Result oid1: %s oid2: %s\n",$oid1,$oid2 if $main::DEBUG > 1;	  if (!$oid1 || !$oid2) {	    warn ("\nERROR: If specifying the full OID, you must specify\n".		  "2 full OID's separated by '&'. Error found with\n".		  "\"$&\" in \"Target[$rou]\"\n");	    $error = "yes";	  }	  $target{$targ}{'oid1'} = $oid1;	  $target{$targ}{'oid2'} = $oid2;      }            while ($$rcfg{"target"}{$rou} =~ /\`([^\`]+)\`(?=[\s\+\/\*]|$)/) {	my $cmd = $1;	my $targ = my $tq = $&;	$tq =~ s/['\\]/\\$&/g;	$$rcfg{"target"}{$rou} =~ s/\`([^\`]+)\`(?=[\s\+\/\*]|$)/$pr$tq$po/;	$$rcfg{targtest}{$rou} .= "($pr$tq$po == -1) || ";	$$rcfg{targcount}{$rou}++;	print "TARGSUBST:".$$rcfg{"target"}{$rou}."\n" if $main::DEBUG > 1;;	$target{$targ}{'command'} = $cmd;      }    } else {      warn ("\nERROR: I can't find a \"target[$rou]\" definition\n");      $error = "yes";    }        # colors format: name#hexcol,    if ($$rcfg{"colours"}{$rou}) {#warn ("\nINFO: \"colours\[$rou\]\" \n$$rcfg{'colours'}{$rou} \n");     if ($$rcfg{'options'}{'dorelpercent'}{$rou}) {      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})\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},	 $$rcfg{'col5'}{$rou}, $$rcfg{'rgb5'}{$rou}) = 	   ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);#	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},\n\#	 $$rcfg{'col5'}{$rou}, $$rcfg{'rgb5'}{$rou}");      } else {	warn ("\nERROR: \"colours[$rou]\" for colour definition\n".	      "       use the format: Name#hexcolour, Name#Hexcolour,...\n",	      "       note, that dorelpercent requires 5 colours");	$error="yes";      }     } else {            

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -