diff options
author | Ole Mathias Heggem <ole@sdok.no> | 2017-04-19 23:16:07 +0200 |
---|---|---|
committer | Ole Mathias Heggem <ole@sdok.no> | 2017-04-19 23:16:07 +0200 |
commit | 7b97188b728c85c498acc8acdce1750c472f2c85 (patch) | |
tree | 12c1436ab7eb97e9434e774671e8ffea134d61db /collectors/snmpfetchng.pl | |
parent | f70f65f7466a480a45a8260b35887cb7ed36b466 (diff) | |
parent | 7d404abf07d865d253ac2cfc353741e8d4af4867 (diff) |
Merge remote-tracking branch 'refs/remotes/tech-server/master'
Diffstat (limited to 'collectors/snmpfetchng.pl')
-rwxr-xr-x | collectors/snmpfetchng.pl | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/collectors/snmpfetchng.pl b/collectors/snmpfetchng.pl index b961cac..1d352a1 100755 --- a/collectors/snmpfetchng.pl +++ b/collectors/snmpfetchng.pl @@ -7,7 +7,7 @@ use POSIX; use SNMP; use Data::Dumper; use lib '/opt/gondul/include'; -use nms qw(convert_mac); +use nms qw(convert_mac convert_decimal); use IO::Socket::IP; SNMP::initMib(); @@ -56,15 +56,6 @@ sub mylog printf STDERR "[%s] %s\n", $time, $msg; } -# Hack to avoid starting the collector before graphite is up. -sleep(5); -my $sock = IO::Socket::IP->new( - PeerHost => "$nms::config::graphite_host:$nms::config::graphite_port", - Timeout => 20, - ) or die "Cannot connect - $@"; - - $sock->blocking( 0 ); - sub populate_switches { @switches = (); @@ -109,7 +100,7 @@ sub inner_loop } } mylog( "Polling " . @switches . " switches: $poll_todo"); - SNMP::MainLoop(10); + SNMP::MainLoop(6); } sub callback{ @@ -121,51 +112,39 @@ sub callback{ my @nicids; my $total = 0; my $now_graphite = time(); + my %tree2; for my $ret (@top) { for my $var (@{$ret}) { for my $inner (@{$var}) { $total++; my ($tag,$type,$name,$iid, $val) = ( $inner->tag ,$inner->type , $inner->name, $inner->iid, $inner->val); - if ($tag eq "ifPhysAddress") { + if ($tag eq "ifPhysAddress" or $tag eq "jnxVirtualChassisMemberMacAddBase") { $val = convert_mac($val); } $tree{$iid}{$tag} = $val; if ($tag eq "ifIndex") { push @nicids, $iid; } + if ($tag =~ m/^jnxVirtualChassisMember/) { + $tree2{'vcm'}{$tag}{$iid} = $val; + } + if ($tag =~ m/^jnxVirtualChassisPort/ ) { + my ($member,$lol,$interface) = split(/\./,$iid,3); + my $decoded_if = convert_decimal($interface); + $tree2{'vcp'}{$tag}{$member}{$decoded_if} = $val; + } } } } - my %tree2; for my $nic (@nicids) { $tree2{'ports'}{$tree{$nic}{'ifName'}} = $tree{$nic}; - for my $tmp_key (keys $tree{$nic}) { - my $field = $tree{$nic}{'ifName'}; - $field =~ s/[^a-z0-9]/_/gi; - my $path = "snmp.$switch{'sysname'}.ports.$field.$tmp_key"; - my $value = $tree{$nic}{$tmp_key}; - if ($value =~ m/^\d+$/) { - print $sock "$path $value $now_graphite\n"; - } - - } delete $tree{$nic}; } for my $iid (keys %tree) { for my $key (keys %{$tree{$iid}}) { $tree2{'misc'}{$key}{$iid} = $tree{$iid}{$key}; - my $localiid = $iid; - if ($localiid eq "") { - $localiid = "_"; - } - $localiid =~ s/[^a-z0-9]/_/gi; - my $path = "snmp.$switch{'sysname'}.misc.$key.$localiid"; - my $value = $tree{$iid}{$key}; - if ($value =~ m/^\d+$/) { - print $sock "$path $value $now_graphite\n"; - } } } if ($total > 0) { @@ -175,7 +154,9 @@ sub callback{ or die "Couldn't unlock switch"; $dbh->commit; if ($total > 0) { - mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s."); + if ((time - $switch{'start'}) > 10) { + mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s."); + } } else { mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s - no data. Timeout?"); } |