diff options
Diffstat (limited to 'clients')
-rwxr-xr-x | clients/dhcptail.pl | 59 | ||||
-rwxr-xr-x | clients/fetch-cubemap-munin.sh | 17 | ||||
-rwxr-xr-x | clients/ipv6-dns.pl | 138 | ||||
-rw-r--r-- | clients/ipv6-stats.pl | 98 | ||||
-rwxr-xr-x | clients/ping.pl | 100 | ||||
-rwxr-xr-x | clients/smanagrun.pl | 156 | ||||
-rwxr-xr-x | clients/snmpfetchng.pl | 141 |
7 files changed, 0 insertions, 709 deletions
diff --git a/clients/dhcptail.pl b/clients/dhcptail.pl deleted file mode 100755 index 9c2111f..0000000 --- a/clients/dhcptail.pl +++ /dev/null @@ -1,59 +0,0 @@ -#! /usr/bin/perl -use DBI; -use POSIX; -use lib '../include'; -use nms; -use strict; -use Data::Dumper; -use warnings; - -BEGIN { - require "../include/config.pm"; - eval { - require "../include/config.local.pm"; - }; -} - -my $year = $nms::config::tgname; -$year =~ s/tg/20/; # hihi - -my %months = ( - Jan => 1, - Feb => 2, - Mar => 3, - Apr => 4, - May => 5, - Jun => 6, - Jul => 7, - Aug => 8, - Sep => 9, - Oct => 10, - Nov => 11, - Dec => 12 -); - -my $realtime = 0; -my ($dbh, $q,$check); -$dbh = nms::db_connect(); -$q = $dbh->prepare("INSERT INTO dhcp (switch,time,ip,mac) VALUES((SELECT switch FROM switches WHERE ?::inet << subnet4 ORDER BY sysname LIMIT 1),?,?,?)"); -$check = $dbh->prepare("SELECT max(time)::timestamp - ?::timestamp < '0s'::interval as doit FROM dhcp;"); - -open(SYSLOG, "tail -n 9999999 -F /var/log/syslog |") or die "Unable to tail syslog: $!"; -while (<SYSLOG>) { - /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d+)\s+(\d+:\d+:\d+).*DHCPACK on (\d+\.\d+\.\d+\.\d+) to (\S+) / or next; - my $date = $year . "-" . $months{$1} . "-" . $2 . " " . $3 . " Europe/Oslo"; - my $machine = $5; - my $via = $6; - $check->execute($date); - $dbh->commit; - my $cond = $check->fetchrow_hashref(); - if (!defined($cond) or !defined($cond->{'doit'}) or $cond->{'doit'} eq '1') { - if ($realtime != 1) { - $realtime = 1; - print "real time achieved...\n"; - } - $q->execute($4,$date,$4,$machine); - $dbh->commit; - } -} -close SYSLOG; diff --git a/clients/fetch-cubemap-munin.sh b/clients/fetch-cubemap-munin.sh deleted file mode 100755 index 0cc62e2..0000000 --- a/clients/fetch-cubemap-munin.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -tgyear="tg16" -reflector1="finn" -reflector2="rey" - -if [ $# -eq 0 ]; then - epoch_to=`date +%s` - epoch_date="`date +%Y%m%d-%H%M`" -else - epoch_to=`date --date "$1" +%s` - epoch_date="`date --date \"$1\" +%Y%m%d-%H%M`" -fi -let "epoch_from = epoch_to - (60 * 60 * 24)" - -wget -qO"/root/tgmanage/examples/$tgyear/streams/streamstats/cubemap_${reflector1}_detailed-$epoch_date.png" "http://munin.$tgyear.gathering.org/munin-cgi/munin-cgi-graph/$tgyear.gathering.org/${reflector1}.$tgyear.gathering.org/cubemap-pinpoint=$epoch_from,$epoch_to.png?&lower_limit=&upper_limit=&size_x=1280&size_y=720" -wget -qO"/root/tgmanage/examples/$tgyear/streams/streamstats/cubemap_${reflector2}_detailed-$epoch_date.png" "http://munin.$tgyear.gathering.org/munin-cgi/munin-cgi-graph/$tgyear.gathering.org/${reflector2}.$tgyear.gathering.org/cubemap-pinpoint=$epoch_from,$epoch_to.png?&lower_limit=&upper_limit=&size_x=1280&size_y=720" - diff --git a/clients/ipv6-dns.pl b/clients/ipv6-dns.pl deleted file mode 100755 index dcb059d..0000000 --- a/clients/ipv6-dns.pl +++ /dev/null @@ -1,138 +0,0 @@ -#! /usr/bin/perl -use DBI; -use Net::DNS; -use Net::IP; -use lib '../include'; -use nms; -use strict; -use warnings; - -BEGIN { -require "../include/config.pm"; - eval { - require "../include/config.local.pm"; - }; -} - -my $dbh = nms::db_connect() or die "Can't connect to database"; -my $res = Net::DNS::Resolver->new; - -$res->nameservers("$nms::config::pri_hostname.$nms::config::tgname.gathering.org"); - -my $kname = 'DHCP_UPDATER'; - -sub get_reverse { - my ($ip) = shift; - $ip = new Net::IP($ip) or return 0; - my $a = $res->query($ip->reverse_ip, 'PTR') or return 0; - foreach my $n ($a->answer) { - return $n->{'ptrdname'}; # Return first element, ignore the rest (= - } - return 0; -} - -sub any_quad_a { - my ($host) = shift; - my $a = $res->query($host, 'AAAA') or return 0; - foreach my $n ($a->answer) { - return 1 if ($n->{'type'} eq 'AAAA'); - } - return 0; -} - -print "Running automagic IPv6 DNS updates\n"; -while (1) { - - # Fetch visible IPv6 addresses from the last three minutes - #my $q = $dbh->prepare("SELECT DISTINCT ON (ipv6.mac) ipv6.address AS v6, ipv6.mac, ipv4.address AS v4, ipv6.time - ipv6.age*'1 second'::interval FROM ipv6 LEFT JOIN ipv4 ON ipv4.mac = ipv6.mac WHERE ipv6.time > NOW()-'3 min'::interval ORDER BY ipv6.mac, ipv6.time DESC, mac") - my $q = $dbh->prepare( -"SELECT DISTINCT ON (v6) v6, ipv6.mac, ipv6.seen, v4 -FROM (SELECT DISTINCT ON (address) address AS v6, mac, seen FROM seen_mac WHERE family(address) = 6 AND seen > CURRENT_TIMESTAMP - '3 min'::interval) ipv6 -LEFT JOIN (SELECT DISTINCT ON (address) address AS v4, mac, seen FROM seen_mac WHERE family(address) = 4 AND seen > CURRENT_TIMESTAMP - '3 min'::interval) ipv4 ON ipv4.mac = ipv6.mac -ORDER BY v6, ipv6.seen DESC, mac") - or die "Can't prepare query"; - $q->execute() or die "Can't execute query"; - - my $aaaas = 0; - my $aaaa_errors = 0; - my $ptrs = 0; - my $ptr_errors = 0; - my $update; - my $v6; - while (my $ref = $q->fetchrow_hashref()) { - my $hostname = get_reverse($ref->{'v4'}); - if ($hostname) { - $v6 = $ref->{'v6'}; - my @parts = split('\.', $hostname); - my $hostname = shift @parts; - my $domain = join('.', @parts); - my $v6arpa = (new Net::IP($v6))->reverse_ip; - - # Don't add records for nets we don't control - next if not $v6arpa =~ m/$nms::config::ipv6zone/; - - # Add IPv6 reverse - if (!get_reverse($ref->{'v6'})) { - $update = Net::DNS::Update->new($nms::config::ipv6zone); - $update->push(pre => nxrrset("$v6arpa IN PTR")); # Only update if the RR is nonexistent - $update->push(update => rr_add("$v6arpa IN PTR $hostname.$domain.")); - $update->sign_tsig($kname, $nms::config::ddns_key); - my $reply = $res->send($update); - if ($reply->header->rcode eq 'NOERROR') { - $ptrs++; - } else { - $ptr_errors++; - } - } - - # Add IPv6 forward - if (!any_quad_a("$hostname.$domain")) { - $update = Net::DNS::Update->new($domain); - $update->push(pre => nxrrset("$hostname.$domain. IN AAAA $v6")); # Only update if the RR is nonexistent - $update->push(update => rr_add("$hostname.$domain. IN AAAA $v6")); - $update->sign_tsig($kname, $nms::config::ddns_key); - my $reply = $res->send($update); - if ($reply->header->rcode eq 'NOERROR') { - $aaaas++; - } else { - $aaaa_errors++; - } - } - } - } - print "Added $ptrs PTR records. $ptr_errors errors occured.\n"; - print "Added $aaaas AAAA records. $aaaa_errors errors occured.\n"; - - - # Remove old PTR records, that is, for hosts we haven't seen the last four - # hours, but not older than four and a half hours, as it would take forever to - # try to delete everything. FIXME: Query the zone file and diff against the - # database, to avoid running as many NS-updates as tuples in the result set. - - $q = $dbh->prepare("SELECT DISTINCT address AS v6 FROM seen_mac WHERE seen BETWEEN CURRENT_TIMESTAMP - '4 hours'::interval AND CURRENT_TIMESTAMP - '4 hours 30 minutes'::interval") - or die "Can't prepare query"; - $q->execute() or die "Can't execute query"; - - my $i = 0; - my $errors = 0; - while (my $ref = $q->fetchrow_hashref()) { - $v6 = $ref->{'v6'}; - if (get_reverse($v6)) { - my $v6arpa = (new Net::IP($v6))->reverse_ip; - my $update = Net::DNS::Update->new($nms::config::ipv6zone); - $update->push(pre => yxrrset("$v6arpa PTR")); # Only update if the RR exists - $update->push(update => rr_del("$v6arpa IN PTR")); - $update->sign_tsig($kname, $nms::config::ddns_key); - my $reply = $res->send($update); - if ($reply->header->rcode eq 'NOERROR') { - $i++; - } else { - $errors++; - } - } - } - - print "Deleted $i old PTR records. $errors errors occured.\n"; - print "Sleeping for two minutes.\n"; - sleep(120); -} diff --git a/clients/ipv6-stats.pl b/clients/ipv6-stats.pl deleted file mode 100644 index ab76cc9..0000000 --- a/clients/ipv6-stats.pl +++ /dev/null @@ -1,98 +0,0 @@ -#! /usr/bin/perl -use strict; -use warnings; -use lib '../include'; -use nms; -use Data::Validate::IP qw(is_public_ipv6 is_public_ipv4 is_private_ipv4); -use Net::MAC qw(mac_is_unicast); - -my $dbh = nms::db_connect(); -$dbh->{AutoCommit} = 0; - -while (1) { - my $coregws = $dbh->prepare("SELECT ip, community, sysname FROM switches WHERE switchtype <> 'dlink3100'") - or die "Can't prepare query: $!"; - $coregws->execute; - - my %seen = (); - my $num_v4 = 0; - my $num_v6 = 0; - while (my $ref = $coregws->fetchrow_hashref) { - print STDERR "Querying ".$ref->{'sysname'}." ...\n"; - my $snmp; - eval { - $snmp = nms::snmp_open_session($ref->{'ip'}, $ref->{'community'}); - }; - warn $@ if $@; - next if not $snmp; - - # Pull in old media table that does not support ipv6. - my $ip_phys_table = fetch($snmp, ('ipNetToMediaNetAddress', 'ipNetToMediaPhysAddress')); - for my $entry (values %$ip_phys_table) { - my $ip_addr = $entry->{'ipNetToMediaNetAddress'}; - my $mac = Net::MAC->new( - mac => nms::convert_mac($entry->{'ipNetToMediaPhysAddress'}), - die => 0, - ); - - next if $mac->get_base() != 16 || $mac->get_mac() eq ''; # We only support base 16 addresses - next if (!is_public_ipv4($ip_addr) && !is_private_ipv4($ip_addr)); # We consider RFC1918 public - - $seen{$ip_addr} = $mac->get_mac(); - $num_v4++; - } - - # Pull in new media table with IPv6 support - $ip_phys_table = $snmp->gettable('ipNetToPhysicalTable'); - for my $entry (values %$ip_phys_table) { - my $type = $entry->{'ipNetToPhysicalNetAddressType'}; - my $ip_addr = undef; - my $mac = Net::MAC->new( - mac => nms::convert_mac($entry->{'ipNetToPhysicalPhysAddress'}), - die => 0, - ); - - if ($type != 2) { - warn "$ip_addr is of unexpected type $type (should be 2)! Tell Berge.\n"; - next; - } - - $ip_addr = nms::convert_ipv6($entry->{'ipNetToPhysicalNetAddress'}); - - next if $mac->get_base() != 16 || $mac->get_mac() eq ''; # We only support base 16 addresses - next if not is_public_ipv6($ip_addr); - - $seen{$ip_addr} = $mac->get_mac(); - $num_v6++; - } - - } - - # Populate database - my $i = 0; - foreach my $ip_addr (keys %seen) { - $i++; - my $q = $dbh->do('INSERT INTO seen_mac (address, mac) VALUES (?, ?)', undef, $ip_addr, $seen{$ip_addr}) - or die "Can't execute query: $!"; - } - - $dbh->commit; - print "Collected $num_v6 IPv6 addresses and $num_v4 IPv4 addresses. $i unique addresses.\n"; - print "Sleeping for 60 seconds ...\n"; - sleep(60); -} - - -# Fetch provided fields from a single table returning {iid => {tag => val}} -sub fetch { - my $session = shift; - my @vars = map { new SNMP::Varbind([$_]) } @_; - my $data = {}; - foreach my $result (@{$session->bulkwalk(0, 8, new SNMP::VarList(@vars))}) { - foreach my $entry (@$result) { - $data->{$entry->iid}->{$entry->tag} = $entry->val; - } - } - return $data; -} - diff --git a/clients/ping.pl b/clients/ping.pl deleted file mode 100755 index d945917..0000000 --- a/clients/ping.pl +++ /dev/null @@ -1,100 +0,0 @@ -#! /usr/bin/perl -use DBI; -use POSIX; -use Time::HiRes; -use Net::Oping; -use strict; -use warnings; -use Data::Dumper; - -use lib '../include'; -use nms; - -$|++; -my $dbh = nms::db_connect(); -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; - -my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null ORDER BY random()"); -my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null"); - -while (1) { - # ping loopbacks - my $ping = Net::Oping->new; - $ping->timeout(0.3); - - $q->execute; - my %ip_to_switch = (); - my %secondary_ip_to_switch = (); - while (my $ref = $q->fetchrow_hashref) { - my $switch = $ref->{'switch'}; - - my $ip = $ref->{'ip'}; - $ping->host_add($ip); - $ip_to_switch{$ip} = $switch; - - my $secondary_ip = $ref->{'secondary_ip'}; - if (defined($secondary_ip)) { - $ping->host_add($secondary_ip); - $secondary_ip_to_switch{$secondary_ip} = $switch; - } - } - my $result = $ping->ping(); - my %dropped = %{$ping->get_dropped()}; - die $ping->get_error if (!defined($result)); - - $dbh->do('COPY ping (switch, latency_ms) FROM STDIN'); # date is implicitly now. - my $drops = 0; - while (my ($ip, $latency) = each %$result) { - my $switch = $ip_to_switch{$ip}; - next if (!defined($switch)); - - if (!defined($latency)) { - $drops += $dropped{$ip}; - } - $latency //= "\\N"; - $dbh->pg_putcopydata("$switch\t$latency\n"); - } - if ($drops > 0) { - print "$drops "; - } - $dbh->pg_putcopyend(); - - $dbh->do('COPY ping_secondary_ip (switch, latency_ms) FROM STDIN'); # date is implicitly now. - while (my ($ip, $latency) = each %$result) { - my $switch = $secondary_ip_to_switch{$ip}; - next if (!defined($switch)); - - $latency //= "\\N"; - $dbh->pg_putcopydata("$switch\t$latency\n"); - } - $dbh->pg_putcopyend(); - - $dbh->commit; - # ping linknets - $ping = Net::Oping->new; - $ping->timeout(0.3); - - $lq->execute; - my @linknets = (); - while (my $ref = $lq->fetchrow_hashref) { - push @linknets, $ref; - $ping->host_add($ref->{'addr1'}); - $ping->host_add($ref->{'addr2'}); - } - if (@linknets) { - $result = $ping->ping(); - die $ping->get_error if (!defined($result)); - - $dbh->do('COPY linknet_ping (linknet, latency1_ms, latency2_ms) FROM STDIN'); # date is implicitly now. - for my $linknet (@linknets) { - my $id = $linknet->{'linknet'}; - my $latency1 = $result->{$linknet->{'addr1'}} // '\N'; - my $latency2 = $result->{$linknet->{'addr2'}} // '\N'; - $dbh->pg_putcopydata("$id\t$latency1\t$latency2\n"); - } - $dbh->pg_putcopyend(); - } - $dbh->commit; -} - diff --git a/clients/smanagrun.pl b/clients/smanagrun.pl deleted file mode 100755 index 9df4b96..0000000 --- a/clients/smanagrun.pl +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/perl -# -# - -use warnings; -use strict; -use Net::Telnet; -use DBI; -use POSIX; -use Data::Dumper::Simple; -use lib '../include'; -use nms; - -BEGIN { - require "../include/config.pm"; - eval { - require "../include/config.local.pm"; - }; -} -# Tweak and check -my $password = ''; -my $delaytime = 30; - -my $dbh = db_connect(); -$dbh->{AutoCommit} = 0; - -my $spoll = $dbh->prepare(" -SELECT - addr, - sysname -FROM - squeue -WHERE - processed = 'f' AND - disabled = 'f' AND - (locked='f' OR now() - updated > '10 minutes'::interval) AND - (delay IS NULL OR delay < now()) -ORDER BY - priority DESC, - added -LIMIT 1"); -my $sgetallpoll = $dbh->prepare(" -SELECT - id, - gid, - addr, - sysname, - cmd -FROM - squeue -WHERE - sysname = ? AND - disabled = 'f' AND - processed = 'f' -ORDER BY - priority DESC, - added"); - -my $slock = $dbh->prepare("UPDATE squeue SET locked = 't', updated=now() WHERE sysname = ?") - or die "Unable to prepare slock"; -my $sunlock = $dbh->prepare("UPDATE squeue SET locked = 'f', updated=now() WHERE sysname = ?") - or die "Unable to prepare sunlock"; -my $sresult = $dbh->prepare("UPDATE squeue SET updated = now(), result = ?, - processed = 't' WHERE id = ?") - or die "Unable to prepare sresult"; -my $sdelay = $dbh->prepare("UPDATE squeue SET delay = now() + delaytime, updated=now(), result = ? WHERE sysname = ?") - or die "Unable to prepae sdelay"; - -sub mylog { - my $msg = shift; - my $time = POSIX::ctime(time); - $time =~ s/\n.*$//; - printf STDERR "[%s] %s\n", $time, $msg; -} - -while (1) { - $spoll->execute() or die "Could not execute spoll"; - my $switch = $spoll->fetchrow_hashref(); - if (!defined($switch)) { - $dbh->commit; - mylog("No available switches in pool, sleeping."); - sleep 10; - next; - } - $slock->execute($switch->{sysname}); - $dbh->commit(); - - if ($switch->{'locked'}) { - mylog("WARNING: Lock timed out on $switch->{'ip'}, breaking lock"); - } - - mylog("Connecting to $switch->{sysname} on $switch->{addr}"); - eval { - my $ssh = switch_connect_ssh($switch->{addr}); - my $conn = $ssh->{telnet}; - if (!defined($conn)) { - mylog("Could not connect to ".$switch->{sysname}."(".$switch->{addr}.")"); - $sdelay->execute("Could not connect to switch, delaying...", $switch->{sysname}); - $sunlock->execute($switch->{sysname}); - $dbh->commit(); - next; - } - my $error; - $error = $sgetallpoll->execute($switch->{sysname}); - if (!$error) { - print "Could not execute sgetallpoll\n".$dbh->errstr(); - switch_disconnect($ssh); - next; - } - while (my $row = $sgetallpoll->fetchrow_hashref()) { - my $sysname = $row->{sysname}; - my @data; - my @commands = split(/[\r\n\000]+/, $row->{cmd}); - for my $cmd (@commands) { - next unless $cmd =~ /\S/; # ignorer linjer med kun whitespace - $cmd =~ s/%SYSNAME%/$sysname/g; - print "sysname: $sysname cmd: $cmd\n"; - push @data, "# $cmd"; - if ($cmd =~ /^#\s*require-version\s+(.*\S)\s*$/) { - my $required_version = $1; - my $version; - foreach my $line (switch_exec("show version", $conn)) { - if ($line =~ /^JUNOS Base OS boot \[(.*)\]/) { - $version = $1; - } elsif ($line =~ /^Junos: (.*\S)/) { - $version = $1; - } - last if defined $version; - } - if ($version ne $required_version) { - push @data, "# '$version' != '$required_version', aborting script"; - last; - } else { - push @data, "# Version matches"; - } - } elsif ($cmd =~ s/^!//) { - push @data, switch_exec($cmd, $conn, 1); - } else { - push @data, switch_exec($cmd, $conn); - } - } - my $result = join("\n", @data); - $sresult->execute($result, $row->{id}); - } - switch_disconnect($ssh); - $sunlock->execute($switch->{sysname}); - }; - if ($@) { - warn $@; - chomp(my $err = $@); - $sdelay->execute($err . ", delaying...", $switch->{sysname}); - $sunlock->execute($switch->{sysname}); - $dbh->commit(); - } -} - diff --git a/clients/snmpfetchng.pl b/clients/snmpfetchng.pl deleted file mode 100755 index 2f5e785..0000000 --- a/clients/snmpfetchng.pl +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -use DBI; -use POSIX; -#use Time::HiRes qw(time); -use SNMP; -use Data::Dumper; -use lib '../include'; -use nms; - -SNMP::initMib(); -SNMP::addMibDirs("/srv/tgmanage/mibs/StandardMibs"); -SNMP::addMibDirs("/srv/tgmanage/mibs/JuniperMibs"); -SNMP::addMibDirs("/srv/tgmanage/mibs"); -SNMP::loadModules('ALL'); - -our $dbh = nms::db_connect(); -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; - -my $qualification = <<"EOF"; -(last_updated IS NULL OR now() - last_updated > poll_frequency) -AND (locked='f' OR now() - last_updated > '15 minutes'::interval) -AND mgmt_v4_addr is not null -EOF - -# Borrowed from snmpfetch.pl -our $qswitch = $dbh->prepare(<<"EOF") -SELECT - sysname,switch,host(mgmt_v4_addr) as ip,community, - DATE_TRUNC('second', now() - last_updated - poll_frequency) AS overdue -FROM - switches -WHERE -$qualification -ORDER BY - overdue DESC -LIMIT ? -EOF - or die "Couldn't prepare qswitch"; -our $qlock = $dbh->prepare("UPDATE switches SET locked='t', last_updated=now() WHERE switch=?") - or die "Couldn't prepare qlock"; -our $qunlock = $dbh->prepare("UPDATE switches SET locked='f', last_updated=now() WHERE switch=?") - or die "Couldn't prepare qunlock"; -my @switches = (); - -my $sth = $dbh->prepare("INSERT INTO snmp (switch,data) VALUES((select switch from switches where sysname=?), ?)"); - -sub mylog -{ - my $msg = shift; - my $time = POSIX::ctime(time); - $time =~ s/\n.*$//; - printf STDERR "[%s] %s\n", $time, $msg; -} - -sub populate_switches -{ - @switches = (); - my $limit = $nms::config::snmp_max; - $qswitch->execute($limit) - or die "Couldn't get switch"; - $dbh->commit; - while (my $ref = $qswitch->fetchrow_hashref()) { - push @switches, { - 'sysname' => $ref->{'sysname'}, - 'id' => $ref->{'switch'}, - 'mgtip' => $ref->{'ip'}, - 'community' => $ref->{'community'} - }; - } -} - -sub inner_loop -{ - populate_switches(); - my $poll_todo = ""; - for my $refswitch (@switches) { - my %switch = %{$refswitch}; - $poll_todo .= "$switch{'sysname'} "; - - $switch{'start'} = time; - $qlock->execute($switch{'id'}) - or die "Couldn't lock switch"; - $dbh->commit; - my $s = SNMP::Session->new(DestHost => $switch{'mgtip'}, - Community => $switch{'community'}, - UseEnums => 1, - Version => '2'); - my $ret = $s->bulkwalk(0, 10, @nms::config::snmp_objects, sub{ callback(\%switch, @_); }); - if (!defined($ret)) { - mylog("Fudge: ". $s->{'ErrorStr'}); - } - } - mylog( "Polling " . @switches . " switches: $poll_todo"); - SNMP::MainLoop(10); -} - -sub callback{ - my @top = $_[1]; - my %switch = %{$_[0]}; - my %tree; - my %ttop; - my %nics; - my @nicids; - - for my $ret (@top) { - for my $var (@{$ret}) { - for my $inner (@{$var}) { - my ($tag,$type,$name,$iid, $val) = ( $inner->tag ,$inner->type , $inner->name, $inner->iid, $inner->val); - if ($tag eq "ifPhysAddress") { - next; - } - $tree{$iid}{$tag} = $val; - if ($tag eq "ifIndex") { - push @nicids, $iid; - } - } - } - } - - my %tree2; - for my $nic (@nicids) { - $tree2{'ports'}{$tree{$nic}{'ifName'}} = $tree{$nic}; - delete $tree{$nic}; - } - for my $iid (keys %tree) { - for my $key (keys %{$tree{$iid}}) { - $tree2{'misc'}{$key}{$iid} = $tree{$iid}{$key}; - } - } - $sth->execute($switch{'sysname'}, JSON::XS::encode_json(\%tree2)); - $qunlock->execute($switch{'id'}) - or die "Couldn't unlock switch"; - $dbh->commit; - mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s."); -} -while (1) { - inner_loop(); -} |