goto-host-from-alarm now searches all known URLs for a host
Costa Tsaousis (ktsaou) committed
Oct 2, 2016 at 18:18 UTC
f806fc909ff5c2d98438529c1b3da5c64155b88d
2 files changed
+53
-13
web/goto-host-from-alarm.html
+45
-7
@@ -73,11 +73,10 @@ function gotoServerValidateUrl(id, guid, url) {
73
var penaldy = 0;
74
var error = 'failed';
75
76
- if(thisIsHttps === false && url.toString().startsWith('https://')) {
76
+ if(thisIsHttps === false && url.toString().startsWith('https://'))
77
// we penalize https only if the current url is http
78
// to allow the user walk through all its servers.
79
penaldy = 500;
80
- }
80
81
else if(thisIsHttps === true && url.toString().startsWith('http://')) {
82
error = 'can\'t check';
@@ -90,7 +89,8 @@ function gotoServerValidateUrl(id, guid, url) {
89
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>';
90
91
NETDATA.registry.hello(url, function(data) {
93
- if (data) {
92
+ if(typeof data !== 'undefined' && data !== null && typeof data.machine_guid === 'string' && data.machine_guid === guid) {
93
+ // console.log('OK ' + id + ' URL: ' + url);
94
document.getElementById(guid + '-' + id + '-status').innerHTML = "OK";
95
96
if(!gotoServerStop) {
@@ -101,11 +101,16 @@ function gotoServerValidateUrl(id, guid, url) {
101
gotoServerMiddleClick = false;
102
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)';
103
}
104
- else
104
+ else {
105
+ document.getElementById('gotoServerResponse').innerHTML += 'found it! It is at:<br/><small>' + url + '</small>';
106
document.location = finalURL;
107
+ }
108
}
109
}
110
else {
111
+ if(typeof data !== 'undefined' && data !== null && typeof data.machine_guid === 'string' && data.machine_guid !== guid)
112
+ error = 'wrong machine';
113
+
114
document.getElementById(guid + '-' + id + '-status').innerHTML = error;
115
gotoServerValidateRemaining--;
116
if(gotoServerValidateRemaining <= 0) {
@@ -134,14 +139,47 @@ var netdataRegistryCallback = function(machines_array) {
139
thisIsHttps = true;
140
141
if(machines_array) {
142
+ var guids = {};
143
+ var checked = {};
144
var len = machines_array.length;
145
+ var count = 0;
146
+
147
while(len--) {
148
if(machines_array[len].name === urlOptions.host) {
149
var ulen = machines_array[len].alternate_urls.length;
150
+ var guid = machines_array[len].guid;
151
+ guids[guid] = true;
152
+
153
gotoServerValidateRemaining = ulen;
142
- while(ulen--)
143
- gotoServerValidateUrl(ulen, machines_array[len].guid, machines_array[len].alternate_urls[ulen]);
144
- return;
154
+ while(ulen--) {
155
+ var url = machines_array[len].alternate_urls[ulen];
156
+ checked[url] = true;
157
+ gotoServerValidateUrl(count++, guid, url);
158
+ }
159
+
160
+ setTimeout(function() {
161
+ if(gotoServerStop === false) {
162
+ document.getElementById('gotoServerResponse').innerHTML = '<b>Added all the known URLs for this machine.</b>';
163
+ var guid;
164
+ for(guid in guids) {
165
+ NETDATA.registry.search(guid, function(data) {
166
+ // console.log(data);
167
+ len = data.urls.length;
168
+ while(len--) {
169
+ var url = data.urls[len][1];
170
+ // console.log(url);
171
+ if(typeof checked[url] === 'undefined') {
172
+ gotoServerValidateRemaining++;
173
+ checked[url] = true;
174
+ gotoServerValidateUrl(count++, guid, url);
175
+ }
176
+ }
177
+ });
178
+ }
179
+ }
180
+ }, 2000);
181
+
182
+ return false;
183
}
184
}
185
}
web/index.html
+8
-6
@@ -683,9 +683,9 @@
683
var error = 'failed';
684
685
if(document.location.toString().startsWith('http://') && url.toString().startsWith('https://'))
686
- // we penalize https only if the current url is http
687
- // to allow the user walk through all its servers.
688
- penaldy = 500;
686
+ // we penalize https only if the current url is http
687
+ // to allow the user walk through all its servers.
688
+ penaldy = 500;
689
690
else if(document.location.toString().startsWith('https://') && url.toString().startsWith('http://'))
691
error = 'can\'t check';
@@ -708,8 +708,10 @@
708
gotoServerMiddleClick = false;
709
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)';
710
}
711
- else
711
+ else {
712
+ document.getElementById('gotoServerResponse').innerHTML += 'found it! It is at:<br/><small>' + url + '</small>';
713
document.location = finalURL;
714
+ }
715
}
716
}
717
else {
@@ -751,11 +753,11 @@
753
if(gotoServerStop === false) {
754
document.getElementById('gotoServerResponse').innerHTML = '<b>Added all the known URLs for this machine.</b>';
755
NETDATA.registry.search(guid, function(data) {
754
- console.log(data);
756
+ // console.log(data);
757
len = data.urls.length;
758
while(len--) {
759
var url = data.urls[len][1];
758
- console.log(url);
760
+ // console.log(url);
761
if(typeof checked[url] === 'undefined') {
762
gotoServerValidateRemaining++;
763
checked[url] = true;