aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@einstein.tg15.gathering.org>2015-03-31 14:00:09 +0200
committerroot <root@einstein.tg15.gathering.org>2015-03-31 14:00:09 +0200
commit8a76ac019ac8f9c1409c4a34a74a4a38ae025d8c (patch)
treebabd876bf36f6c6de0157acec7228c233964f2ef
parent49a9639ccd52d4a07a0a0263c948c3cfdf0bd696 (diff)
Fix uplink map (requires SQL changes)
-rwxr-xr-xclients/snmpfetch.pl15
-rwxr-xr-xweb/nms.gathering.org/uplinkkart.pl2
2 files changed, 11 insertions, 6 deletions
diff --git a/clients/snmpfetch.pl b/clients/snmpfetch.pl
index 1b43395..6eb9eb5 100755
--- a/clients/snmpfetch.pl
+++ b/clients/snmpfetch.pl
@@ -50,7 +50,7 @@ our $qlock = $dbh->prepare("UPDATE switches SET locked='t', last_updated=now() W
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";
-our $qpoll = $dbh->prepare("INSERT INTO polls (time, switch, port, bytes_in, bytes_out, errors_in, errors_out, official_port,operstatus) VALUES (timeofday()::timestamp,?,?,?,?,?,?,true,?)")
+our $qpoll = $dbh->prepare("INSERT INTO polls (time, switch, port, bytes_in, bytes_out, errors_in, errors_out, official_port,operstatus,ifdescr) VALUES (timeofday()::timestamp,?,?,?,?,?,?,true,?,?)")
or die "Couldn't prepare qpoll";
poll_loop(@ARGV);
@@ -148,6 +148,7 @@ sub poll_loop {
push @vars, ["ifOutOctets", $port];
push @vars, ["ifInErrors", $port];
push @vars, ["ifOutErrors", $port];
+ push @vars, ["ifDescr", $port];
push @vars, ["ifOperStatus", $port];
my $varlist = SNMP::VarList->new(@vars);
$session->get($varlist, [ \&callback, $switch_status, $port ]);
@@ -189,7 +190,8 @@ sub callback {
my ($switch, $port, $vars) = @_;
my ($in, $out, $ine, $oute) = (undef, undef, undef, undef);
- my $operstatus = "false";
+ my $operstatus = 2;
+ my $ifdescr = undef;
for my $var (@$vars) {
if ($port != $var->[1]) {
@@ -205,6 +207,8 @@ sub callback {
$oute = $var->[2];
} elsif ($var->[0] eq 'ifOperStatus') {
$operstatus = $var->[2];
+ } elsif ($var->[0] eq 'ifDescr') {
+ $ifdescr = $var->[2];
} else {
die "Response for unknown OID $var->[0].$var->[1]";
}
@@ -216,18 +220,19 @@ sub callback {
warn $switch->{'sysname'}.":$port: failed reading in";
}
$ok = 0;
- warn "no in";
}
if (!defined($out) || $out !~ /^\d+$/) {
if (defined($oute)) {
warn $switch->{'sysname'}.":$port: failed reading in";
}
$ok = 0;
- warn "no out";
+ }
+ if (!defined($ifdescr)) {
+ $ok = 0;
}
if ($ok) {
- $qpoll->execute($switch->{'switch'}, $port, $in, $out, $ine, $oute,$operstatus) || die "%s:%s: %s\n", $switch->{'switch'}, $port, $in;
+ $qpoll->execute($switch->{'switch'}, $port, $in, $out, $ine, $oute,$operstatus,$ifdescr) || die "%s:%s: %s\n", $switch->{'switch'}, $port, $in;
$dbh->commit;
} else {
warn $switch->{'sysname'} . " failed to OK.";
diff --git a/web/nms.gathering.org/uplinkkart.pl b/web/nms.gathering.org/uplinkkart.pl
index 135cd61..06160f9 100755
--- a/web/nms.gathering.org/uplinkkart.pl
+++ b/web/nms.gathering.org/uplinkkart.pl
@@ -40,7 +40,7 @@ for my $ports (0..4) {
$img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, $y + 10, $ports);
}
-my $q = $dbh->prepare('select switch,sysname,(select placement from placements where placements.switch=switches.switch) as placement,count((bytes_in > 0 and bytes_out > 0) or null) as active_ports from switches natural left join get_current_datarate() natural join placements where port between 45 and 48 and switchtype like \'dlink3100%\' group by switch,sysname');
+my $q = $dbh->prepare(' select switch,sysname,(select placement from placements where placements.switch = switches.switch) as placement,count((operstatus = 1) or null) as active_ports from switches natural left join get_operstatus() natural join placements where ifdescr = \'ge-0/0/44\' or ifdescr = \'ge-0/0/45\' or ifdescr = \'ge-0/0/46\' or ifdescr = \'ge-0/0/47\' group by switch,sysname');
$q->execute();
while (my $ref = $q->fetchrow_hashref()) {
my $ports = $ref->{'active_ports'};