aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xweb/nms-public.gathering.org/api/public/switch-state3
-rw-r--r--web/nms-public.gathering.org/js/nms-info-box.js54
-rw-r--r--web/nms-public.gathering.org/js/nms-map-handlers.js104
-rw-r--r--web/nms-public.gathering.org/js/nms-map.js39
-rw-r--r--web/nms-public.gathering.org/js/nms.js10
5 files changed, 146 insertions, 64 deletions
diff --git a/web/nms-public.gathering.org/api/public/switch-state b/web/nms-public.gathering.org/api/public/switch-state
index 32cf9a6..2a2b5b6 100755
--- a/web/nms-public.gathering.org/api/public/switch-state
+++ b/web/nms-public.gathering.org/api/public/switch-state
@@ -32,7 +32,6 @@ while ( my $ref = $q->fetchrow_hashref() ) {
}
$json{'switches'}{$sysname}{'uplinks'}{'total'} += 1;
}
-
$json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'};
$json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
$json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'};
@@ -43,6 +42,7 @@ while ( my $ref = $q->fetchrow_hashref() ) {
}
$json{'switches'}{$sysname}{totals}{'total'} += 1;
}
+ $json{'switches'}{$sysname}{'temp'} = $data{'misc'}{'enterprises.2636.3.1.13.1.7.7.1.0.0'}{''};
$json{'switches'}{$sysname}{'time'} = $ref->{'time'};
}
@@ -83,6 +83,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) {
}
$json{'then'}{$sysname}{totals}{'total'} += 1;
}
+ $json{'then'}{$sysname}{'temp'} = $data{'misc'}{'enterprises.2636.3.1.13.1.7.7.1.0.0'}{''};
$json{'then'}{$sysname}{'time'} = $ref->{'time'};
}
$nms::web::cc{'max-age'} = "5";
diff --git a/web/nms-public.gathering.org/js/nms-info-box.js b/web/nms-public.gathering.org/js/nms-info-box.js
index 2d12d56..0481420 100644
--- a/web/nms-public.gathering.org/js/nms-info-box.js
+++ b/web/nms-public.gathering.org/js/nms-info-box.js
@@ -5,9 +5,7 @@
*
* Interface: nmsInfoBox.showWindow(windowType,optionalParameter), nmsInfoBox.hide(), nmsInfoBox.refresh()
*
- * Any windowTypes should at a minimum implement load, unload, getTitle, getContent, getChildContent
- *
- * TODO: Implement useful update methods on windowTypes
+ * Any windowTypes should at a minimum implement load, update, unload, getTitle, getContent, getChildContent
*
*/
@@ -88,6 +86,7 @@ nmsInfoBox._show = function(argument) {
}
this._container.appendChild(panel);
this._container.style.display = "block";
+ $('[data-toggle="popover"]').popover({placement:"top",container:'body'});
};
/*
@@ -210,7 +209,7 @@ nmsInfoBox._windowTypes.switchInfo = {
}
},
getTitle: function() {
- return '<button type="button" class="edit btn btn-xs btn-warning" onclick="nmsInfoBox._windowTypes.switchInfo.showEdit(\'' + this.sw + '\');">Edit</button> <button type="button" class="comments btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showComments(\'' + this.sw + '\');">Comments</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'ports\');">Ports</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'misc\');">Misc</button> ' + this.sw + '';
+ return '<h4>' + this.sw + '</h4><button type="button" class="edit btn btn-xs btn-warning" onclick="nmsInfoBox._windowTypes.switchInfo.showEdit(\'' + this.sw + '\');">Edit</button> <button type="button" class="comments btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showComments(\'' + this.sw + '\');">Comments</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'ports\');">Ports</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'misc\');">Misc</button>';
},
getContent: function() {
return this.content;
@@ -219,6 +218,7 @@ nmsInfoBox._windowTypes.switchInfo = {
return this.childContent;
},
showComments: function() {
+ var oldView = this.activeView;
this.activeView = "comments";
var domObj = document.createElement("div");
var comments = [];
@@ -233,10 +233,6 @@ nmsInfoBox._windowTypes.switchInfo = {
if(!nmsData.comments || !nmsData.comments.comments) {
this.commentsHash = false;
- // We have data, but its old, so don't change data
- } else if(this.commentsHash != false && this.commentsHash == nmsData.comments.hash) {
- return;
-
// We have data, refresh
} else if(nmsData.comments.comments[this.sw]) {
this.commentsHash = nmsData.comments.hash;
@@ -251,7 +247,6 @@ nmsInfoBox._windowTypes.switchInfo = {
var commenttable = nmsInfoBox._makeCommentTable(comments);
commenttable.id = "info-switch-comments-table";
domObj.appendChild(commenttable);
- $(function () { $('[data-toggle="popover"]').popover({placement:"top",continer:'body'}) })
}
// We have no data for this switch, but its still correct
@@ -334,9 +329,14 @@ nmsInfoBox._windowTypes.switchInfo = {
nmsInfoBox.refresh();
},
unload: function() {
- this.childContent = false;
+ this.title = '';
+ this.content = '';
+ this.childContent = false;
+ this.sw = '';
+ this.swi = '';
+ this.swm = '';
this.commentsHash = false;
- this.activeView = "";
+ this.activeView = '';
},
save: function() {
var myData = nmsInfoBox._editStringify(this.sw);
@@ -346,6 +346,10 @@ nmsInfoBox._windowTypes.switchInfo = {
dataType: "text",
data:myData,
success: function (data, textStatus, jqXHR) {
+ var result = JSON.parse(data);
+ if(result.switches_updated.length > 0) { // FIXME unresolved variable switches_addded
+ nmsInfoBox.hide();
+ }
nmsData.invalidate("switches");
nmsData.invalidate("smanagement");
}
@@ -385,6 +389,7 @@ nmsInfoBox._makeTable = function(content, caption) {
}
for (var v in content) {
tr = table.insertRow(-1);
+ tr.className = content[v][0].toLowerCase();
td1 = tr.insertCell(0);
td2 = tr.insertCell(1);
td1.innerHTML = content[v][0];
@@ -438,7 +443,7 @@ nmsInfoBox._makeCommentTable = function(content) {
nmsInfoBox._searchSmart = function(id, sw) {
try {
- if (nmsData.smanagement.switches[sw].distro == id) {
+ if (nmsData.switches.switches[sw].distro_name == id) {
return true;
}
if (id.match("active")) {
@@ -463,15 +468,22 @@ nmsInfoBox._searchSmart = function(id, sw) {
}
}
}
- if (nmsData.smanagement.switches[sw].ip.match(id)) {
- return true;
- }
- if (nmsData.smanagement.switches[sw].subnet4.match(id)) {
- return true;
- }
- if (nmsData.smanagement.switches[sw].subnet6.match(id)) {
- return true;
- }
+ try {
+ if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) {
+ return true;
+ }
+ if (nmsData.smanagement.switches[sw].mgmt_v6_addr.match(id)) {
+ return true;
+ }
+ } catch (e) {}
+ try {
+ if (nmsData.smanagement.switches[sw].subnet4.match(id)) {
+ return true;
+ }
+ if (nmsData.smanagement.switches[sw].subnet6.match(id)) {
+ return true;
+ }
+ } catch (e) {}
if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) {
return true;
}
diff --git a/web/nms-public.gathering.org/js/nms-map-handlers.js b/web/nms-public.gathering.org/js/nms-map-handlers.js
index 0bec084..7c13421 100644
--- a/web/nms-public.gathering.org/js/nms-map-handlers.js
+++ b/web/nms-public.gathering.org/js/nms-map-handlers.js
@@ -67,6 +67,12 @@ var handler_comment = {
name:"Fresh comment spotter"
};
+var handler_snmp = {
+ init:snmpInit,
+ tag:"snmp",
+ name:"SNMP state"
+};
+
var handlers = [
handler_uplinks,
handler_temp,
@@ -75,7 +81,8 @@ var handlers = [
handler_disco,
handler_comment,
handler_traffic_tot,
- handler_dhcp
+ handler_dhcp,
+ handler_snmp
];
/*
@@ -133,6 +140,8 @@ function uplinkInit()
*/
function trafficInit()
{
+ nmsData.addHandler("switches","mapHandler",trafficUpdater);
+ nmsData.addHandler("switchstate","mapHandler",trafficUpdater);
var m = 1024 * 1024 / 8;
drawGradient([lightgreen,green,orange,red]);
setLegend(1,colorFromSpeed(0),"0 (N/A)");
@@ -144,33 +153,28 @@ function trafficInit()
function trafficUpdater()
{
- if (!nms.switches_now["switches"])
+ if (!nmsData.switchstate.switches || !nmsData.switchstate.then)
return;
- for (var sw in nms.switches_now["switches"]) {
+ for (var sw in nmsData.switchstate.switches) {
var speed = 0;
- for (var port in nms.switches_now["switches"][sw]["ports"]) {
- if (/ge-0\/0\/44$/.exec(port) ||
- /ge-0\/0\/45$/.exec(port) ||
- /ge-0\/0\/46$/.exec(port) ||
- /ge-0\/0\/47$/.exec(port))
- {
- if (!nms.switches_then["switches"][sw] ||
- !nms.switches_then["switches"][sw]["ports"] ||
- !nms.switches_then["switches"][sw]["ports"][port])
- continue;
- var t = nms.switches_then["switches"][sw]["ports"][port];
- var n = nms.switches_now["switches"][sw]["ports"][port];
- speed += (parseInt(t["ifhcoutoctets"]) -parseInt(n["ifhcoutoctets"])) / (parseInt(t["time"] - n["time"]));
- speed += (parseInt(t["ifhcinoctets"]) -parseInt(n["ifhcinoctets"])) / (parseInt(t["time"] - n["time"]));
- }
- }
+ try {
+ var t = parseInt(nmsData.switchstate.then[sw].uplinks.ifHCOutOctets);
+ var n = parseInt(nmsData.switchstate.switches[sw].uplinks.ifHCOutOctets);
+ var tt = parseInt(nmsData.switchstate.then[sw].time);
+ var nt = parseInt(nmsData.switchstate.switches[sw].time);
+ } catch (e) { continue;};
+ var tdiff = nt - tt;
+ var diff = n - t;
+ speed = diff / tdiff;
if(!isNaN(speed))
- setSwitchColor(sw,colorFromSpeed(speed));
+ nmsMap.setSwitchColor(sw,colorFromSpeed(speed));
}
}
function trafficTotInit()
{
+ nmsData.addHandler("switches","mapHandler",trafficTotUpdater);
+ nmsData.addHandler("switchstate","mapHandler",trafficTotUpdater);
var m = 1024 * 1024 / 8;
drawGradient([lightgreen,green,orange,red]);
setLegend(1,colorFromSpeed(0),"0 (N/A)");
@@ -182,20 +186,21 @@ function trafficTotInit()
function trafficTotUpdater()
{
- if (!nms.switches_now["switches"])
+ if (!nmsData.switchstate.switches || !nmsData.switchstate.then)
return;
- for (var sw in nms.switches_now["switches"]) {
+ for (var sw in nmsData.switchstate.switches) {
var speed = 0;
- for (var port in nms.switches_now["switches"][sw]["ports"]) {
- if (!nms.switches_then["switches"][sw] ||
- !nms.switches_then["switches"][sw]["ports"] ||
- !nms.switches_then["switches"][sw]["ports"][port])
- continue;
- var t = nms.switches_then["switches"][sw]["ports"][port];
- var n = nms.switches_now["switches"][sw]["ports"][port];
- speed += (parseInt(t["ifhcoutoctets"]) -parseInt(n["ifhcoutoctets"])) / (parseInt(t["time"] - n["time"]));
- }
- setSwitchColor(sw,colorFromSpeed(speed,5));
+ try {
+ var t = parseInt(nmsData.switchstate.then[sw].totals.ifHCOutOctets);
+ var n = parseInt(nmsData.switchstate.switches[sw].totals.ifHCOutOctets);
+ var tt = parseInt(nmsData.switchstate.then[sw].time);
+ var nt = parseInt(nmsData.switchstate.switches[sw].time);
+ } catch (e) { continue;};
+ var tdiff = nt - tt;
+ var diff = n - t;
+ speed = diff / tdiff;
+ if(!isNaN(speed))
+ nmsMap.setSwitchColor(sw,colorFromSpeed(speed));
}
}
@@ -231,19 +236,15 @@ function tempUpdater()
var t = "white";
var temp = "";
- if(!nmsData.snmp || !nmsData.snmp.snmp || ! nmsData.snmp.snmp[sw] || !nmsData.snmp.snmp[sw]["misc"] || !nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"])
+ if(!nmsData.switchstate || !nmsData.switchstate.switches || !nmsData.switchstate.switches[sw] || !nmsData.switchstate.switches[sw].temp)
continue;
- var tempObj = nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"];
- Object.keys(tempObj).forEach(function (key) {
- if(key == "") {
- temp = tempObj[key] + "°C";
- t = temp_color(temp);
- }
- });
-
+ var t = nmsData.switchstate.switches[sw].temp;
+ temp = t + "°C";
+ t = temp_color(temp);
nmsMap.setSwitchColor(sw, t);
nmsMap.setSwitchInfo(sw, temp);
+
}
}
@@ -428,3 +429,24 @@ function discoInit()
setLegend(5,"white","!");
}
+function snmpUpdater() {
+ for (var sw in nmsData.switches.switches) {
+ if (nmsData.snmp.snmp[sw] == undefined || nmsData.snmp.snmp[sw].misc == undefined) {
+ nmsMap.setSwitchColor(sw, red);
+ } else if (nmsData.snmp.snmp[sw].misc.sysName[0] != sw) {
+ nmsMap.setSwitchColor(sw, orange);
+ } else {
+ nmsMap.setSwitchColor(sw, green);
+ }
+ }
+}
+function snmpInit() {
+ nmsData.addHandler("snmp", "mapHandler", snmpUpdater);
+
+ setLegend(1,green,"OK");
+ setLegend(2,orange, "Sysname mismatch");
+ setLegend(3,red,"No SNMP data");
+ setLegend(4,green, "");
+ setLegend(5,green,"");
+
+}
diff --git a/web/nms-public.gathering.org/js/nms-map.js b/web/nms-public.gathering.org/js/nms-map.js
index 648643c..ada6886 100644
--- a/web/nms-public.gathering.org/js/nms-map.js
+++ b/web/nms-public.gathering.org/js/nms-map.js
@@ -158,6 +158,7 @@ nmsMap._resizeEvent = function() {
nmsMap._blurDrawn = false;
nmsMap._drawBG();
nmsMap._drawAllSwitches();
+ nmsMap._drawAllLinknets();
nmsMap.drawNow();
nmsMap.stats.resizeEvents++;
}
@@ -274,6 +275,9 @@ nmsMap._drawSwitch = function(sw)
this._drawBox(this._c.switch.ctx, box['x'],box['y'],box['width'],box['height']);
this._c.switch.ctx.shadowBlur = 0;
this._drawText(this._c.text.ctx, sw,box);
+
+ if(this._info[sw])
+ this._drawSwitchInfo(sw);
};
nmsMap._drawSwitchInfo = function(sw) {
@@ -328,9 +332,38 @@ nmsMap._drawText = function(ctx, text, box, align) {
ctx.restore();
};
+nmsMap._setLinknetColor = function(l, color1, color2)
+{
+ var oldcolor1;
+ var oldcolor2;
+ try {
+ oldcolor1 = nmsMap._linknets[l].sysname1;
+ oldcolor2 = nmsMap._linknets[l].sysname2;
+ if (oldcolor1 == color1 && oldcolor2 == color2) {
+ return ;
+ }
+ } catch (e) {}
+ nmsMap._linknets[l] = {};
+ nmsMap._linknets[l].sysname1 = color1;
+ nmsMap._linknets[l].sysname2 = color2;
+ nmsMap._drawLinknet(l)
+}
+
+nmsMap._drawLinknet = function(l) {
+ try {
+ var color1 = blue;
+ var color2 = blue;
+ try {
+ color1 = nmsMap._linknets[l].sysname1;
+ color2 = nmsMap._linknets[l].sysname2;
+ } catch(e) { }
+ nmsMap._connectSwitches(nmsData.switches.linknets[l].sysname1, nmsData.switches.linknets[l].sysname2, color1, color2);
+ } catch(e) { }
+}
+
nmsMap._drawAllLinknets = function() {
for (var l in nmsData.switches.linknets) {
- nmsMap._connectSwitches(nmsData.switches.linknets[l].switch1, nmsData.switches.linknets[l].switch2);
+ nmsMap._drawLinknet(l);
}
}
nmsMap._drawAllSwitches = function() {
@@ -389,10 +422,12 @@ nmsMap._connectBoxes = function(box1, box2,color1, color2) {
gradient.addColorStop(0, color1);
gradient.addColorStop(1, color2);
ctx.strokeStyle = gradient;
+ ctx.beginPath();
ctx.moveTo(x0,y0);
ctx.lineTo(x1,y1);
ctx.lineWidth = 5;
ctx.stroke();
+ ctx.closePath();
ctx.restore();
};
@@ -416,6 +451,8 @@ nmsMap.canvasClick = function(e)
} else {
nmsInfoBox.click(sw);
}
+ } else {
+ nmsInfoBox.hide();
}
};
diff --git a/web/nms-public.gathering.org/js/nms.js b/web/nms-public.gathering.org/js/nms.js
index f145177..c09fca0 100644
--- a/web/nms-public.gathering.org/js/nms.js
+++ b/web/nms-public.gathering.org/js/nms.js
@@ -38,6 +38,9 @@ var nms = {
'5':setMapModeFromN,
'6':setMapModeFromN,
'7':setMapModeFromN,
+ '8':setMapModeFromN,
+ '9':setMapModeFromN,
+ 'c':toggleConnect,
'h':moveTimeFromKey,
'j':moveTimeFromKey,
'k':moveTimeFromKey,
@@ -345,6 +348,10 @@ function toggleLayer(layer) {
l.style.display = 'none';
}
+function toggleConnect() {
+ toggleLayer("linkCanvas");
+}
+
function commentInactive(id)
{
commentChange(id,"inactive");
@@ -534,6 +541,9 @@ function setMapModeFromN(e,key)
case '7':
setUpdater(handler_traffic_tot);
break;
+ case '8':
+ setUpdater(handler_snmp);
+ break;
case '9':
setUpdater(handler_disco);
break;