commit fd8c64c9fe9ddc26100ce1da81b7de02be0fde44 Author: fds2610 Date: Mon Nov 10 14:31:17 2025 +0000 :qErster Commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..d27679e --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# 🖥️ monitor + +**monitor** ist ein leichtgewichtiges Monitoring-Tool, das mehrere Systeme per **Ping** überwacht und die Ergebnisse in einer **statischen HTML-Webseite** anzeigt. +Ideal für kleine Netzwerke, Homelabs oder interne Statusseiten. + +--- + +## 🚀 Features + +- Überwacht beliebig viele Hosts per **ICMP-Ping** +- Generiert automatisch eine **statische HTML-Statusseite** +- Anzeige von: + - Antwortzeit (ms) + - Online-/Offline-Status + - Letztem Check-Zeitpunkt +- Einfache Konfiguration über JSON oder YAML +- Keine Datenbank, kein Serverprozess – alles rein statisch +- Optional: automatischer Refresh der Webseite + +--- + +## 📁 Projektstruktur + + diff --git a/check_fds.sh b/check_fds.sh new file mode 100755 index 0000000..81d8db4 --- /dev/null +++ b/check_fds.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# Pfad zur Textdatei mit Hostname-IP-Paaren (pro Zeile: hostname ip) +HOST_FILE="hosts.conf" +# Pfad zum mail_fds.py-Skript +MAIL_SCRIPT="mail_fds.py" +# Pfad zur Statusdatei +STATUS_FILE="/var/www/html/status.txt" + +# Funktion zum Prüfen einer IP und Schreiben des Status +check_ip() { + local hostname="$1" + local ip="$2" + local success_count=0 +# echo "Prüfe $hostname ($ip) ..." + + for i in {1..3}; do + if ping -c 1 -W 2 "$ip" &> /dev/null; then + ((success_count++)) + else + echo " Ping $i an $ip fehlgeschlagen." + fi + done + + local status="online" + if [ "$success_count" -lt 2 ]; then + status="offline" + echo " Mehr als ein Ping fehlgeschlagen für $hostname ($ip). Führe $MAIL_SCRIPT aus." + ./"$MAIL_SCRIPT" --subject "Ping-Fehler bei $hostname $ip" --credentials credentials.conf + else + echo " $hostname ($ip) ist erreichbar." + fi + + # Status in status.conf schreiben/aktualisieren + local now=$(date +"%Y-%m-%d %H:%M") + awk -v h="$hostname" -v i="$ip" -v s="$status" -v d="$now" ' + BEGIN { found=0 } + { + if ($1 == h && $2 == i) { + print h, i, s, d; + found=1; + } else { + print $0; + } + } + END { + if (!found && h != "" && i != "") { + print h, i, s, d; + } + }' "$STATUS_FILE" > "$STATUS_FILE.tmp" && mv "$STATUS_FILE.tmp" "$STATUS_FILE" +} + +# Hauptskript +echo "Pruefung: $(date)" +if [ ! -f "$HOST_FILE" ]; then + echo "Fehler: Datei $HOST_FILE nicht gefunden." + exit 1 +fi +if [ ! -f "$MAIL_SCRIPT" ]; then + echo "Fehler: Skript $MAIL_SCRIPT nicht gefunden." + exit 1 +fi + +# Statusdatei anlegen, falls nicht vorhanden +touch "$STATUS_FILE" + +while read -r line; do + hostname=$(echo "$line" | awk '{print $1}') + ip=$(echo "$line" | awk '{print $2}') + if [ -n "$hostname" ] && [ -n "$ip" ]; then + check_ip "$hostname" "$ip" + fi +done < "$HOST_FILE" diff --git a/credentials-sample.conf b/credentials-sample.conf new file mode 100644 index 0000000..7605d0c --- /dev/null +++ b/credentials-sample.conf @@ -0,0 +1,6 @@ +smtp.strato.de:587 +proxmox@sonnengetrock.net +~%2VNAY@9J9u@Xkwo +proxmox@sonnengetrock.net +felix@schepmann.de + diff --git a/echo b/echo new file mode 100644 index 0000000..e69de29 diff --git a/hosts-sample.conf b/hosts-sample.conf new file mode 100644 index 0000000..a308a08 --- /dev/null +++ b/hosts-sample.conf @@ -0,0 +1,7 @@ +OpenCCU 192.168.2.4 +HomeAssistant 192.168.2.11 +Paperless 192.168.2.19 +Server1 192.168.2.18 +Server2 192.168.2.17 +Server3 192.168.2.16 + diff --git a/html/mon.html b/html/mon.html new file mode 100644 index 0000000..e78d1c1 --- /dev/null +++ b/html/mon.html @@ -0,0 +1,299 @@ + + + + + + FDS Server-Status + + + +
☰
+ + +
+

Server-Status Übersicht

+ + + + + + + + + + + + +
HostnameIP-AdresseStatusLetzte Prüfung
+
+ + + + + + + diff --git a/mail_fds.py b/mail_fds.py new file mode 100755 index 0000000..27bd540 --- /dev/null +++ b/mail_fds.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +import smtplib +import argparse +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart + +def read_credentials(file_path): + """Liest SMTP-Serverdetails und Credentials aus einer Textdatei. + Format der Datei (jeweils eine Zeile): + smtp_server:port + username + password + from_address + to_address + """ + with open(file_path, 'r') as f: + lines = [line.strip() for line in f.readlines() if line.strip()] + if len(lines) != 5: + raise ValueError("Die Credential-Datei muss genau 5 Zeilen enthalten.") + smtp_server, smtp_port = lines[0].split(':') + username = lines[1] + password = lines[2] + from_addr = lines[3] + to_addr = lines[4] + return smtp_server, smtp_port, username, password, from_addr, to_addr + +def send_email(smtp_server, smtp_port, username, password, from_addr, to_addr, subject, body): + """Versendet eine E-Mail mit den angegebenen Parametern.""" + msg = MIMEMultipart() + msg['From'] = from_addr + msg['To'] = to_addr + msg['Subject'] = subject + msg.attach(MIMEText(body, 'plain')) + + try: + with smtplib.SMTP(smtp_server, int(smtp_port)) as server: + server.starttls() + server.login(username, password) + server.send_message(msg) + print("E-Mail erfolgreich versendet.") + except Exception as e: + print(f"Fehler beim Versand der E-Mail: {e}") + +def main(): + parser = argparse.ArgumentParser(description='Versendet eine E-Mail mit festem Textinhalt und dynamischem Betreff.') + parser.add_argument('--subject', type=str, required=True, help='Betreff der E-Mail') + parser.add_argument('--credentials', type=str, required=True, help='Pfad zur Credential-Datei') + args = parser.parse_args() + + smtp_server, smtp_port, username, password, from_addr, to_addr = read_credentials(args.credentials) + body = """Hallo, + +dies ist eine automatisch generierte E-Mail. + +Mit freundlichen Grüßen, +Dein Skript""" + + send_email(smtp_server, smtp_port, username, password, from_addr, to_addr, args.subject, body) + +if __name__ == "__main__": + main()