]> arthur.barton.de Git - netdata.git/commitdiff
added the page needed for alarm links
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 9 Sep 2016 23:59:28 +0000 (02:59 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 9 Sep 2016 23:59:28 +0000 (02:59 +0300)
web/Makefile.am
web/goto-host-from-alarm.html [new file with mode: 0755]

index 3c8d19d90128f37b5b201b89dab76bfc7941490e..fc14269f8f4c1ead407f60d6e5d5267c23632c77 100644 (file)
@@ -12,6 +12,7 @@ dist_web_DATA = \
        dashboard.css \
        dashboard.slate.css \
        favicon.ico \
+       goto-host-from-alarm.html \
        index.html \
        netdata-swagger.yaml \
        netdata-swagger.json \
diff --git a/web/goto-host-from-alarm.html b/web/goto-host-from-alarm.html
new file mode 100755 (executable)
index 0000000..deab6b8
--- /dev/null
@@ -0,0 +1,143 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <title>Goto a host you know...</title>
+    <meta name="application-name" content="netdata">
+
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <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;</script>
+    <script type="text/javascript" src="dashboard.js?v46"></script>
+
+    <script>
+    var urlOptions = {
+        host: null,
+        chart: null,
+        family: null,
+        hasProperty: function(property) {
+            // console.log('checking property ' + property + ' of type ' + typeof(this[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]] = p[1];
+        }
+
+        console.log(urlOptions);
+    }
+
+    function netdataURL(url) {
+        return url + '#' + urlOptions.family;
+    }
+
+    var gotoServerValidateRemaining = 0;
+    var gotoServerMiddleClick = false;
+    var gotoServerStop = false;
+    function gotoServerValidateUrl(id, guid, url) {
+        console.log(id);
+        console.log(guid);
+        console.log(url);
+
+        var penaldy = 0;
+        if(document.location.toString().startsWith('http://') && 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;
+
+        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>';
+
+            NETDATA.registry.hello(url, function(data) {
+                if (data) {
+                    // console.log('OK ' + id + ' URL: ' + url);
+                    document.getElementById(guid + '-' + id + '-status').innerHTML = "OK";
+
+                    if(!gotoServerStop) {
+                        gotoServerStop = true;
+
+                        if(gotoServerMiddleClick) {
+                            window.open(finalURL, '_blank');
+                            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 = "failed!";
+                    gotoServerValidateRemaining--;
+                    if(gotoServerValidateRemaining <= 0) {
+                        gotoServerMiddleClick = false;
+                        document.getElementById('gotoServerResponse').innerHTML = '<b>Sorry! I cannot find any operational URL for this server</b>';
+                    }
+                }
+            });
+        }, (id * 50) + penaldy);
+    }
+
+    var netdataRegistryCallback = function(machines_array) {
+        if(machines_array) {
+            var len = machines_array.length;
+            while(len--) {
+                if(machines_array[len].name === urlOptions.host) {
+                    console.log(machines_array[len]);
+
+                    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();
+
+    if(typeof urlOptions.host !== 'string')
+        document.getElementById('bodylog').innerHTML = "Sorry... bad request.";
+
+    if(typeof urlOptions.family !== 'string')
+        urlOptions.family = '';
+
+    if(typeof urlOptions.chart !== 'string')
+        urlOptions.chart = '';
+    </script>
+
+</head>
+<body>
+<div class="container" id="">
+    <div id="bodylog" style="padding-top: 40px; font-size: 18px;">
+        Please wait...
+
+        <div style="padding-top: 20px;">
+            <table id="gotoServerList">
+            </table>
+        </div>
+        <p style="padding-top: 10px;"><small>
+            This page can only find netdata URLs you have already visited and are active for your account on this registry.
+        </small></p>
+        <div id="gotoServerResponse" style="display: block; width: 100%; text-align: center; padding-top: 20px;"></div>
+    </div>
+
+</div>
+</body>
+</html>