Perl Net::SNMP::接口 |接口错误
我有以下脚本,用于查看接口是否针对 Cisco 交换机出现错误。我遇到的唯一问题是当我清除接口上的计数器时,Net::SNMP 仍然显示它们:
Perl 脚本 (switch.pl):
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
use Net::SNMP;
use Net::SNMP::Interfaces;
use Net::SNMP::Interfaces::Details;
my @hosts;
push (@hosts, switch1);
foreach my $item (@hosts) {
checkinterfaces($item);
}
sub checkinterfaces {
my $host = shift;
my $interfaces = Net::SNMP::Interfaces->new(Hostname => $host, Community => 'public');
my @inter = $interfaces->all_interfaces();
for my $i (@inter) {
my $if = $i->name;
my $inerr = $i->ifInErrors;
my $outerr = $i->ifOutErrors;
if ($inerr > 0 || $outerr > 0 ){
print "$if is experiencing errors - Input Errors:$inerr/Output Errors:$outerr\n";
}
}
第一遍:
$ perl switch.pl
FastEthernet0/1 is experiencing errors - Input Errors:2201991/Output Errors:0
清除端口上的计数器:
switch1#sh int fa0/1
FastEthernet0/1 is up, line protocol is up (connected)
....
15470020 packets input, 2415584329 bytes, 0 no buffer
Received 29399 broadcasts (0 multicast)
0 runts, 1656 giants, 0 throttles
2199177 input errors, 2197521 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 22890 multicast, 0 pause input
0 input packets with dribble condition detected
53541600 packets output, 266583342 bytes, 0 underruns
0 output errors, 0 collisions, 2 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier, 0 PAUSE output
0 output buffer failures, 0 output buffers swapped out
switch1#clear counters fa0/1
Clear "show interface" counters on this interface [confirm]y
switch1#sh int fa0/1
FastEthernet0/1 is up, line protocol is up (connected)
....
1229 packets input, 1905693 bytes, 0 no buffer
Received 0 broadcasts (0 multicast)
0 runts, 0 giants, 0 throttles
297 input errors, 297 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
0 input packets with dribble condition detected
1334 packets output, 141440 bytes, 0 underruns
0 output errors, 0 collisions, 0 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier, 0 PAUSE output
0 output buffer failures, 0 output buffers swapped out
switch1#
第二遍:
$ perl switch.pl
FastEthernet0/20 is experiencing errors - Input Errors:2211150/Output Errors:0
接口仍然遇到错误,但是它似乎没有获得正确的值。
I have the following script that I am using to see if an interface has errors against Cisco switches. The only problem I am experiencing is when I clear counters on an interface, Net::SNMP still shows them:
Perl Script (switch.pl):
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
use Net::SNMP;
use Net::SNMP::Interfaces;
use Net::SNMP::Interfaces::Details;
my @hosts;
push (@hosts, switch1);
foreach my $item (@hosts) {
checkinterfaces($item);
}
sub checkinterfaces {
my $host = shift;
my $interfaces = Net::SNMP::Interfaces->new(Hostname => $host, Community => 'public');
my @inter = $interfaces->all_interfaces();
for my $i (@inter) {
my $if = $i->name;
my $inerr = $i->ifInErrors;
my $outerr = $i->ifOutErrors;
if ($inerr > 0 || $outerr > 0 ){
print "$if is experiencing errors - Input Errors:$inerr/Output Errors:$outerr\n";
}
}
First pass:
$ perl switch.pl
FastEthernet0/1 is experiencing errors - Input Errors:2201991/Output Errors:0
Clearing counters on the port:
switch1#sh int fa0/1
FastEthernet0/1 is up, line protocol is up (connected)
....
15470020 packets input, 2415584329 bytes, 0 no buffer
Received 29399 broadcasts (0 multicast)
0 runts, 1656 giants, 0 throttles
2199177 input errors, 2197521 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 22890 multicast, 0 pause input
0 input packets with dribble condition detected
53541600 packets output, 266583342 bytes, 0 underruns
0 output errors, 0 collisions, 2 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier, 0 PAUSE output
0 output buffer failures, 0 output buffers swapped out
switch1#clear counters fa0/1
Clear "show interface" counters on this interface [confirm]y
switch1#sh int fa0/1
FastEthernet0/1 is up, line protocol is up (connected)
....
1229 packets input, 1905693 bytes, 0 no buffer
Received 0 broadcasts (0 multicast)
0 runts, 0 giants, 0 throttles
297 input errors, 297 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
0 input packets with dribble condition detected
1334 packets output, 141440 bytes, 0 underruns
0 output errors, 0 collisions, 0 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier, 0 PAUSE output
0 output buffer failures, 0 output buffers swapped out
switch1#
Second Pass:
$ perl switch.pl
FastEthernet0/20 is experiencing errors - Input Errors:2211150/Output Errors:0
The interface is still experiencing errors, however it does not appear to be obtaining the correct value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您必须使用 snmp 将计数器设置回零。
From what I remember you have to set the counter back to zero with snmp.