diff --git a/README.md b/README.md index 97bec60..33bb013 100644 --- a/README.md +++ b/README.md @@ -25,33 +25,109 @@ chmod +x freshStart.sh ``` ## 📦 Components Installed -**System Packages:** +### System Packages * python3-pip * smartmontools * iperf3 * python3-psutil * python3-requests +* lm-sensors +* neofetch +* rsync -**Prometheus Node Exporter:** +### Prometheus Node Exporter ✅ Installed as a systemd service ✅ Runs on default port 9100 ✅ Configured to start on boot -**Hardware Monitoring Daemon (hwmon):** +### Hardware Monitoring Daemon (hwmon) ✅ Installed as a systemd service and timer -✅ Performs regular system health checks +✅ Performs regular system health checks every 15 minutes ✅ Creates tickets for detected issues +✅ **NEW:** API key configuration via `/etc/hwmonDaemon/.env` + +## ⚙️ Configuration + +### hwmonDaemon API Key Setup + +The script will prompt you for an API key during installation. You can: + +**Option 1: Enter during installation** +```bash +Enter API key (or press Enter to skip): d8f356a06bd5612eca9c5ff948b592a56020cc61937764461458372c9ef30931 +``` + +**Option 2: Configure later** +Edit the configuration file: +```bash +nano /etc/hwmonDaemon/.env +``` + +Add your API key: +```env +TICKET_API_KEY=your_actual_api_key_here +TICKET_API_URL=http://10.10.10.45/create_ticket_api.php +``` + +The `.env` file is created with restricted permissions (`chmod 600`) for security. + +## 🔍 Verification -🔍 **Verification** Verify service status after installation: ```bash systemctl status node_exporter systemctl status hwmon.timer ``` -🌐 **Network Requirements** -Service Purpose -GitHub Node Exporter download -10.10.10.110:3000 hwmon daemon files -10.10.10.45 Ticket API access \ No newline at end of file +Test hwmonDaemon with dry-run: +```bash +/usr/bin/env python3 -c "import urllib.request; exec(urllib.request.urlopen('http://10.10.10.63:3000/LotusGuild/hwmonDaemon/raw/branch/main/hwmonDaemon.py').read().decode('utf-8'))" --dry-run +``` + +Check if API key is loaded: +```bash +cat /etc/hwmonDaemon/.env +journalctl -u hwmon.service | grep "TICKET_API_KEY" +``` + +## 🌐 Network Requirements + +| Service | Purpose | +|---------|---------| +| GitHub | Node Exporter download | +| 10.10.10.63:3000 | hwmon daemon files (Gitea) | +| 10.10.10.45 | Ticket API access | + +## 📁 File Locations + +| File/Directory | Purpose | +|---------------|---------| +| `/etc/hwmonDaemon/.env` | API key configuration | +| `/var/log/hwmonDaemon/` | hwmon log files | +| `/etc/systemd/system/hwmon.service` | hwmon systemd service | +| `/etc/systemd/system/hwmon.timer` | hwmon systemd timer | +| `/usr/local/bin/node_exporter` | Node Exporter binary | + +## 🔧 Troubleshooting + +### hwmonDaemon not creating tickets + +Check if API key is configured: +```bash +cat /etc/hwmonDaemon/.env +``` + +Check logs for authentication errors: +```bash +journalctl -u hwmon.service -n 50 +``` + +### Update API key after installation + +Edit the configuration file: +```bash +nano /etc/hwmonDaemon/.env +``` + +No service restart needed - changes take effect on next run. \ No newline at end of file diff --git a/freshStart.sh b/freshStart.sh index c6a412e..c65f0b1 100644 --- a/freshStart.sh +++ b/freshStart.sh @@ -99,12 +99,12 @@ echo "Installing hwmon daemon..." # Download hwmon service files with error handling echo "Downloading hwmon service files..." -if ! curl --max-time 30 --retry 3 -o /etc/systemd/system/hwmon.service http://10.10.10.110:3000/JWS/hwmonDaemon/raw/branch/main/hwmon.service; then +if ! curl --max-time 30 --retry 3 -o /etc/systemd/system/hwmon.service http://10.10.10.63:3000/LotusGuild/hwmonDaemon/raw/branch/main/hwmon.service; then echo "ERROR: Failed to download hwmon.service" exit 1 fi -if ! curl --max-time 30 --retry 3 -o /etc/systemd/system/hwmon.timer http://10.10.10.110:3000/JWS/hwmonDaemon/raw/branch/main/hwmon.timer; then +if ! curl --max-time 30 --retry 3 -o /etc/systemd/system/hwmon.timer http://10.10.10.63:3000/LotusGuild/hwmonDaemon/raw/branch/main/hwmon.timer; then echo "ERROR: Failed to download hwmon.timer" exit 1 fi @@ -120,9 +120,51 @@ if [[ ! -s /etc/systemd/system/hwmon.timer ]]; then exit 1 fi -# Create log directory for hwmon +# Create configuration directory for hwmon +echo "Setting up hwmon configuration..." +mkdir -p /etc/hwmonDaemon mkdir -p /var/log/hwmonDaemon +# Prompt for API key or use default +echo "" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " hwmonDaemon API Key Configuration" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo "" +echo "The hwmonDaemon requires an API key to create tickets." +echo "You can enter it now or configure it later by editing:" +echo " /etc/hwmonDaemon/.env" +echo "" +read -p "Enter API key (or press Enter to skip): " API_KEY + +if [[ -n "$API_KEY" ]]; then + # Create .env file with API key + cat > /etc/hwmonDaemon/.env << EOF +# hwmonDaemon Configuration +# Auto-generated by freshStart.sh on $(date) + +# Ticket API Configuration +TICKET_API_KEY=$API_KEY +TICKET_API_URL=http://10.10.10.45/create_ticket_api.php +EOF + chmod 600 /etc/hwmonDaemon/.env + echo "✓ API key configured in /etc/hwmonDaemon/.env" +else + # Create template .env file + cat > /etc/hwmonDaemon/.env << 'EOF' +# hwmonDaemon Configuration +# Edit this file to add your API key + +# Ticket API Configuration +TICKET_API_KEY=your_api_key_here +TICKET_API_URL=http://10.10.10.45/create_ticket_api.php +EOF + chmod 600 /etc/hwmonDaemon/.env + echo "⚠️ WARNING: API key not configured!" + echo " Edit /etc/hwmonDaemon/.env to add your API key before tickets can be created" +fi +echo "" + # Start the hwmon daemon systemctl daemon-reload systemctl enable hwmon.timer @@ -148,7 +190,7 @@ fi # Test hwmon with error handling echo "Testing hwmon dry-run..." -if ! /usr/bin/env python3 -c "import urllib.request; exec(urllib.request.urlopen('http://10.10.10.110:3000/JWS/hwmonDaemon/raw/branch/main/hwmonDaemon.py').read().decode('utf-8'))" --dry-run; then +if ! /usr/bin/env python3 -c "import urllib.request; exec(urllib.request.urlopen('http://10.10.10.63:3000/LotusGuild/hwmonDaemon/raw/branch/main/hwmonDaemon.py').read().decode('utf-8'))" --dry-run; then echo "WARNING: hwmon dry-run test failed, but services are installed" fi @@ -161,7 +203,14 @@ echo "Services installed:" echo " - Node Exporter: http://$(hostname -I | awk '{print $1}'):9100/metrics" echo " - hwmon daemon: Monitoring system health every 15 minutes" echo "" +echo "Configuration files:" +echo " - hwmon config: /etc/hwmonDaemon/.env" +echo "" echo "Log locations:" echo " - Node Exporter: journalctl -u node_exporter" echo " - hwmon: journalctl -u hwmon.service" -echo " - hwmon logs: /var/log/hwmonDaemon/" \ No newline at end of file +echo " - hwmon logs: /var/log/hwmonDaemon/" +echo "" +if [[ ! -s /etc/hwmonDaemon/.env ]] || grep -q "your_api_key_here" /etc/hwmonDaemon/.env 2>/dev/null; then + echo "⚠️ REMINDER: Configure your API key in /etc/hwmonDaemon/.env" +fi \ No newline at end of file diff --git a/update_api_key.sh b/update_api_key.sh new file mode 100755 index 0000000..49d0201 --- /dev/null +++ b/update_api_key.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# Quick script to update hwmonDaemon API key on existing servers + +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " hwmonDaemon API Key Update Utility" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo "" + +# Check if running as root +if [[ $EUID -ne 0 ]]; then + echo "❌ This script must be run as root" + exit 1 +fi + +# Create directory if it doesn't exist +mkdir -p /etc/hwmonDaemon + +# Prompt for API key +echo "Enter your Tinker Tickets API key:" +read -p "API Key: " API_KEY + +if [[ -z "$API_KEY" ]]; then + echo "❌ API key cannot be empty" + exit 1 +fi + +# Create/update .env file +cat > /etc/hwmonDaemon/.env << EOF +# hwmonDaemon Configuration +# Updated on $(date) + +# Ticket API Configuration +TICKET_API_KEY=$API_KEY +TICKET_API_URL=http://10.10.10.45/create_ticket_api.php +EOF + +chmod 600 /etc/hwmonDaemon/.env + +echo "" +echo "✅ API key updated successfully!" +echo "" +echo "Configuration saved to: /etc/hwmonDaemon/.env" +echo "" +echo "The new API key will be used on the next hwmon run." +echo "To test immediately:" +echo " systemctl start hwmon.service" +echo "" +echo "Check logs:" +echo " journalctl -u hwmon.service -n 20"