check_centreon_snmp_traffic插件监控Linux虚拟机网卡的bug修订方法

测试check_centreon_snmp_traffic可以检测Windows的网卡流量,可以检测交换机的网卡流量,但不能检测Linux虚拟机的eth0网卡,显示的错误是 Error : Card speed is null, check command options

修复这个错误的方法如下:

把430行附近的

if (!$speed_card && !defined($opt_T)) {
    print "Error : Card speed is null, check command options\n";
    exit $ERRORS{'UNKNOWN'};
}


改为

if (!$speed_card && !defined($opt_T)) {
    #print "Error : Card speed is null, check command options\n";
    #exit $ERRORS{'UNKNOWN'};
    #xiugai
    if(!defined($in_bits)&&!defined($out_bits))
    {
        print "Error : Card speed is null, check command options\n";
        exit $ERRORS{'UNKNOWN'};
    }
    #set default 100Mb
    $speed_card = 100000000;
}


也就是当检测不到网卡速度($speed_card==0),但已经得到网卡流量数值($in_bits和$out_bits)时,把网卡速度默认赋值为100000000,即100Mb。这样就能得到检测结果了,由于-w和-c参数使用的是百分比,所以在设置这两个参数时要注意数值大小。

此外,默认命令行不输出状态结果,可以做如下修改,使得输出结果带状态字符串,例如下面开头的OK:

OK: Traffic In : 30.04 Mb/s (3.0 %), Out : 4.80 Mb/s (0.5 %) |traffic_in=30039837,6Bits/s;40000000;200000000;0;1000000000 traffic_out=4801448,7Bits/s;40000000;200000000;0;1000000000


修改方法是,把590行附近的

printf("Traffic In : %.2f ".$in_prefix."b/s (".$in_usage." %%), Out : %.2f ".$out_prefix."b/s (".$out_usage." %%) ", $in_traffic, $out_traffic);


改为

printf($status.": Traffic In : %.2f ".$in_prefix."b/s (".$in_usage." %%), Out : %.2f ".$out_prefix."b/s (".$out_usage." %%) ", $in_traffic, $out_traffic);

 



posted @ 2012-08-20 17:04  SmartDog  阅读(1346)  评论(1编辑  收藏  举报