added functionality

This commit is contained in:
2025-01-04 01:42:16 -05:00
parent 5173302eb4
commit 7b70f4a980
5 changed files with 83 additions and 35 deletions

39
app.py Normal file
View 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)