![kerecsen kerecsen]()
打开mrgt执行文件"/usr/bin/mrtg",修改getexternal函数:
- sub getexternal ($) {
- my $command = shift;
- my $in=undef;
- my $out=undef;
- my $uptime="unknown";
- my $name="unknown";
- my $ctime=""; ##### add by kerecsen.liang #####
- open (EXTERNAL , $command."|")
- or warn "$NOW: WARNING: Running '$command': $!n";
- warn "$NOW: WARNING: Could not get any data from external command ".
- "'".$command.
- "'nMaybe the external command did not even start. ($!)nn" if eof EXTERNAL;
- chomp( $in=<EXTERNAL>) unless eof EXTERNAL;
- chomp( $out=<EXTERNAL>) unless eof EXTERNAL;
- chomp( $uptime=<EXTERNAL>) unless eof EXTERNAL;
- chomp( $name=<EXTERNAL>) unless eof EXTERNAL;
- chomp( $ctime=<EXTERNAL>) unless eof EXTERNAL; ##### add by kerecsen.liang #####
- close EXTERNAL;
- # strip returned date
- $uptime =~ s/^s*(.*?)s*/$1/;
- $name =~ s/^s*(.*?)s*/$1/;
- # do we have numbers in the external programs answer ?
- if ( not defined $in ) {
- warn "$NOW: WARNING: Problem with External get '$command':n".
- " Expected a Number for 'in' but nothing'nn";
- } elsif ( $in eq 'UNKNOWN' ) {
- $in = undef;
- } elsif ( $in !~ /([-+]?d+(.d+)?)/ ) {
- warn "$NOW: WARNING: Problem with External get '$command':n".
- " Expected a Number for 'in' but got '$in'nn";
- $in = undef;
- } else {
- $in = $1;
- }
- if ( not defined $out ) {
- warn "$NOW: WARNING: Problem with External get '$command':n".
- " Expected a Number for 'out' but nothing'nn";
- } elsif ( $out eq 'UNKNOWN' ) {
- $out = undef;
- } elsif ( $out !~ /([-+]?d+(.d+)?)/ ) {
- warn "$NOW: WARNING: Problem with External get '$command':n".
- " Expected a Number for 'out' but got '$out'nn";
- $out = undef;
- } else {
- $out = $1;
- }
- if ( $ctime eq "" ) { ##### add by kerecsen.liang #####
- $ctime=time; ##### add by kerecsen.liang #####
- } ##### add by kerecsen.liang #####
- debug('snpo',"External result:".($in||"undef")." out:".($out||"undef")." uptime:".($uptime||"undef")." name:".($name||"undef"));
- return ($in,$out,$ctime,$uptime,$name); ##### change time to $ctime,change by kerecsen.liang #####
- }
09-01 07:46