aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org
diff options
context:
space:
mode:
authorMagnus Kirø <magnuskiro@gmail.com>2016-03-22 11:14:46 +0100
committerMagnus Kirø <magnuskiro@gmail.com>2016-03-22 11:14:46 +0100
commit7806081670c8c9807fc8b6628b3d7a6eff841ded (patch)
tree082e522b99cd5b864a8963523f2b3889f6cff808 /web/nms.gathering.org
parente501dd7dd88bf52edd914a8f078141b91d53939b (diff)
parent2d19233ba32fd23ad7182d3cccb58cec9e377a75 (diff)
MERGE fix.
Diffstat (limited to 'web/nms.gathering.org')
-rwxr-xr-xweb/nms.gathering.org/api/private/switch-add4
-rwxr-xr-xweb/nms.gathering.org/api/private/switch-update4
-rwxr-xr-xweb/nms.gathering.org/api/public/dhcp19
-rwxr-xr-xweb/nms.gathering.org/api/public/switch-state13
-rwxr-xr-xweb/nms.gathering.org/api/public/switches3
-rw-r--r--web/nms.gathering.org/js/nms-info-box.js77
-rw-r--r--web/nms.gathering.org/js/nms-map.js44
-rw-r--r--web/nms.gathering.org/js/nms.js8
8 files changed, 116 insertions, 56 deletions
diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add
index 70d6212..48f62fc 100755
--- a/web/nms.gathering.org/api/private/switch-add
+++ b/web/nms.gathering.org/api/private/switch-add
@@ -22,7 +22,7 @@ my @dups;
my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip');
+my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip');
sub convertplace
{
@@ -81,7 +81,7 @@ foreach my $tmp2 (@tmp) {
} keys %switch;
- $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});");
+ $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});");
push @added, $switch{'sysname'};
}
}
diff --git a/web/nms.gathering.org/api/private/switch-update b/web/nms.gathering.org/api/private/switch-update
index 3d7b119..6507d2b 100755
--- a/web/nms.gathering.org/api/private/switch-update
+++ b/web/nms.gathering.org/api/private/switch-update
@@ -22,7 +22,7 @@ my @dups;
my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip');
+my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip');
sub convertplace
{
@@ -81,7 +81,7 @@ foreach my $tmp2 (@tmp) {
} keys %switch;
- $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});");
+ $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});");
push @added, $switch{'sysname'};
} else {
if (defined($switch{'placement'})) {
diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp
new file mode 100755
index 0000000..d432af0
--- /dev/null
+++ b/web/nms.gathering.org/api/public/dhcp
@@ -0,0 +1,19 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+use lib '../../../../include';
+use nms::web qw (%json finalize_output);
+use strict;
+use warnings;
+use Data::Dumper;
+
+my $q = $nms::web::dbh->prepare('select distinct on (sysname) extract(epoch from date_trunc(\'second\',time)) as time,sysname from dhcp join switches on dhcp.switch = switches.switch where ' . $nms::web::when . ' order by sysname,time desc;');
+$q->execute();
+while ( my $ref = $q->fetchrow_hashref() ) {
+ my $sysname = $ref->{'sysname'};
+ $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'};
+}
+
+$nms::web::cc{'max-age'} = "5";
+$nms::web::cc{'stale-while-revalidate'} = "30";
+finalize_output();
diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state
index 62d0078..6f7573c 100755
--- a/web/nms.gathering.org/api/public/switch-state
+++ b/web/nms.gathering.org/api/public/switch-state
@@ -20,7 +20,7 @@ while ( my $ref = $q->fetchrow_hashref() ) {
my %port = %{$data{'ports'}{$porti}};
my $smallport = $porti;
$smallport =~ s/[0-9-].*$//;
- if ($porti =~ /ge-0\/0\/4[4-7]/ or $porti eq 'eth0') {
+ if ($porti =~ /ge-0\/0\/4[4-7]/) {
$json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
$json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
if ($port{'ifOperStatus'} eq "up") {
@@ -29,12 +29,15 @@ while ( my $ref = $q->fetchrow_hashref() ) {
$json{'switches'}{$sysname}{'uplinks'}{'total'} += 1;
}
- $json{'switches'}{$sysname}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'switches'}{$sysname}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
+ $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'};
+ $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
+ $json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'};
+ $json{'switches'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{$smallport}{'live'} += 1;
+ $json{'switches'}{$sysname}{ifs}{$smallport}{'live'} += 1;
+ $json{'switches'}{$sysname}{totals}{'live'} += 1;
}
- $json{'switches'}{$sysname}{$smallport}{'total'} += 1;
+ $json{'switches'}{$sysname}{totals}{'total'} += 1;
}
$json{'switches'}{$sysname}{'time'} = $ref->{'time'};
}
diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches
index 8447b2b..7e7f10b 100755
--- a/web/nms.gathering.org/api/public/switches
+++ b/web/nms.gathering.org/api/public/switches
@@ -12,14 +12,13 @@ use Data::Dumper;
$nms::web::cc{'max-age'} = "60";
-my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,switchtype,poll_frequency,community,last_updated from switches where placement is not null');
+my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,poll_frequency,community,last_updated from switches where placement is not null');
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
$ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/;
my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4);
my $sysname = $ref->{'sysname'};
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'switchtype'} = $ref->{'switchtype'};
$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'x'} = $x2;
$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'y'} = $y2;
$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2;
diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js
index e0f9273..24c1e31 100644
--- a/web/nms.gathering.org/js/nms-info-box.js
+++ b/web/nms.gathering.org/js/nms-info-box.js
@@ -251,6 +251,8 @@ nmsInfoBox._windowTypes.switchInfo = {
content.push([v, html]);
}
+ content.sort();
+
var table = nmsInfoBox._makeTable(content, "edit");
domObj.appendChild(table);
@@ -318,6 +320,7 @@ nmsInfoBox._windowTypes.switchInfo = {
nmsInfoBox.click = function(sw)
{
this.showWindow("switchInfo",sw);
+ this._windowTypes.switchInfo.showComments();
};
/*
@@ -394,33 +397,37 @@ nmsInfoBox._makeCommentTable = function(content) {
};
nmsInfoBox._searchSmart = function(id, sw) {
- if (nmsData.smanagement.switches[sw].distro == id) {
- console.log("ieh");
- return true;
- }
- if (id.match("[a-z]+.active")) {
- console.log("hei: " + sw);
- var family = id.match("[a-z]+");
- var limit = id;
- limit = limit.replace(family + ".active>","");
- limit = limit.replace(family + ".active<","");
- limit = limit.replace(family + ".active=","");
- var operator = id.replace(family + ".active","")[0];
- if (limit == parseInt(limit)) {
- if (operator == ">" ) {
- if (nmsData.switchstate.switches[sw][family].live > limit) {
- return true;
- }
- } else if (operator == "<") {
- if (nmsData.switchstate.switches[sw][family].live < limit) {
- return true;
- }
- } else if (operator == "=") {
- if (nmsData.switchstate.switches[sw][family].live == limit) {
- return true;
+ try {
+ if (nmsData.smanagement.switches[sw].distro == id) {
+ return true;
+ }
+ if (id.match("active")) {
+ var limit = id;
+ limit = limit.replace("active>","");
+ limit = limit.replace("active<","");
+ limit = limit.replace("active=","");
+ var operator = id.replace("active","")[0];
+ if (limit == parseInt(limit)) {
+ if (operator == ">" ) {
+ if (nmsData.switchstate.switches[sw]['totals'].live > limit) {
+ return true;
+ }
+ } else if (operator == "<") {
+ if (nmsData.switchstate.switches[sw]['totals'].live < limit) {
+ return true;
+ }
+ } else if (operator == "=") {
+ if (nmsData.switchstate.switches[sw]['totals'].live == limit) {
+ return true;
+ }
}
}
}
+ if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) {
+ return true;
+ }
+ } catch (e) {
+ return false;
}
return false;
};
@@ -437,6 +444,7 @@ nmsInfoBox._search = function() {
id = el.value;
}
if(id) {
+ nmsMap.enableHighlights();
for(var sw in nmsData.switches.switches) {
if (id[0] == "/") {
if (nmsInfoBox._searchSmart(id.slice(1),sw)) {
@@ -455,23 +463,32 @@ nmsInfoBox._search = function() {
}
}
} else {
- nmsMap.removeAllSwitchHighlights();
+ nmsMap.disableHighlights();
}
if(matches.length == 1) {
document.getElementById("searchbox-submit").classList.add("btn-primary");
document.getElementById("searchbox").dataset.match = matches[0];
- document.getElementById("searchbox").addEventListener("keydown",nmsInfoBox._searchKeyListener,false);
} else {
document.getElementById("searchbox-submit").classList.remove("btn-primary");
document.getElementById("searchbox").dataset.match = '';
- document.getElementById("searchbox").removeEventListener("keydown",nmsInfoBox._searchKeyListener,false);
}
};
nmsInfoBox._searchKeyListener = function(e) {
- if(e.keyCode == 13) {
- var sw = document.getElementById("searchbox").dataset.match;
- nmsInfoBox.showWindow("switchInfo",sw);
+ switch (e.keyCode) {
+ case 13:
+ var sw = document.getElementById("searchbox").dataset.match;
+ if(sw != '') {
+ nmsInfoBox.showWindow("switchInfo",sw);
+ this._windowTypes.switchInfo.showComments();
+ }
+ break;
+ case 27:
+ document.getElementById("searchbox").dataset.match = '';
+ document.getElementById("searchbox").value = '';
+ nmsInfoBox._search();
+ nmsInfoBox.hide();
+ break;
}
};
diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js
index c6bad49..ffedcbf 100644
--- a/web/nms.gathering.org/js/nms-map.js
+++ b/web/nms.gathering.org/js/nms-map.js
@@ -10,7 +10,8 @@
* nmsMap.setSwitchColor(switch,color)
* nmsMap.setSwitchInfo(switch,info)
* nmsMap.setSwitchHighlight(switch,true/false)
- * nmsMap.removeAllSwitchHighlights()
+ * nmsMap.enableHighlights()
+ * nmsMap.disableHighlights()
*/
@@ -47,6 +48,7 @@ var nmsMap = nmsMap || {
_color: { },
_highlight: { },
+ _highlightActive: false,
_c: {}
};
@@ -73,21 +75,29 @@ nmsMap.setSwitchColor = function(sw, color) {
}
};
+
nmsMap.setSwitchHighlight = function(sw, highlight) {
- if(highlight)
- highlight == true;
- if (this._highlight[sw] != highlight) {
- this._highlight[sw] = highlight;
- this._drawSwitch(sw);
- this.stats.highlightChange++;
- }
+ if( highlight )
+ highlight = true;
+ if ( this._highlight[sw] != highlight ) {
+ this.stats.highlightChange++;
+ this._highlight[sw] = highlight;
+ }
+ this._drawSwitch(sw);
};
-nmsMap.removeAllSwitchHighlights = function() {
- for(var sw in this._highlight)
- this.setSwitchHighlight(sw,false);
+
+nmsMap.enableHighlights = function() {
+ this._highlightActive = true;
};
+
+nmsMap.disableHighlights = function() {
+ this._highlightActive = false;
+ this._drawAllSwitches();
+};
+
+
nmsMap.reset = function() {
for (var sw in this._color) {
nmsMap.setSwitchColor(sw, undefined);
@@ -236,7 +246,7 @@ nmsMap._drawSwitchBlur = function(sw)
this._c.blur.ctx.fillStyle = "red";
this._c.blur.ctx.shadowBlur = 30;
this._c.blur.ctx.shadowColor = "white";
- this._c.blur.ctx.scale(this.scale, this.scale); // FIXME
+ this._c.blur.ctx.scale(this.scale, this.scale); // FIXME <- fix what?!
this._c.blur.ctx.fillRect(box['x'],box['y'],box['width'],box['height']);
this._c.blur.ctx.restore();
};
@@ -249,8 +259,12 @@ nmsMap._drawSwitch = function(sw)
return;
var box = this._getBox(sw);
var color = nmsMap._color[sw];
- if(nmsMap._highlight[sw]) {
- color = red;
+ if(this._highlightActive) {
+ if(nmsMap._highlight[sw]) {
+ color = green;
+ } else {
+ color = white;
+ }
}
if (color == undefined) {
color = blue;
@@ -336,7 +350,7 @@ nmsMap._drawAllBlur = function() {
nmsMap._drawBox = function(ctx, x, y, boxw, boxh) {
ctx.save();
- ctx.scale(this.scale, this.scale); // FIXME
+ ctx.scale(this.scale, this.scale); // FIXME <- what?!
ctx.fillRect(x,y, boxw, boxh);
ctx.lineWidth = 1;
ctx.strokeStyle = "#000000";
diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js
index c1f8da2..8d28028 100644
--- a/web/nms.gathering.org/js/nms.js
+++ b/web/nms.gathering.org/js/nms.js
@@ -481,6 +481,7 @@ function initNMS() {
detectHandler();
nms.playback.play();
setupKeyhandler();
+ setupSearchKeyHandler();
}
function detectHandler() {
@@ -607,6 +608,13 @@ function setupKeyhandler()
});
}
+function setupSearchKeyHandler()
+{
+ $("#searchbox").keyup(function(e) {
+ nmsInfoBox._searchKeyListener(e);
+ });
+}
+
function getCookie(cname) {
var name = cname + "=";