var SkyScanner = (function(){ var tzOffset = new Date().getTimezoneOffset() * 60; var defaultOptions = { }; var initializers = []; class SkyScanner { constructor(options){ this.options = {} Object.assign(this.options, defaultOptions); Object.assign(this.options, options); var self = this; this.lagDetector = null; this.currentTimeout = null; this.serverTime = "N/A"; this.serverString = "N/A"; this.lastIssueUpdate = "N/A"; this.currentIssues = []; this.currentNodes = []; this.issues = { OK: 0, WARN: 0, CRITICAL: 0, }; LN().option("wsError",(e)=>self.wsError(e)); LN().option("wsClose",(e)=>self.wsClose(e)); LN().option("wsUpdate",(e)=>self.wsUpdate(e)); LN().connect(); LN().rpc(null,"GetServerString",[],function(r,e){ self.serverString = r; }); } static getInitializers(){ return initializers; } wsUpdate(state) { try { if (this.lagDetector) clearTimeout(this.lagDetector); this.serverTime = moment(state.currentTime).format(); this.lagDetector = setTimeout(function(){ this.serverTime = "Server lag detected"; }, 2000); } catch (e) { console.log(e); } } wsError(e){ this.serverTime = "WebSocket: Error: " + JSON.stringify(e); } wsClose(e){ this.serverTime = "WebSocket: Connection lost"; setTimeout(function(){ LN().connect(); }, 2500 ); } updateIssues(){ var self = this; console.log("Update issue list"); LN().rpc("CheckService","GetIssueList",[],function(r,e){ if (e){ alert("Error fetching current issue list!\n" + JSON.stringify(e)); } else { self.currentIssues = r; self.issues = { OK: 0, WARN: 0, CRITICAL: 0, }; for (var n=0;n 0 ? moment.unix(this.History.slice(-1)[0].Timestamp) : moment(); var m2 = this.History.length > 1 ? moment.unix(this.History.slice(-2)[0].Timestamp) : moment(); this.currentStateTime = (now - m1)/1000; if (STATES.indexOf(currentNode.checkState) < STATES.indexOf(this.CheckState)) { currentNode.checkState = this.CheckState; currentNode.highestStateTime = 0; } if (currentNode.highestStateTime < this.currentStateTime) currentNode.highestStateTime = this.currentStateTime; this.previousCheckState = this.History.length > 1 ? " ( " + this.History.slice(-2)[0].NewState + "=" + timespan((m1 - m2)/1000) + " )" : ""; m1 = now; $.each(this.History.reverse(), function(){ m2 = moment.unix(this.Timestamp); this.duration = (m1 - m2)/1000; m1 = m2; }); }); } updateNodes(){ var self = this; console.log("Update node list"); LN().rpc("entities","GetNodes",[],function(r,e){ if (e){ alert("Error fetching current node list!\n" + JSON.stringify(e)); } else { self.currentNodes = r; } }); } loadNode(nodeID,cb,refreshIntervall){ var self = this; LN().rpc("entities","GetNode",[nodeID,],function(r,e){ if (refreshIntervall && self.currentTimeout) clearTimeout(self.currentTimeout); skyscanner.upgradeNode(r); cb(r); if (refreshIntervall) setTimeout(()=>{ self.loadNode(nodeID,cb,refreshIntervall); }, refreshIntervall); }); } encodeID( t ) { return ("" + t).replace( /[\.\/]/g, "_"); } loadPerformanceGraph(perfPath,interval,cb){ LN().rpc("perfValues","GetPerfData",[perfPath,interval],(perfData,e)=>{ if (e){ console.log(e); } else { cb(perfData); } }); } getCheckStateTime(checkState){ var history = [] var now = moment.unix((Date.now()/1000) - tzOffset); var m1 = checkState.History.length > 0 ? moment.unix(checkState.History.slice(-1)[0].Timestamp) : moment(); var m2 = checkState.History.length > 1 ? moment.unix(checkState.History.slice(-2)[0].Timestamp) : moment(); var currentStateTime = (now - m1)/1000; timespan(currentStateTime) + (this.History.length > 1 ? " ( " + this.History.slice(-2)[0].NewState + "=" + timespan((m1 - m2)/1000) + " )" : "") } static scaleSI(value) { if (!value) return null; if (value > 1000000000) return ((value / 1000000000) | 0) + "G"; if (value > 1000000) return ((value / 1000000) | 0) + "M"; if (value > 1000) return ((value / 1000) | 0) + "k"; return value; } } return SkyScanner; })() var skyScannerRoutes = []