From 7b70f4a980c6b3542b74f9fe9912f378b554ace4 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 4 Jan 2025 01:42:16 -0500 Subject: [PATCH] added functionality --- app.js | 34 ---------------------------------- app.py | 39 +++++++++++++++++++++++++++++++++++++++ config.json | 25 +++++++++++++++++++++++++ index.html | 2 +- static/app.js | 18 ++++++++++++++++++ 5 files changed, 83 insertions(+), 35 deletions(-) delete mode 100644 app.js create mode 100644 app.py create mode 100644 config.json create mode 100644 static/app.js diff --git a/app.js b/app.js deleted file mode 100644 index e2c05ee..0000000 --- a/app.js +++ /dev/null @@ -1,34 +0,0 @@ -function updateMetrics() { - fetch('/api/metrics') - .then(response => response.json()) - .then(data => { - document.getElementById('network-health').innerHTML = ` -
-

Network Health

-

CPU: ${data.network_health.cpu_percent}%

-

Memory: ${data.network_health.memory_percent}%

-

Connections: ${data.network_health.network_connections}

-
- `; - - document.getElementById('latency').innerHTML = ` -
-

Latency

-

${data.latency.toFixed(2)} ms

-
- `; - - document.getElementById('bandwidth').innerHTML = ` -
-

Bandwidth

-

Download: ${data.bandwidth.download.toFixed(2)} Mbps

-

Upload: ${data.bandwidth.upload.toFixed(2)} Mbps

-
- `; - }); -} - -// Update metrics every 30 seconds -setInterval(updateMetrics, 30000); -// Initial update -updateMetrics(); diff --git a/app.py b/app.py new file mode 100644 index 0000000..9469088 --- /dev/null +++ b/app.py @@ -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) diff --git a/config.json b/config.json new file mode 100644 index 0000000..7e722e2 --- /dev/null +++ b/config.json @@ -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 +} diff --git a/index.html b/index.html index 8f9e423..0e00ba2 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@
-

GANDALF Network Monitor

+

GANDALF (Global Advanced Network Detection And Link Facilitator)

Ubiquiti Network Management Dashboard

diff --git a/static/app.js b/static/app.js new file mode 100644 index 0000000..f22b965 --- /dev/null +++ b/static/app.js @@ -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();