|
Bogdan Timofte
authored
3 months ago
|
1
|
#!/bin/bash
|
|
|
2
|
|
|
|
3
|
# Test script pentru debugging autoSMART collector
|
|
|
4
|
# Acest script permite testarea manualelor cu debugging activ
|
|
|
5
|
|
|
|
6
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
7
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
|
8
|
|
|
|
9
|
echo "🔍 Testing autoSMART collector debugging..."
|
|
|
10
|
echo "Project root: $PROJECT_ROOT"
|
|
|
11
|
|
|
|
12
|
# Verifică dacă există configurația de debug
|
|
|
13
|
if [[ -f "/etc/default/autosmart" ]]; then
|
|
|
14
|
echo "✓ Found configuration file: /etc/default/autosmart"
|
|
|
15
|
echo "Current configuration:"
|
|
|
16
|
cat /etc/default/autosmart
|
|
|
17
|
echo ""
|
|
|
18
|
else
|
|
|
19
|
echo "❌ Configuration file /etc/default/autosmart not found"
|
|
|
20
|
echo "Creating test configuration..."
|
|
|
21
|
sudo mkdir -p /etc/default
|
|
|
22
|
sudo tee /etc/default/autosmart > /dev/null << 'EOF'
|
|
|
23
|
# AutoSMART Configuration - Test Debug Mode
|
|
|
24
|
AUTOSMART_DEBUG="true"
|
|
|
25
|
EOF
|
|
|
26
|
echo "✓ Test configuration created"
|
|
|
27
|
fi
|
|
|
28
|
|
|
|
29
|
# Verifică dacă există fișierul de configurare pentru daemon
|
|
|
30
|
CONFIG_FILE="$PROJECT_ROOT/test-config.yaml"
|
|
|
31
|
if [[ ! -f "$CONFIG_FILE" ]]; then
|
|
|
32
|
echo "Creating test configuration file: $CONFIG_FILE"
|
|
|
33
|
cat > "$CONFIG_FILE" << 'EOF'
|
|
|
34
|
node:
|
|
|
35
|
id: test-node
|
|
|
36
|
scan_interval: 30
|
|
|
37
|
store_unchanged: false
|
|
|
38
|
|
|
|
39
|
collection:
|
|
|
40
|
full_scan_interval: 300
|
|
|
41
|
|
|
|
42
|
database:
|
|
|
43
|
host: 192.168.2.102
|
|
|
44
|
database: autosmart
|
|
|
45
|
user: autosmart
|
|
|
46
|
password: autosmart123
|
|
|
47
|
EOF
|
|
|
48
|
echo "✓ Test config created: $CONFIG_FILE"
|
|
|
49
|
fi
|
|
|
50
|
|
|
|
51
|
echo ""
|
|
|
52
|
echo "🔧 Available devices for testing:"
|
|
|
53
|
ls -la /dev/sd* /dev/nvme* 2>/dev/null | head -10
|
|
|
54
|
|
|
|
55
|
echo ""
|
|
|
56
|
echo "💾 Testing database connectivity..."
|
|
|
57
|
if command -v psql >/dev/null; then
|
|
|
58
|
echo "Testing connection to database..."
|
|
|
59
|
psql -h 192.168.2.102 -U autosmart -d autosmart -c "SELECT 'Database connection OK' as status;" 2>/dev/null || echo "❌ Database connection failed"
|
|
|
60
|
else
|
|
|
61
|
echo "❌ psql not available for testing"
|
|
|
62
|
fi
|
|
|
63
|
|
|
|
64
|
echo ""
|
|
|
65
|
echo "🚀 To run collector in debug mode:"
|
|
|
66
|
echo "export AUTOSMART_DEBUG=true"
|
|
|
67
|
echo "sudo -E perl $SCRIPT_DIR/smart-collector-daemon.pl --config $CONFIG_FILE --debug --foreground"
|
|
|
68
|
|
|
|
69
|
echo ""
|
|
|
70
|
echo "📊 To check hdd_presence table:"
|
|
|
71
|
echo "psql -h 192.168.2.102 -U autosmart -d autosmart -c \"SELECT * FROM hdd_presence;\""
|
|
|
72
|
|
|
|
73
|
echo ""
|
|
|
74
|
echo "📋 To check hdd_inventory table:"
|
|
|
75
|
echo "psql -h 192.168.2.102 -U autosmart -d autosmart -c \"SELECT id, serial_number, model_name, current_node_id, last_seen FROM hdd_inventory;\""
|
|
|
76
|
|
|
|
77
|
echo ""
|
|
|
78
|
echo "🔍 To check SMART readings:"
|
|
|
79
|
echo "psql -h 192.168.2.102 -U autosmart -d autosmart -c \"SELECT COUNT(*) as total_readings FROM smart_readings;\""
|