Compare commits
9
Commits
73b4f0690b
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1b2d10394 | ||
|
|
9512520bfe | ||
|
|
ab3044d053 | ||
|
|
7345b746e0 | ||
|
|
e0c4d62f0b | ||
|
|
7dbb13d31b | ||
|
|
a51a493665 | ||
|
|
343ad5d8ad | ||
|
|
c5548ecf6d |
@@ -0,0 +1 @@
|
||||
/ansible
|
||||
@@ -0,0 +1,3 @@
|
||||
# Place under /etc/dnsmasq.d/99-dns-vip.conf
|
||||
# This will propagate the DNS VIP of keepalived as DNS Server over DHCP
|
||||
dhcp-option=option:dns-server,192.168.1.4
|
||||
@@ -0,0 +1,37 @@
|
||||
# Place under /etc/keepalived/keepalived.conf on BACKUP pihole
|
||||
global_defs {
|
||||
router_id pihole-dns-02
|
||||
script_user root
|
||||
enable_script_security
|
||||
}
|
||||
|
||||
vrrp_script chk_ftl {
|
||||
script "/etc/scripts/chk_ftl"
|
||||
interval 1
|
||||
weight -10
|
||||
}
|
||||
|
||||
vrrp_instance PIHOLE {
|
||||
state BACKUP
|
||||
interface eth0
|
||||
virtual_router_id 55
|
||||
priority 145
|
||||
advert_int 1
|
||||
unicast_src_ip 192.168.1.3
|
||||
unicast_peer {
|
||||
192.168.1.2
|
||||
}
|
||||
|
||||
authentication {
|
||||
auth_type PASS
|
||||
auth_pass secret
|
||||
}
|
||||
|
||||
virtual_ipaddress {
|
||||
192.168.1.4/24
|
||||
}
|
||||
|
||||
track_script {
|
||||
chk_ftl
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# Place under /etc/keepalived/keepalived.conf on MASTER pihole
|
||||
global_defs {
|
||||
router_id pihole-dns-01
|
||||
script_user root
|
||||
enable_script_security
|
||||
}
|
||||
|
||||
vrrp_script chk_ftl {
|
||||
script "/usr/local/scripts/chk_ftl"
|
||||
interval 1
|
||||
weight -10
|
||||
}
|
||||
|
||||
vrrp_instance PIHOLE {
|
||||
state MASTER
|
||||
interface eth0
|
||||
virtual_router_id 55
|
||||
priority 150
|
||||
advert_int 1
|
||||
unicast_src_ip 192.168.2.2
|
||||
unicast_peer {
|
||||
192.168.2.3
|
||||
}
|
||||
|
||||
authentication {
|
||||
auth_type PASS
|
||||
auth_pass secret
|
||||
}
|
||||
|
||||
virtual_ipaddress {
|
||||
192.168.2.4/24
|
||||
}
|
||||
|
||||
track_script {
|
||||
chk_ftl
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Place under /etc/scripts for FTL Status check of keepalived
|
||||
|
||||
STATUS=$(ps ax | grep -v grep | grep pihole-FTL)
|
||||
|
||||
if [ "$STATUS" != "" ]
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
#(c)By CeMunz IT
|
||||
#Script zum Sicheren löschen von Festplatten
|
||||
|
||||
clear
|
||||
|
||||
echo "Willkommen beil Löschungstool für Festplatten (HDDs)"
|
||||
echo ""
|
||||
echo "Es laufen insgesammt 2 Löschvorgänge durch!"
|
||||
echo ""
|
||||
|
||||
FP= ls /dev/sd* | grep sd
|
||||
echo ""
|
||||
read -p "Bitte Festplatte wählen (a...g):" lp
|
||||
echo "folgende Festplatte wird gelöscht:"
|
||||
|
||||
echo "/dev/sd$lp"
|
||||
echo -n "Richtige Platte gewählt?(j/n): "
|
||||
read -r choice
|
||||
|
||||
case $choice in
|
||||
j|J)
|
||||
echo "Festplatte wird gelöscht. NICHT VORZEITIG STOPPEN!"
|
||||
;;
|
||||
*)
|
||||
echo "Vorgang abgebrochen!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
echo "Erster Vorgang"
|
||||
|
||||
# Setzen des Passwortes zum löschen
|
||||
sudo hdparm --user-master u --security-set-pass Eins /dev/sd$lp > /dev/null
|
||||
sudo hdparm --user-master u --security-erase-enhanced Eins /dev/sd$lp
|
||||
|
||||
echo "Zweiter Vorgang"
|
||||
|
||||
### In Bearbeitung!
|
||||
### #sudo dd if=/dev/urandom of=/dev/sd$lp bs=4M status=progress conv=fdatasync
|
||||
|
||||
### #echo "Dritter Vorgang"
|
||||
|
||||
sudo dd if=/dev/zero of=/dev/sd$lp bs=1M status=progress conv=fdatasync
|
||||
|
||||
echo "Metadaten löschen:" # wipefs macht die Platte "sauber" von Metadaten für eine neue Nutzung
|
||||
wipefs -a /dev/sd$lp
|
||||
|
||||
echo "Festplatte /dev/sd$lp erfolgtreich gelöscht!"
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Dieses Script ist für die Aktuallisierung vom Hivellominer Node
|
||||
#
|
||||
# Eine Überarbeitung ist zulässig, muss aber dann wieder zur Verfügung gestellt werden
|
||||
#
|
||||
# Version 1.2
|
||||
#
|
||||
# (c)2025 CeMunzIT Christopher Münzer
|
||||
|
||||
clear
|
||||
|
||||
dir="/opt/hivello/"
|
||||
hv="hivello"
|
||||
hvd="$hv.deb"
|
||||
|
||||
if [ -d "$dir" ]; then
|
||||
echo "Verzeichniss vorhanden"
|
||||
else
|
||||
echo "Verzeichniss wird erstellt"
|
||||
if ! mkdir -p "$dir"; then
|
||||
echo "Konnte Verzeichnis nicht erstellen" >&2
|
||||
exit 2
|
||||
fi
|
||||
echo "Verzeichnis erfolgreich erstellt"
|
||||
fi
|
||||
|
||||
cd $dir
|
||||
|
||||
if [ -f "$hvd" ]; then
|
||||
echo "$hv vohanden und wird deinstalliert"
|
||||
sleep 4
|
||||
dpkg -r $hv
|
||||
echo "$hvd Datei wird gelöscht"
|
||||
sleep 4
|
||||
rm -rf $hvd
|
||||
else
|
||||
echo "Datei ist nicht vorhanden und wird gedownloadet"
|
||||
fi
|
||||
|
||||
wget https://download.hivello.services/linux/hivello.deb
|
||||
|
||||
sleep 4
|
||||
|
||||
cd $dir
|
||||
|
||||
echo "neue Datei wird Installiert"
|
||||
|
||||
sleep 3
|
||||
|
||||
dpkg -i $hvd
|
||||
|
||||
echo "beendet"
|
||||
@@ -0,0 +1,6 @@
|
||||
OWM_API_KEY=ea645349e2fbb2ff573104bdd6763604
|
||||
DB_USER=root
|
||||
DB_PASSWORD=dein_db_passwort
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_NAME=weather_db
|
||||
@@ -0,0 +1,36 @@
|
||||
**1. Voraussetzungen installieren**
|
||||
|
||||
API Key auf openweathermap.org generieren
|
||||
|
||||
```
|
||||
pip install requests mariadb python-dotenv
|
||||
```
|
||||
|
||||
**2. Datenbank Vorbereiten**
|
||||
|
||||
```
|
||||
CREATE DATABASE weather_db;
|
||||
|
||||
USE weather_db;
|
||||
|
||||
CREATE TABLE weather_data (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
city VARCHAR(100) NOT NULL,
|
||||
country VARCHAR(10),
|
||||
temperature FLOAT,
|
||||
feels_like FLOAT,
|
||||
humidity INT,
|
||||
pressure INT,
|
||||
wind_speed FLOAT,
|
||||
description VARCHAR(255),
|
||||
recorded_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
**3. Script und .env Datei ablegen und bearbeiten**
|
||||
|
||||
**4. Cronjob**
|
||||
```
|
||||
0 * * * * /usr/bin/python3 /pfad/zum/weather_script.py
|
||||
```
|
||||
@@ -0,0 +1,114 @@
|
||||
import requests
|
||||
import mariadb
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Umgebungsvariablen aus .env laden
|
||||
load_dotenv()
|
||||
|
||||
# --- Konfiguration ---
|
||||
API_KEY = os.getenv("OWM_API_KEY")
|
||||
CITY = "Berlin"
|
||||
UNITS = "metric" # metric = Celsius, imperial = Fahrenheit
|
||||
|
||||
DB_CONFIG = {
|
||||
"user": os.getenv("DB_USER", "root"),
|
||||
"password": os.getenv("DB_PASSWORD", ""),
|
||||
"host": os.getenv("DB_HOST", "127.0.0.1"),
|
||||
"port": int(os.getenv("DB_PORT", 3306)),
|
||||
"database": os.getenv("DB_NAME", "weather_db"),
|
||||
}
|
||||
|
||||
|
||||
def fetch_weather(city):
|
||||
"""Ruft Wetterdaten von der OpenWeatherMap-API ab."""
|
||||
url = "https://api.openweathermap.org/data/2.5/weather"
|
||||
params = {
|
||||
"q": city,
|
||||
"appid": API_KEY,
|
||||
"units": UNITS,
|
||||
"lang": "de",
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(url, params=params, timeout=10)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Fehler beim Abrufen der Wetterdaten: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def parse_weather(data):
|
||||
"""Extrahiert die relevanten Felder aus der API-Antwort."""
|
||||
return {
|
||||
"city": data["name"],
|
||||
"country": data["sys"].get("country", ""),
|
||||
"temperature": data["main"]["temp"],
|
||||
"feels_like": data["main"]["feels_like"],
|
||||
"humidity": data["main"]["humidity"],
|
||||
"pressure": data["main"]["pressure"],
|
||||
"wind_speed": data["wind"]["speed"],
|
||||
"description": data["weather"][0]["description"],
|
||||
}
|
||||
|
||||
|
||||
def save_to_db(weather):
|
||||
"""Speichert die Wetterdaten in der MariaDB."""
|
||||
try:
|
||||
conn = mariadb.connect(**DB_CONFIG)
|
||||
except mariadb.Error as e:
|
||||
print(f"Fehler bei der DB-Verbindung: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
sql = """
|
||||
INSERT INTO weather_data
|
||||
(city, country, temperature, feels_like, humidity,
|
||||
pressure, wind_speed, description, recorded_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
values = (
|
||||
weather["city"],
|
||||
weather["country"],
|
||||
weather["temperature"],
|
||||
weather["feels_like"],
|
||||
weather["humidity"],
|
||||
weather["pressure"],
|
||||
weather["wind_speed"],
|
||||
weather["description"],
|
||||
datetime.now(),
|
||||
)
|
||||
|
||||
try:
|
||||
cursor.execute(sql, values)
|
||||
conn.commit()
|
||||
print(f"Daten gespeichert (ID: {cursor.lastrowid})")
|
||||
except mariadb.Error as e:
|
||||
print(f"Fehler beim Speichern: {e}")
|
||||
conn.rollback()
|
||||
finally:
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
def main():
|
||||
if not API_KEY:
|
||||
print("Fehler: OWM_API_KEY nicht gesetzt. Bitte in .env eintragen.")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Rufe Wetterdaten für '{CITY}' ab...")
|
||||
data = fetch_weather(CITY)
|
||||
|
||||
if data:
|
||||
weather = parse_weather(data)
|
||||
print(f"Temperatur: {weather['temperature']}°C, "
|
||||
f"{weather['description']}")
|
||||
save_to_db(weather)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user