registry-alert-redirect.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <!doctype html><html><head><title>Netdata Agent Alert Redirect</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,height=device-height,initial-scale=1,minimum-scale=1"/><meta name="apple-mobile-web-app-capable" content="yes"/><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/><script>function loadStyle(url, { media, insertAfter: aref, insertBefore: bref, rel, type } = {}) {
  2. rel = rel || 'stylesheet'
  3. type = type || 'text/css'
  4. return new Promise(function(resolve, reject) {
  5. let link = document.createElement('link');
  6. link.type = type;
  7. link.rel = rel;
  8. link.href = url;
  9. link.media = media || 'all';
  10. link.onerror = function(err) {
  11. reject(new URIError(`loadStyle: the stylesheet ${err.target.src} is not accessible.`));
  12. };
  13. link.onload = function() {
  14. resolve();
  15. };
  16. if (aref) {
  17. aref.parentNode.insertBefore(link, aref.nextSibling);
  18. return;
  19. }
  20. if (bref) {
  21. bref.parentNode.insertBefore(link, bref);
  22. return;
  23. }
  24. document.head.appendChild(link);
  25. });
  26. }
  27. loadStyle("v2/static/splash.css")
  28. loadStyle("v2/favicon.ico", {rel: "icon", type: "image/x-icon"})</script></head><body><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N6CBMJD" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><div id="agent-splash-screen" class="loading"><div class="hero"><div class="logo-container"><svg width="133" height="105" viewBox="0 0 133 105" fill="none" xmlns="http://www.w3.org/2000/svg" class="logo-blur"><path fill-rule="evenodd" clip-rule="evenodd" d="M81.697 105H55.0693L0.5 0.5H77.9598C108.079 0.554913 132.484 24.7711 132.5 54.6451C132.452 82.485 109.73 105 81.697 105Z" fill="rgba(0,171,68,0.1)"/></svg> <svg width="133" height="105" viewBox="0 0 133 105" fill="none" xmlns="http://www.w3.org/2000/svg" class="logo"><path fill-rule="evenodd" clip-rule="evenodd" d="M81.697 105H55.0693L0.5 0.5H77.9598C108.079 0.554913 132.484 24.7711 132.5 54.6451C132.452 82.485 109.73 105 81.697 105Z" fill="#DDFFEB"/></svg></div><div class="headings"><h1 class="title">Netdata Alert Notifications</h1><div class="flex-center flex-column" id="main-message">Trying to find a Netdata Agent for this alert...</div><table id="mynodes"></table></div></div></div><script>let searchParams = new URLSearchParams(location.search)
  29. let mg = searchParams.get("agent_machine_guid")
  30. let tr_i = searchParams.get("transition_id")
  31. let token = location.hash.substring(1)
  32. function buildIframe(url) {
  33. let iframe = document.createElement('iframe');
  34. iframe.src = url + "/registry-hello.html" + location.search + "&url=" + url;
  35. iframe.style = { position: "absolute", left: "-99999999px" };
  36. iframe.width = 0 ;
  37. iframe.height = 0;
  38. iframe.tabindex = -1;
  39. iframe.title = "empty";
  40. iframe.classList.add("hidden");
  41. document.body.appendChild(iframe);
  42. return iframe
  43. }
  44. function urlToId(s) {
  45. s = s.trim();
  46. s = s.replace(/^https?:\/\//i, '');
  47. s = s.replace(/\W/g, '_');
  48. return s;
  49. }
  50. fetch("api/v1/registry?action=hello", { cache: "no-cache", credentials: "include" })
  51. .then(function(response) { return response.json() })
  52. .then(function(helloData) {
  53. if (helloData.anonymous_statistics !== false) {
  54. (function (w, d, s, l, i) {
  55. w[l] = w[l] || []
  56. w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" })
  57. var f = d.getElementsByTagName(s)[0],
  58. j = d.createElement(s),
  59. dl = l != "dataLayer" ? "&l=" + l : ""
  60. j.async = true
  61. j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl
  62. f.parentNode.insertBefore(j, f)
  63. })(window, document, "script", "dataLayer", "GTM-N6CBMJD")
  64. }
  65. fetch("api/v1/registry?action=search&for=" + mg, { cache: "no-cache", credentials: "include", headers: { ["X-Netdata-Auth"]: 'Bearer ' + (token || localStorage.getItem("registry-netdata-token")) } })
  66. .then(function(response) { return response.json() })
  67. .then(function(data) {
  68. let table = document.getElementById("mynodes");
  69. if (data.status === "ok") {
  70. if (!token) {
  71. if (location.protocol === "https:" && data.urls.some(function(u) {
  72. return (/http:/).test(u)
  73. })) {
  74. return location.replace('http://' + location.href.substring(8) + "#" + localStorage.getItem("registry-netdata-token"))
  75. }
  76. }
  77. data.urls.sort(function(a, b) {
  78. return b[2] - a[2];
  79. }).forEach(function(urlData) {
  80. let urlMg = urlData[0]
  81. let url = urlData[1]
  82. let urlHostname = urlData[4]
  83. let rowIframe = buildIframe(url)
  84. let row = document.createElement("tr");
  85. let cell1 = document.createElement("td");
  86. let link = document.createElement("a");
  87. link.href = (urlHostname ? (url + "/spaces/" + urlHostname + "/rooms/local/alerts/" + (tr_i || "") + location.search) : url + location.search).replace(/\/+/g, "/");
  88. link.textContent = url;
  89. link.target = "_blank";
  90. link.classList.add("button", "ghost");
  91. cell1.appendChild(link);
  92. row.appendChild(cell1);
  93. let cell2 = document.createElement("td");
  94. cell2.id = urlToId("_" + url + urlMg);
  95. cell2.textContent = "checking...";
  96. row.appendChild(cell2);
  97. table.appendChild(row);
  98. window.addEventListener('message', function(event) {
  99. if (event.source !== rowIframe.contentWindow) return;
  100. if (event.data.url !== url || event.data.mg !== urlMg) return;
  101. link.href = event.data.hostname ? (url + "/spaces/" + event.data.hostname + "/rooms/local/alerts/" + (tr_i || "") + location.search) : url + location.search;
  102. let cellStatus = document.getElementById(urlToId("_" + url + urlMg));
  103. if (event.data.isSame) {
  104. cell2.textContent = "OK";
  105. } else if (event.data.hasError) {
  106. cell2.textContent = "can't connect";
  107. } else {
  108. cell2.textContent = "wrong node";
  109. }
  110. });
  111. setTimeout(function() {
  112. let cellStatus = document.getElementById(urlToId("_" + url + urlMg));
  113. document.getElementById('agent-splash-screen').classList.remove("loading");
  114. if (cell2.textContent !== "checking...") {
  115. return;
  116. }
  117. cell2.textContent = "can't connect";
  118. }, 5000)
  119. })
  120. let el = document.getElementById('agent-splash-screen');
  121. el.classList.add("table");
  122. document.getElementById('main-message').textContent = "Select a URL to see details about this alert:"
  123. } else {
  124. let el = document.getElementById('main-message');
  125. el.innerHTML = "<p>Can't find any Netdata Agent for this alert.</p><small>Netdata learns Agent URLs when you view them and associates them with web browsers.<br/>Probably, you have never viewed the dashboard of the Netdata Agent that sent this notification, with the browser you use now.</small>"
  126. }
  127. }).catch(function(e) {
  128. let el = document.getElementById('main-message');
  129. el.textContent = "Oops! Something went wrong."
  130. })
  131. })</script></body></html>