Skip to content

Commit f806fc9

Browse files
committed
goto-host-from-alarm now searches all known URLs for a host
1 parent 88e83f6 commit f806fc9

2 files changed

Lines changed: 53 additions & 13 deletions

File tree

web/goto-host-from-alarm.html

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@
7373
var penaldy = 0;
7474
var error = 'failed';
7575

76-
if(thisIsHttps === false && url.toString().startsWith('https://')) {
76+
if(thisIsHttps === false && url.toString().startsWith('https://'))
7777
// we penalize https only if the current url is http
7878
// to allow the user walk through all its servers.
7979
penaldy = 500;
80-
}
8180

8281
else if(thisIsHttps === true && url.toString().startsWith('http://')) {
8382
error = 'can\'t check';
@@ -90,7 +89,8 @@
9089
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>';
9190

9291
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);
9494
document.getElementById(guid + '-' + id + '-status').innerHTML = "OK";
9595

9696
if(!gotoServerStop) {
@@ -101,11 +101,16 @@
101101
gotoServerMiddleClick = false;
102102
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)';
103103
}
104-
else
104+
else {
105+
document.getElementById('gotoServerResponse').innerHTML += 'found it! It is at:<br/><small>' + url + '</small>';
105106
document.location = finalURL;
107+
}
106108
}
107109
}
108110
else {
111+
if(typeof data !== 'undefined' && data !== null && typeof data.machine_guid === 'string' && data.machine_guid !== guid)
112+
error = 'wrong machine';
113+
109114
document.getElementById(guid + '-' + id + '-status').innerHTML = error;
110115
gotoServerValidateRemaining--;
111116
if(gotoServerValidateRemaining <= 0) {
@@ -134,14 +139,47 @@
134139
thisIsHttps = true;
135140

136141
if(machines_array) {
142+
var guids = {};
143+
var checked = {};
137144
var len = machines_array.length;
145+
var count = 0;
146+
138147
while(len--) {
139148
if(machines_array[len].name === urlOptions.host) {
140149
var ulen = machines_array[len].alternate_urls.length;
150+
var guid = machines_array[len].guid;
151+
guids[guid] = true;
152+
141153
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;
145183
}
146184
}
147185
}

web/index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,9 @@
683683
var error = 'failed';
684684

685685
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;
689689

690690
else if(document.location.toString().startsWith('https://') && url.toString().startsWith('http://'))
691691
error = 'can\'t check';
@@ -708,8 +708,10 @@
708708
gotoServerMiddleClick = false;
709709
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)';
710710
}
711-
else
711+
else {
712+
document.getElementById('gotoServerResponse').innerHTML += 'found it! It is at:<br/><small>' + url + '</small>';
712713
document.location = finalURL;
714+
}
713715
}
714716
}
715717
else {
@@ -751,11 +753,11 @@
751753
if(gotoServerStop === false) {
752754
document.getElementById('gotoServerResponse').innerHTML = '<b>Added all the known URLs for this machine.</b>';
753755
NETDATA.registry.search(guid, function(data) {
754-
console.log(data);
756+
// console.log(data);
755757
len = data.urls.length;
756758
while(len--) {
757759
var url = data.urls[len][1];
758-
console.log(url);
760+
// console.log(url);
759761
if(typeof checked[url] === 'undefined') {
760762
gotoServerValidateRemaining++;
761763
checked[url] = true;

0 commit comments

Comments
 (0)