Chinaunix首页 | 论坛 | 博客
  • 博客访问: 423558
  • 博文数量: 72
  • 博客积分: 1599
  • 博客等级: 上尉
  • 技术积分: 1125
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-16 13:22
文章分类

全部博文(72)

文章存档

2014年(3)

2013年(8)

2012年(23)

2011年(23)

2010年(15)

分类: PERL

2013-05-29 10:34:02

打开mrgt执行文件"/usr/bin/mrtg",修改getexternal函数:

  1. sub getexternal ($) {
  2.     my $command = shift;
  3.     my $in=undef;
  4.     my $out=undef;
  5.     my $uptime="unknown";
  6.     my $name="unknown";
  7.     my $ctime=""; ##### add by kerecsen.liang #####

  8.     open (EXTERNAL , $command."|")
  9.         or warn "$NOW: WARNING: Running '$command': $!n";

  10.     warn "$NOW: WARNING: Could not get any data from external command ".
  11.         "'".$command.
  12.             "'nMaybe the external command did not even start. ($!)nn" if eof EXTERNAL;

  13.     chomp( $in=<EXTERNAL>) unless eof EXTERNAL;
  14.     chomp( $out=<EXTERNAL>) unless eof EXTERNAL;
  15.     chomp( $uptime=<EXTERNAL>) unless eof EXTERNAL;
  16.     chomp( $name=<EXTERNAL>) unless eof EXTERNAL;
  17.     chomp( $ctime=<EXTERNAL>) unless eof EXTERNAL; ##### add by kerecsen.liang #####


  18.     close EXTERNAL;

  19.     # strip returned date
  20.     $uptime =~ s/^s*(.*?)s*/$1/;
  21.     $name =~ s/^s*(.*?)s*/$1/;
  22.     # do we have numbers in the external programs answer ?
  23.     if ( not defined $in ) {
  24.         warn "$NOW: WARNING: Problem with External get '$command':n".
  25.             " Expected a Number for 'in' but nothing'nn";
  26.     } elsif ( $in eq 'UNKNOWN' ) {
  27.         $in = undef;
  28.     } elsif ( $in !~ /([-+]?d+(.d+)?)/ ) {
  29.         warn "$NOW: WARNING: Problem with External get '$command':n".
  30.             " Expected a Number for 'in' but got '$in'nn";
  31.         $in = undef;
  32.     } else {
  33.         $in = $1;
  34.     }

  35.     if ( not defined $out ) {
  36.         warn "$NOW: WARNING: Problem with External get '$command':n".
  37.             " Expected a Number for 'out' but nothing'nn";
  38.     } elsif ( $out eq 'UNKNOWN' ) {
  39.         $out = undef;
  40.     } elsif ( $out !~ /([-+]?d+(.d+)?)/ ) {
  41.         warn "$NOW: WARNING: Problem with External get '$command':n".
  42.             " Expected a Number for 'out' but got '$out'nn";
  43.         $out = undef;
  44.     } else {
  45.         $out = $1;
  46.     }

  47.     if ( $ctime eq "" ) { ##### add by kerecsen.liang #####
  48.         $ctime=time; ##### add by kerecsen.liang #####
  49.     } ##### add by kerecsen.liang #####

  50.     debug('snpo',"External result:".($in||"undef")." out:".($out||"undef")." uptime:".($uptime||"undef")." name:".($name||"undef"));
  51.     return ($in,$out,$ctime,$uptime,$name); ##### change time to $ctime,change by kerecsen.liang #####
  52. }


阅读(1351) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~