@cryptotaxi247 / netdata-1 / commits / fdd64e430

added the page needed for alarm links

Costa Tsaousis (ktsaou) committed Sep 10, 2016 at 02:59 UTC fdd64e430308121d830b05fa76dff597cde78c3e
2 files changed +144
web/Makefile.am
+1
@@ -12,6 +12,7 @@ dist_web_DATA = \
12 dashboard.css \
13 dashboard.slate.css \
14 favicon.ico \
15 + goto-host-from-alarm.html \
16 index.html \
17 netdata-swagger.yaml \
18 netdata-swagger.json \
web/goto-host-from-alarm.html new
+143
@@ -0,0 +1,143 @@
1 +<!DOCTYPE html>
2 +<html lang="en">
3 +<head>
4 + <title>Goto a host you know...</title>
5 + <meta name="application-name" content="netdata">
6 +
7 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8 + <meta charset="utf-8">
9 + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
10 + <meta name="viewport" content="width=device-width, initial-scale=1">
11 + <meta name="apple-mobile-web-app-capable" content="yes">
12 + <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
13 +
14 + <script>var netdataRegistry = true;</script>
15 + <script type="text/javascript" src="dashboard.js?v46"></script>
16 +
17 + <script>
18 + var urlOptions = {
19 + host: null,
20 + chart: null,
21 + family: null,
22 + hasProperty: function(property) {
23 + // console.log('checking property ' + property + ' of type ' + typeof(this[property]));
24 + return typeof this[property] !== 'undefined';
25 + }
26 + };
27 +
28 + function netdataQueryParse() {
29 + var query = document.location.search.split('?');
30 + var variables = query[1].split('&');
31 + var len = variables.length;
32 + while(len--) {
33 + var p = variables[len].split('=');
34 + if(urlOptions.hasProperty(p[0]) && typeof p[1] !== 'undefined')
35 + urlOptions[p[0]] = p[1];
36 + }
37 +
38 + console.log(urlOptions);
39 + }
40 +
41 + function netdataURL(url) {
42 + return url + '#' + urlOptions.family;
43 + }
44 +
45 + var gotoServerValidateRemaining = 0;
46 + var gotoServerMiddleClick = false;
47 + var gotoServerStop = false;
48 + function gotoServerValidateUrl(id, guid, url) {
49 + console.log(id);
50 + console.log(guid);
51 + console.log(url);
52 +
53 + var penaldy = 0;
54 + if(document.location.toString().startsWith('http://') && url.toString().startsWith('https://'))
55 + // we penalize https only if the current url is http
56 + // to allow the user walk through all its servers.
57 + penaldy = 500;
58 +
59 + var finalURL = netdataURL(url);
60 +
61 + setTimeout(function() {
62 + 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>';
63 +
64 + NETDATA.registry.hello(url, function(data) {
65 + if (data) {
66 + // console.log('OK ' + id + ' URL: ' + url);
67 + document.getElementById(guid + '-' + id + '-status').innerHTML = "OK";
68 +
69 + if(!gotoServerStop) {
70 + gotoServerStop = true;
71 +
72 + if(gotoServerMiddleClick) {
73 + window.open(finalURL, '_blank');
74 + gotoServerMiddleClick = false;
75 + 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)';
76 + }
77 + else
78 + document.location = finalURL;
79 + }
80 + }
81 + else {
82 + document.getElementById(guid + '-' + id + '-status').innerHTML = "failed!";
83 + gotoServerValidateRemaining--;
84 + if(gotoServerValidateRemaining <= 0) {
85 + gotoServerMiddleClick = false;
86 + document.getElementById('gotoServerResponse').innerHTML = '<b>Sorry! I cannot find any operational URL for this server</b>';
87 + }
88 + }
89 + });
90 + }, (id * 50) + penaldy);
91 + }
92 +
93 + var netdataRegistryCallback = function(machines_array) {
94 + if(machines_array) {
95 + var len = machines_array.length;
96 + while(len--) {
97 + if(machines_array[len].name === urlOptions.host) {
98 + console.log(machines_array[len]);
99 +
100 + var ulen = machines_array[len].alternate_urls.length;
101 + gotoServerValidateRemaining = ulen;
102 + while(ulen--)
103 + gotoServerValidateUrl(ulen, machines_array[len].guid, machines_array[len].alternate_urls[ulen]);
104 +
105 + return;
106 + }
107 + }
108 + }
109 +
110 + document.getElementById('bodylog').innerHTML = "Sorry... your account is not linked to a netdata server named: <b>" + urlOptions.host + '</b>';
111 + };
112 +
113 + netdataQueryParse();
114 +
115 + if(typeof urlOptions.host !== 'string')
116 + document.getElementById('bodylog').innerHTML = "Sorry... bad request.";
117 +
118 + if(typeof urlOptions.family !== 'string')
119 + urlOptions.family = '';
120 +
121 + if(typeof urlOptions.chart !== 'string')
122 + urlOptions.chart = '';
123 + </script>
124 +
125 +</head>
126 +<body>
127 +<div class="container" id="">
128 + <div id="bodylog" style="padding-top: 40px; font-size: 18px;">
129 + Please wait...
130 +
131 + <div style="padding-top: 20px;">
132 + <table id="gotoServerList">
133 + </table>
134 + </div>
135 + <p style="padding-top: 10px;"><small>
136 + This page can only find netdata URLs you have already visited and are active for your account on this registry.
137 + </small></p>
138 + <div id="gotoServerResponse" style="display: block; width: 100%; text-align: center; padding-top: 20px;"></div>
139 + </div>
140 +
141 +</div>
142 +</body>
143 +</html>