Parcourir la source

Allow us to view stored data in real-time! 🥳🥳

Sacha Ligthert il y a 1 an
Parent
commit
6c38363694
2 fichiers modifiés avec 64 ajouts et 0 suppressions
  1. 63 0
      server/agents.html
  2. 1 0
      server/jsonDumper.go

+ 63 - 0
server/agents.html

@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>JSON Data Display</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            margin: 20px;
+        }
+        #data-container {
+            margin-top: 20px;
+        }
+        .data-item {
+            margin-bottom: 10px;
+        }
+    </style>
+</head>
+<body>
+    <h1>JSON Data Display</h1>
+    <div id="data-container">
+        <!-- Data will be inserted here -->
+    </div>
+
+    <script>
+        const url = 'http://localhost:8080/json'; // Replace with your actual URL
+        const dataContainer = document.getElementById('data-container');
+
+        async function fetchData() {
+            try {
+                const response = await fetch(url);
+                if (!response.ok) {
+                    throw new Error('Network response was not ok');
+                }
+                const data = await response.json();
+                updateData(data);
+            } catch (error) {
+                console.error('There was a problem with the fetch operation:', error);
+            }
+        }
+
+        function updateData(data) {
+            const agent = data.Agents.blackbox;
+            dataContainer.innerHTML = `
+                <div class="data-item"><strong>Name:</strong> ${agent.Name}</div>
+                <div class="data-item"><strong>Registration Time:</strong> ${agent.Reg}</div>
+                <div class="data-item"><strong>Cores:</strong> ${agent.Cores}</div>
+                <div class="data-item"><strong>CPU Usage:</strong> ${agent.Cpu.join(', ')}</div>
+                <div class="data-item"><strong>Max Memory:</strong> ${agent.Mem_max}</div>
+                <div class="data-item"><strong>Memory Usage:</strong> ${agent.Mem_usg.join(', ')}</div>
+                <div class="data-item"><strong>Task ID:</strong> ${agent.TaskId}</div>
+            `;
+        }
+
+        // Fetch data initially
+        fetchData();
+
+        // Fetch data every second
+        setInterval(fetchData, 1000);
+    </script>
+</body>
+</html>

+ 1 - 0
server/jsonDumper.go

@@ -13,6 +13,7 @@ func (server *Server) jsonDumper(w http.ResponseWriter, r *http.Request) {
 		w.WriteHeader(http.StatusInternalServerError)
 		w.Write([]byte("This is my Website"))
 	}
+	w.Header().Set("Access-Control-Allow-Origin", "*")
 	w.Header().Set("Content-Type", "application/json")
 	w.WriteHeader(http.StatusOK)
 	w.Write(json)