aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--web/nms.gathering.org/api/API.rst15
-rwxr-xr-xweb/nms.gathering.org/api/private/port-state33
-rwxr-xr-xweb/nms.gathering.org/api/public/switch-state47
-rw-r--r--web/nms.gathering.org/js/nms.js1
4 files changed, 42 insertions, 54 deletions
diff --git a/web/nms.gathering.org/api/API.rst b/web/nms.gathering.org/api/API.rst
index 4751ee5..61fbb5a 100644
--- a/web/nms.gathering.org/api/API.rst
+++ b/web/nms.gathering.org/api/API.rst
@@ -46,15 +46,15 @@ Update frequency: on user input
Lists comments.
-/api/private/port-state
------------------------
+/api/private/snmp
+-----------------
Methods: GET
Update frequency: Every few seconds, based on SNMP data.
-Returns detailed per-port statistics. Being somewhat reorganized but will
-remain highly relevant.
+Returns full SNMP-data, split into two trees. 'misc' and 'ports'.
+
/api/private/switches-management
--------------------------------
@@ -70,10 +70,15 @@ List management information for switches.
Methods: POST
-Add switches, supports same format as tools/add_switches.txt.pl
+Add or update switches, supports same format as tools/add_switches.txt.pl
Accepts an array of switches.
+Magic: If you set placement to be "reset", it will re-calculate placement
+based on sysname. For new switches, this is redundant as an empty
+placement-field will trigger the same behavior.
+
+
Public
......
diff --git a/web/nms.gathering.org/api/private/port-state b/web/nms.gathering.org/api/private/port-state
deleted file mode 100755
index 8c6b64c..0000000
--- a/web/nms.gathering.org/api/private/port-state
+++ /dev/null
@@ -1,33 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '../../../../include';
-use nms::web;
-use strict;
-use warnings;
-
-my $query = 'select sysname,extract(epoch from date_trunc(\'second\',time)) as time, ifname,ifhighspeed,ifhcinoctets,ifhcoutoctets from polls natural join switches where time in (select max(time) from polls where ' . $nms::web::when . ' group by switch,ifname);';
-my $q = $nms::web::dbh->prepare($query);
-$q->execute();
-
-while (my $ref = $q->fetchrow_hashref()) {
- my @fields = ('ifhighspeed','ifhcoutoctets','ifhcinoctets');
- foreach my $val (@fields) {
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{$val} = $ref->{$val};
- }
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{'time'} = $ref->{'time'};
-}
-
-my $q3 = $nms::web::dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $nms::web::when . ' order by switch,time desc');
-
-
-$q3->execute();
-while (my $ref = $q3->fetchrow_hashref()) {
- my $sysname = $ref->{'sysname'};
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp'} = $ref->{'temp'};
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp_time'} = $ref->{'time'};
-}
-$nms::web::cc{'max-age'} = '2';
-$nms::web::cc{'stale-while-revalidate'} = '120';
-
-finalize_output();
diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state
index 999a1d8..cd9c0d2 100755
--- a/web/nms.gathering.org/api/public/switch-state
+++ b/web/nms.gathering.org/api/public/switch-state
@@ -2,12 +2,41 @@
# vim:ts=8:sw=8
use lib '../../../../include';
-use nms::web;
+use nms::web qw (%json finalize_output);
use strict;
use warnings;
+use Data::Dumper;
+
+my $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch);');
-my $query = 'select sysname,extract(epoch from date_trunc(\'second\',time)) as time, ifname,ifhighspeed,ifhcinoctets,ifhcoutoctets from polls natural join switches where time in (select max(time) from polls where ' . $nms::web::when . ' group by switch,ifname);';
-my $q = $nms::web::dbh->prepare($query);
+$q->execute();
+while (my $ref = $q->fetchrow_hashref()) {
+ my $sysname = $ref->{'sysname'};
+
+ my %data = %{JSON::XS::decode_json($ref->{'data'})};
+
+ for my $porti (keys %{$data{'ports'}}) {
+ my %port = %{$data{'ports'}{$porti}};
+ if ($porti =~ /ge-0\/0\/4[4-7]/ or $porti eq 'eth0') {
+ $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
+ $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
+ if ($port{'ifOperStatus'} eq "up") {
+ $json{'switches'}{$sysname}{'uplinks'}{'live'} += 1;
+ }
+ $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1;
+ }
+ $json{'switches'}{$sysname}{'ifHCInOctets'} += $port{'ifHCInOctets'};
+ $json{'switches'}{$sysname}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
+ if ($port{'ifOperStatus'} eq "up") {
+ $json{'switches'}{$sysname}{'live'} += 1;
+ }
+ $json{'switches'}{$sysname}{'total'} += 1;
+ }
+ $json{'switches'}{$sysname}{'time'} = $ref->{'time'};
+}
+
+finalize_output();
+exit;
$q->execute();
while (my $ref = $q->fetchrow_hashref()) {
@@ -29,18 +58,6 @@ while (my $ref = $q3->fetchrow_hashref()) {
$nms::web::json{'switches'}{$ref->{'sysname'}}{'temp'} = $ref->{'temp'};
}
-my $q2 = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) time,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " . $nms::web::when . " group by switch)");
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency'} = $ref->{'latency_ms'};
-}
-
-my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " . $nms::web::when . " ORDER BY switch, time DESC;");
-$qs->execute();
-while (my $ref = $qs->fetchrow_hashref()) {
- $nms::web::json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'};
-}
-
$nms::web::cc{'max-age'} = "5";
$nms::web::cc{'stale-while-revalidate'} = "30";
finalize_output();
diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js
index 025fab9..88407f3 100644
--- a/web/nms.gathering.org/js/nms.js
+++ b/web/nms.gathering.org/js/nms.js
@@ -475,7 +475,6 @@ function initNMS() {
// Private
nmsData.registerSource("snmp","/api/private/snmp");
- nmsData.registerSource("portstate","/api/private/port-state");
nmsData.registerSource("comments", "/api/private/comments");
nmsData.registerSource("smanagement","/api/private/switches-management");