webapp.scripts.modules.logs-navigation.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of willow-servers Show documentation
Show all versions of willow-servers Show documentation
Willow operational servlets and servers
The newest version!
Box.Application.addModule('logs-navigation', function(context) {
'use strict';
var socket, seen = [], d3, timeFormatter;
var pollAlerts = function() {
var pollConf = {};
pollConf.stop = new Date().getTime();
pollConf.start = pollConf.stop - (1000 * 60 * 60 * 12);
pollConf.step = 10000;
pollConf.minSteps = 30;
pollConf.metricKey = "/log";
var conf = JSON.stringify(pollConf);
socket.send(conf);
};
var onEvents = function(event) {
var willowEvents = JSON.parse(event.data);
var i;
for (i=0; i" + timeFormatter(new Date(willowEvents.data[i].timestamp)) + " " +
"" + willowEvents.data[i].logger + " " +
"" + willowEvents.data[i].level + " " +
"" + willowEvents.data[i].message + " ");
}
}
};
var seenEvent = function(id) {
if (seen.indexOf(id) > -1) {
return true;
} else {
seen.push(id);
return false;
}
};
return {
init: function() {
d3 = context.getGlobal("d3");
timeFormatter = d3.time.format("%Y-%m-%d %X");
var loc = window.location, ws_uri;
if (loc.protocol === "https:") {
ws_uri = "wss:";
} else {
ws_uri = "ws:";
}
var ctx = "/";
var ctxEnd = loc.pathname.lastIndexOf("/");
if (ctxEnd > 0) {
if (loc.pathname.indexOf("/") === 0) {
ctx = "";
}
ctx += loc.pathname.substring(0, contextEnd) + "/";
}
ws_uri += "//" + loc.host + ctx + "poll/";
socket = new WebSocket(ws_uri);
socket.onopen = pollAlerts;
socket.onmessage = onEvents;
}
};
});