diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-09-24 17:34:24 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-09-24 17:34:24 +0300 |
commit | 43cec16e60a8cadaffc0aca4bb08455cbf143b22 (patch) | |
tree | 9a5ad2761832ec1dfe8087816b4f026abdbba7c9 /web/goto-host-from-alarm.html | |
parent | 6a8dcea7d0df301104c10efa8e4db9dad5a7633b (diff) |
optimizatons suggested by sitespeed.io
Diffstat (limited to 'web/goto-host-from-alarm.html')
-rwxr-xr-x | web/goto-host-from-alarm.html | 239 |
1 files changed, 119 insertions, 120 deletions
diff --git a/web/goto-host-from-alarm.html b/web/goto-host-from-alarm.html index ff7a00ffd3..e3f4391f8b 100755 --- a/web/goto-host-from-alarm.html +++ b/web/goto-host-from-alarm.html @@ -11,147 +11,146 @@ <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> - <script> - var netdataRegistry = true; - var netdataRegistryAfterMs = 0; - var netdataTheme = 'slate'; - var netdataShowHelp = true; - </script> - <script type="text/javascript" src="dashboard.js?v51"></script> - - <script> - var urlOptions = { - host: null, - chart: null, - family: null, - alarm: null, - alarm_unique_id: 0, - alarm_id: 0, - alarm_event_id: 0, - hasProperty: function(property) { - return typeof this[property] !== 'undefined'; - } - }; - - function netdataQueryParse() { - var query = document.location.search.split('?'); - var variables = query[1].split('&'); - var len = variables.length; - while(len--) { - var p = variables[len].split('='); - if(urlOptions.hasProperty(p[0]) && typeof p[1] !== 'undefined') - urlOptions[p[0]] = decodeURIComponent(p[1]); - } - - if(typeof urlOptions.family !== 'string') - urlOptions.family = ''; - - if(typeof urlOptions.chart !== 'string') - urlOptions.chart = ''; +</head> +<script> + var netdataRegistry = true; + var netdataRegistryAfterMs = 0; + var netdataTheme = 'slate'; + var netdataShowHelp = true; +</script> +<script type="text/javascript" src="dashboard.js?v51"></script> + +<script> +var urlOptions = { + host: null, + chart: null, + family: null, + alarm: null, + alarm_unique_id: 0, + alarm_id: 0, + alarm_event_id: 0, + hasProperty: function(property) { + return typeof this[property] !== 'undefined'; } - - function netdataURL(url) { - return url + '#top' - + ';nowelcome=1' - // + ';show_alarms=1' - + ';chart=' + encodeURIComponent(urlOptions.chart) - + ';family=' + encodeURIComponent(urlOptions.family) - + ';alarm=' + encodeURIComponent(urlOptions.alarm) - + ';alarm_unique_id=' + urlOptions.alarm_unique_id.toString() - + ';alarm_id=' + urlOptions.alarm_id.toString() - + ';alarm_event_id=' + urlOptions.alarm_event_id.toString() - ; +}; + +function netdataQueryParse() { + var query = document.location.search.split('?'); + var variables = query[1].split('&'); + var len = variables.length; + while(len--) { + var p = variables[len].split('='); + if(urlOptions.hasProperty(p[0]) && typeof p[1] !== 'undefined') + urlOptions[p[0]] = decodeURIComponent(p[1]); } - var gotoServerValidateRemaining = 0; - var gotoServerMiddleClick = false; - var gotoServerStop = false; - var thisIsHttps = false; - var urlsInHttp = 0; - function gotoServerValidateUrl(id, guid, url) { - var penaldy = 0; - var error = 'failed'; - - if(thisIsHttps === false && url.toString().startsWith('https://')) { - // we penalize https only if the current url is http - // to allow the user walk through all its servers. - penaldy = 500; - } + if(typeof urlOptions.family !== 'string') + urlOptions.family = ''; + + if(typeof urlOptions.chart !== 'string') + urlOptions.chart = ''; +} + +function netdataURL(url) { + return url + '#top' + + ';nowelcome=1' + // + ';show_alarms=1' + + ';chart=' + encodeURIComponent(urlOptions.chart) + + ';family=' + encodeURIComponent(urlOptions.family) + + ';alarm=' + encodeURIComponent(urlOptions.alarm) + + ';alarm_unique_id=' + urlOptions.alarm_unique_id.toString() + + ';alarm_id=' + urlOptions.alarm_id.toString() + + ';alarm_event_id=' + urlOptions.alarm_event_id.toString() + ; +} + +var gotoServerValidateRemaining = 0; +var gotoServerMiddleClick = false; +var gotoServerStop = false; +var thisIsHttps = false; +var urlsInHttp = 0; +function gotoServerValidateUrl(id, guid, url) { + var penaldy = 0; + var error = 'failed'; + + if(thisIsHttps === false && url.toString().startsWith('https://')) { + // we penalize https only if the current url is http + // to allow the user walk through all its servers. + penaldy = 500; + } - else if(thisIsHttps === true && url.toString().startsWith('http://')) { - error = 'can\'t check'; - urlsInHttp++; - } + else if(thisIsHttps === true && url.toString().startsWith('http://')) { + error = 'can\'t check'; + urlsInHttp++; + } - var finalURL = netdataURL(url); + var finalURL = netdataURL(url); - setTimeout(function() { - document.getElementById('gotoServerList').innerHTML += '<tr><td style="padding-left: 20px;"><a href="' + finalURL + '" target="_blank">' + url + '</a></td><td style="padding-left: 30px;"><code id="' + guid + '-' + id + '-status">checking...</code></td></tr>'; + setTimeout(function() { + document.getElementById('gotoServerList').innerHTML += '<tr><td style="padding-left: 20px;"><a href="' + finalURL + '" target="_blank">' + url + '</a></td><td style="padding-left: 30px;"><code id="' + guid + '-' + id + '-status">checking...</code></td></tr>'; - NETDATA.registry.hello(url, function(data) { - if (data) { - document.getElementById(guid + '-' + id + '-status').innerHTML = "OK"; + NETDATA.registry.hello(url, function(data) { + if (data) { + document.getElementById(guid + '-' + id + '-status').innerHTML = "OK"; - if(!gotoServerStop) { - gotoServerStop = true; + if(!gotoServerStop) { + gotoServerStop = true; - if(gotoServerMiddleClick) { - window.open(finalURL); - gotoServerMiddleClick = false; - document.getElementById('gotoServerResponse').innerHTML = '<b>Opening new window to ' + NETDATA.registry.machines[guid].name + '<br/><a href="' + finalURL + '">' + url + '</a></b><br/>(check your pop-up blocker if it fails)'; - } - else - document.location = finalURL; + if(gotoServerMiddleClick) { + window.open(finalURL); + gotoServerMiddleClick = false; + document.getElementById('gotoServerResponse').innerHTML = '<b>Opening new window to ' + NETDATA.registry.machines[guid].name + '<br/><a href="' + finalURL + '">' + url + '</a></b><br/>(check your pop-up blocker if it fails)'; } + else + document.location = finalURL; } - else { - document.getElementById(guid + '-' + id + '-status').innerHTML = error; - gotoServerValidateRemaining--; - if(gotoServerValidateRemaining <= 0) { - gotoServerMiddleClick = false; - document.getElementById('gotoServerResponse').innerHTML = '<b>Sorry! I cannot find any operational URL for this server</b>'; - - if(thisIsHttps === true && urlsInHttp > 0) { - document.getElementById('gotoServerResponse').innerHTML += '<br/>redirecting myself to HTTP to allow checking'; - document.location = document.location.toString().replace('https://', 'http://'); - } + } + else { + document.getElementById(guid + '-' + id + '-status').innerHTML = error; + gotoServerValidateRemaining--; + if(gotoServerValidateRemaining <= 0) { + gotoServerMiddleClick = false; + document.getElementById('gotoServerResponse').innerHTML = '<b>Sorry! I cannot find any operational URL for this server</b>'; + + if(thisIsHttps === true && urlsInHttp > 0) { + document.getElementById('gotoServerResponse').innerHTML += '<br/>redirecting myself to HTTP to allow checking'; + document.location = document.location.toString().replace('https://', 'http://'); } } - }); - }, (id * 50) + penaldy); + } + }); + }, (id * 50) + penaldy); +} + +var netdataRegistryCallback = function(machines_array) { + if(typeof urlOptions.host !== 'string') { + document.getElementById('bodylog').innerHTML = "Sorry... bad request."; + return; } - var netdataRegistryCallback = function(machines_array) { - if(typeof urlOptions.host !== 'string') { - document.getElementById('bodylog').innerHTML = "Sorry... bad request."; - return; - } - - document.getElementById('message').innerHTML = 'These are the URLs this machine is known:'; + document.getElementById('message').innerHTML = 'These are the URLs this machine is known:'; - if(document.location.toString().startsWith('https://')) - thisIsHttps = true; + if(document.location.toString().startsWith('https://')) + thisIsHttps = true; - if(machines_array) { - var len = machines_array.length; - while(len--) { - if(machines_array[len].name === urlOptions.host) { - var ulen = machines_array[len].alternate_urls.length; - gotoServerValidateRemaining = ulen; - while(ulen--) - gotoServerValidateUrl(ulen, machines_array[len].guid, machines_array[len].alternate_urls[ulen]); - return; - } + if(machines_array) { + var len = machines_array.length; + while(len--) { + if(machines_array[len].name === urlOptions.host) { + var ulen = machines_array[len].alternate_urls.length; + gotoServerValidateRemaining = ulen; + while(ulen--) + gotoServerValidateUrl(ulen, machines_array[len].guid, machines_array[len].alternate_urls[ulen]); + return; } } + } - document.getElementById('bodylog').innerHTML = "Sorry... your account is not linked to a netdata server named: <b>" + urlOptions.host + '</b>'; - }; - - netdataQueryParse(); - </script> + document.getElementById('bodylog').innerHTML = "Sorry... your account is not linked to a netdata server named: <b>" + urlOptions.host + '</b>'; +}; -</head> +netdataQueryParse(); +</script> <body> <div class="container" id=""> <div id="bodylog" style="padding-top: 8vmax; font-size: 2.0vmax;"> |