registry-alert-redirect.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!doctype html><html><head><title>Netdata Registry</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><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=search&for=" + mg, { cache: "no-cache", credentials: "include", headers: { Authorization: 'Bearer ' + (token || localStorage.getItem("registry-netdata-token")) } })
  51. .then(function(response) { return response.json() })
  52. .then(function(data) {
  53. let table = document.getElementById("mynodes");
  54. if (data.status === "ok") {
  55. if (location.protocol === "https:" && data.urls.some(function(u) {
  56. return (/http:/).test(u)
  57. })) {
  58. return location.replace('http://' + location.href.substring(8) + "#" + localStorage.getItem("registry-netdata-token"))
  59. }
  60. data.urls.sort(function(a, b) {
  61. return b[2] - a[2];
  62. }).forEach(function(urlData) {
  63. let urlMg = urlData[0]
  64. let url = urlData[1]
  65. let urlHostname = urlData[4]
  66. let rowIframe = buildIframe(url)
  67. let row = document.createElement("tr");
  68. let cell1 = document.createElement("td");
  69. let link = document.createElement("a");
  70. link.href = urlHostname ? (url + "/spaces/" + urlHostname + "/rooms/local/alerts/" + (tr_i || "") + location.search) : url + location.search;
  71. link.textContent = url;
  72. link.target = "_blank";
  73. link.classList.add("button", "ghost");
  74. cell1.appendChild(link);
  75. row.appendChild(cell1);
  76. let cell2 = document.createElement("td");
  77. cell2.id = urlToId("_" + url + urlMg);
  78. cell2.textContent = "checking...";
  79. row.appendChild(cell2);
  80. table.appendChild(row);
  81. window.addEventListener('message', function(event) {
  82. if (event.source !== rowIframe.contentWindow) return;
  83. if (event.data.url !== url || event.data.mg !== urlMg) return;
  84. link.href = event.data.hostname ? (url + "/spaces/" + event.data.hostname + "/rooms/local/alerts/" + (tr_i || "") + location.search) : url + location.search;
  85. let cellStatus = document.getElementById(urlToId("_" + url + urlMg));
  86. if (event.data.isSame) {
  87. cell2.textContent = "OK";
  88. } else if (event.data.hasError) {
  89. cell2.textContent = "can't connect";
  90. } else {
  91. cell2.textContent = "wrong node";
  92. }
  93. });
  94. setTimeout(function() {
  95. let cellStatus = document.getElementById(urlToId("_" + url + urlMg));
  96. document.getElementById('agent-splash-screen').classList.remove("loading");
  97. if (cell2.textContent !== "checking...") {
  98. return;
  99. }
  100. cell2.textContent = "can't connect";
  101. }, 5000)
  102. })
  103. let el = document.getElementById('agent-splash-screen');
  104. el.classList.add("table");
  105. document.getElementById('main-message').textContent = "Select a URL to see details about this alert:"
  106. } else {
  107. let el = document.getElementById('main-message');
  108. 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>"
  109. }
  110. }).catch(function(e) {
  111. let el = document.getElementById('main-message');
  112. el.textContent = "Oops! Something went wrong."
  113. })</script></body></html>