added functionality
This commit is contained in:
34
app.js
34
app.js
@ -1,34 +0,0 @@
|
|||||||
function updateMetrics() {
|
|
||||||
fetch('/api/metrics')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
document.getElementById('network-health').innerHTML = `
|
|
||||||
<div class="metric-card">
|
|
||||||
<h2>Network Health</h2>
|
|
||||||
<p>CPU: ${data.network_health.cpu_percent}%</p>
|
|
||||||
<p>Memory: ${data.network_health.memory_percent}%</p>
|
|
||||||
<p>Connections: ${data.network_health.network_connections}</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
document.getElementById('latency').innerHTML = `
|
|
||||||
<div class="metric-card">
|
|
||||||
<h2>Latency</h2>
|
|
||||||
<p>${data.latency.toFixed(2)} ms</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
document.getElementById('bandwidth').innerHTML = `
|
|
||||||
<div class="metric-card">
|
|
||||||
<h2>Bandwidth</h2>
|
|
||||||
<p>Download: ${data.bandwidth.download.toFixed(2)} Mbps</p>
|
|
||||||
<p>Upload: ${data.bandwidth.upload.toFixed(2)} Mbps</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update metrics every 30 seconds
|
|
||||||
setInterval(updateMetrics, 30000);
|
|
||||||
// Initial update
|
|
||||||
updateMetrics();
|
|
||||||
39
app.py
Normal file
39
app.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from flask import Flask, render_template, jsonify
|
||||||
|
import subprocess
|
||||||
|
import platform
|
||||||
|
import json
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
def ping(host):
|
||||||
|
param = '-n' if platform.system().lower() == 'windows' else '-c'
|
||||||
|
command = ['ping', param, '1', host]
|
||||||
|
return subprocess.call(command, stdout=subprocess.DEVNULL) == 0
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
with open('config.json') as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
device_status = {}
|
||||||
|
|
||||||
|
def update_status():
|
||||||
|
while True:
|
||||||
|
config = load_config()
|
||||||
|
for device in config['devices']:
|
||||||
|
device_status[device['name']] = ping(device['ip'])
|
||||||
|
time.sleep(config['check_interval'])
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def home():
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
|
@app.route('/api/status')
|
||||||
|
def status():
|
||||||
|
return jsonify(device_status)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
status_thread = threading.Thread(target=update_status, daemon=True)
|
||||||
|
status_thread.start()
|
||||||
|
app.run(debug=True)
|
||||||
25
config.json
Normal file
25
config.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"name": "UniFi Dream Machine Pro",
|
||||||
|
"ip": "192.168.1.1",
|
||||||
|
"type": "router"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "UniFi Switch 24 PoE",
|
||||||
|
"ip": "192.168.1.2",
|
||||||
|
"type": "switch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AP Living Room",
|
||||||
|
"ip": "192.168.1.10",
|
||||||
|
"type": "access_point"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AP Office",
|
||||||
|
"ip": "192.168.1.11",
|
||||||
|
"type": "access_point"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"check_interval": 30
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>GANDALF Network Monitor</h1>
|
<h1>GANDALF (Global Advanced Network Detection And Link Facilitator)</h1>
|
||||||
<p>Ubiquiti Network Management Dashboard</p>
|
<p>Ubiquiti Network Management Dashboard</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
18
static/app.js
Normal file
18
static/app.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
function updateDeviceStatus() {
|
||||||
|
fetch('/api/status')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
Object.entries(data).forEach(([deviceName, isUp]) => {
|
||||||
|
const deviceElement = document.querySelector(`.device-status:has(span:contains("${deviceName}"))`);
|
||||||
|
if (deviceElement) {
|
||||||
|
const indicator = deviceElement.querySelector('.status-indicator');
|
||||||
|
indicator.className = `status-indicator status-${isUp ? 'up' : 'down'}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update every 30 seconds
|
||||||
|
setInterval(updateDeviceStatus, 30000);
|
||||||
|
// Initial update
|
||||||
|
updateDeviceStatus();
|
||||||
Reference in New Issue
Block a user