Added api key for hwmonDaemon
This commit is contained in:
96
README.md
96
README.md
@@ -25,33 +25,109 @@ chmod +x freshStart.sh
|
|||||||
```
|
```
|
||||||
|
|
||||||
## 📦 Components Installed
|
## 📦 Components Installed
|
||||||
**System Packages:**
|
|
||||||
|
|
||||||
|
### System Packages
|
||||||
* python3-pip
|
* python3-pip
|
||||||
* smartmontools
|
* smartmontools
|
||||||
* iperf3
|
* iperf3
|
||||||
* python3-psutil
|
* python3-psutil
|
||||||
* python3-requests
|
* python3-requests
|
||||||
|
* lm-sensors
|
||||||
|
* neofetch
|
||||||
|
* rsync
|
||||||
|
|
||||||
**Prometheus Node Exporter:**
|
### Prometheus Node Exporter
|
||||||
✅ Installed as a systemd service
|
✅ Installed as a systemd service
|
||||||
✅ Runs on default port 9100
|
✅ Runs on default port 9100
|
||||||
✅ Configured to start on boot
|
✅ Configured to start on boot
|
||||||
|
|
||||||
**Hardware Monitoring Daemon (hwmon):**
|
### Hardware Monitoring Daemon (hwmon)
|
||||||
✅ Installed as a systemd service and timer
|
✅ 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
|
✅ 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:
|
Verify service status after installation:
|
||||||
```bash
|
```bash
|
||||||
systemctl status node_exporter
|
systemctl status node_exporter
|
||||||
systemctl status hwmon.timer
|
systemctl status hwmon.timer
|
||||||
```
|
```
|
||||||
|
|
||||||
🌐 **Network Requirements**
|
Test hwmonDaemon with dry-run:
|
||||||
Service Purpose
|
```bash
|
||||||
GitHub Node Exporter download
|
/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
|
||||||
10.10.10.110:3000 hwmon daemon files
|
```
|
||||||
10.10.10.45 Ticket API access
|
|
||||||
|
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.
|
||||||
@@ -99,12 +99,12 @@ echo "Installing hwmon daemon..."
|
|||||||
|
|
||||||
# Download hwmon service files with error handling
|
# Download hwmon service files with error handling
|
||||||
echo "Downloading hwmon service files..."
|
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"
|
echo "ERROR: Failed to download hwmon.service"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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"
|
echo "ERROR: Failed to download hwmon.timer"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -120,9 +120,51 @@ if [[ ! -s /etc/systemd/system/hwmon.timer ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
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
|
# Start the hwmon daemon
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable hwmon.timer
|
systemctl enable hwmon.timer
|
||||||
@@ -148,7 +190,7 @@ fi
|
|||||||
|
|
||||||
# Test hwmon with error handling
|
# Test hwmon with error handling
|
||||||
echo "Testing hwmon dry-run..."
|
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"
|
echo "WARNING: hwmon dry-run test failed, but services are installed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -161,7 +203,14 @@ echo "Services installed:"
|
|||||||
echo " - Node Exporter: http://$(hostname -I | awk '{print $1}'):9100/metrics"
|
echo " - Node Exporter: http://$(hostname -I | awk '{print $1}'):9100/metrics"
|
||||||
echo " - hwmon daemon: Monitoring system health every 15 minutes"
|
echo " - hwmon daemon: Monitoring system health every 15 minutes"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "Configuration files:"
|
||||||
|
echo " - hwmon config: /etc/hwmonDaemon/.env"
|
||||||
|
echo ""
|
||||||
echo "Log locations:"
|
echo "Log locations:"
|
||||||
echo " - Node Exporter: journalctl -u node_exporter"
|
echo " - Node Exporter: journalctl -u node_exporter"
|
||||||
echo " - hwmon: journalctl -u hwmon.service"
|
echo " - hwmon: journalctl -u hwmon.service"
|
||||||
echo " - hwmon logs: /var/log/hwmonDaemon/"
|
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
|
||||||
49
update_api_key.sh
Executable file
49
update_api_key.sh
Executable file
@@ -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"
|
||||||
Reference in New Issue
Block a user