forked from cyberblu3s/CyberBlue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-wazuh-services.sh
More file actions
executable file
·180 lines (153 loc) · 6.28 KB
/
Copy pathfix-wazuh-services.sh
File metadata and controls
executable file
·180 lines (153 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# ============================================================================
# CyberBlue SOC - Complete Wazuh Services Fix
# ============================================================================
# This script completely fixes all Wazuh SSL certificate issues and ensures
# all Wazuh components (indexer, manager, dashboard) start properly.
# ============================================================================
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Logging functions
log() {
echo -e "${GREEN}[$(date +'%H:%M:%S')] ✅ $1${NC}"
}
log_info() {
echo -e "${CYAN}[$(date +'%H:%M:%S')] ℹ️ $1${NC}"
}
log_warn() {
echo -e "${YELLOW}[$(date +'%H:%M:%S')] ⚠️ $1${NC}"
}
log_error() {
echo -e "${RED}[$(date +'%H:%M:%S')] ❌ $1${NC}"
}
echo -e "${BLUE}"
echo "🔧 =================================="
echo " Complete Wazuh Services Fix"
echo "🔧 =================================="
echo -e "${NC}"
# Step 1: Complete cleanup of Wazuh components
log_info "Step 1: Stopping and removing all Wazuh components..."
sudo docker stop wazuh-indexer wazuh-dashboard wazuh-manager wazuh-cert-genrator 2>/dev/null || true
sudo docker rm wazuh-indexer wazuh-dashboard wazuh-manager wazuh-cert-genrator 2>/dev/null || true
log "All Wazuh containers stopped and removed"
# Step 2: Complete SSL certificate cleanup
log_info "Step 2: Completely cleaning SSL certificate directory..."
sudo rm -rf wazuh/config/wazuh_indexer_ssl_certs
sudo mkdir -p wazuh/config/wazuh_indexer_ssl_certs
sudo chown -R $(whoami):$(id -gn) wazuh/config/wazuh_indexer_ssl_certs
sudo chmod 755 wazuh/config/wazuh_indexer_ssl_certs
log "SSL certificate directory cleaned and recreated"
# Step 3: Remove any cached certificate volumes
log_info "Step 3: Cleaning Docker volumes for fresh certificate generation..."
sudo docker volume rm $(sudo docker volume ls -q | grep -E "(wazuh|cert)") 2>/dev/null || true
log "Docker volumes cleaned"
# Function to run Docker Compose (handles both v1 and v2)
docker_compose() {
if command -v docker-compose >/dev/null 2>&1; then
sudo docker-compose "$@"
else
sudo docker compose "$@"
fi
}
# Step 4: Generate fresh certificates
log_info "Step 4: Generating fresh SSL certificates..."
docker_compose up -d generator
log_info "Waiting for certificate generation to complete (30 seconds)..."
sleep 30
# Check if certificates were generated
if [[ -f "wazuh/config/wazuh_indexer_ssl_certs/admin.pem" ]]; then
log "SSL certificates generated successfully"
else
log_error "Certificate generation failed"
sudo docker logs wazuh-cert-genrator --tail 20
exit 1
fi
# Step 5: Fix certificate permissions and ownership
log_info "Step 5: Fixing certificate permissions and ownership..."
sudo chown -R $(whoami):$(id -gn) wazuh/config/wazuh_indexer_ssl_certs/
sudo chmod 644 wazuh/config/wazuh_indexer_ssl_certs/*.pem
sudo chmod 644 wazuh/config/wazuh_indexer_ssl_certs/*.key 2>/dev/null || true
# Remove any directory artifacts that might have been created
sudo find wazuh/config/wazuh_indexer_ssl_certs -type d -name "*.pem" -exec rm -rf {} \; 2>/dev/null || true
sudo find wazuh/config/wazuh_indexer_ssl_certs -type d -name "*.key" -exec rm -rf {} \; 2>/dev/null || true
log "Certificate permissions fixed"
# Step 6: Start Wazuh services in proper order with health checks
log_info "Step 6: Starting Wazuh services in proper order..."
# Start indexer first
log_info "Starting Wazuh Indexer..."
docker_compose up -d wazuh.indexer
log_info "Waiting for Wazuh Indexer to initialize (45 seconds)..."
sleep 45
# Check indexer health
if curl -s -k -u admin:SecretPassword https://localhost:9200/_cluster/health >/dev/null 2>&1; then
log "Wazuh Indexer is healthy"
else
log_warn "Wazuh Indexer health check failed, but continuing..."
fi
# Start manager
log_info "Starting Wazuh Manager..."
docker_compose up -d wazuh.manager
log_info "Waiting for Wazuh Manager to initialize (30 seconds)..."
sleep 30
# Check manager health
if sudo docker ps | grep -q "wazuh-manager.*Up"; then
log "Wazuh Manager is running"
else
log_warn "Wazuh Manager may have issues, checking logs..."
sudo docker logs wazuh-manager --tail 10
fi
# Start dashboard
log_info "Starting Wazuh Dashboard..."
docker_compose up -d wazuh.dashboard
log_info "Waiting for Wazuh Dashboard to initialize (45 seconds)..."
sleep 45
# Check dashboard health
if curl -s http://localhost:7001 >/dev/null 2>&1; then
log "Wazuh Dashboard is accessible"
else
log_warn "Wazuh Dashboard health check failed, but may still be starting..."
fi
# Step 7: Final verification
log_info "Step 7: Final verification of all Wazuh services..."
echo ""
echo -e "${BLUE}🔍 Wazuh Services Status:${NC}"
sudo docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep wazuh
# Count running Wazuh services
WAZUH_RUNNING=$(sudo docker ps | grep -c "wazuh.*Up" || echo "0")
echo ""
if [[ "$WAZUH_RUNNING" -eq 3 ]]; then
log "All 3 Wazuh services are running successfully!"
echo -e "${GREEN}✅ Wazuh Dashboard: http://$(hostname -I | awk '{print $1}'):7001${NC}"
echo -e "${GREEN}✅ Credentials: admin / SecretPassword${NC}"
elif [[ "$WAZUH_RUNNING" -eq 2 ]]; then
log_warn "2/3 Wazuh services are running (may need more time)"
elif [[ "$WAZUH_RUNNING" -eq 1 ]]; then
log_warn "1/3 Wazuh services are running (check logs for issues)"
else
log_error "No Wazuh services are running properly"
echo "Check logs with: sudo docker logs [wazuh-container-name]"
exit 1
fi
# Step 8: Restart certificate generator to clean state
log_info "Step 8: Cleaning up certificate generator..."
sudo docker stop wazuh-cert-genrator 2>/dev/null || true
echo ""
echo -e "${GREEN}🎉 =================================="
echo " Wazuh Services Fix Complete!"
echo "🎉 ==================================${NC}"
echo ""
echo -e "${CYAN}📊 Total Running Services:${NC}"
TOTAL_RUNNING=$(sudo docker ps | grep -c "Up" || echo "0")
echo " Running containers: $TOTAL_RUNNING"
echo ""
echo -e "${CYAN}🌐 Next Steps:${NC}"
echo "1. Check CyberBlue Portal: https://$(hostname -I | awk '{print $1}'):5443"
echo "2. Should now show 15/15 services running"
echo "3. Access Wazuh at: http://$(hostname -I | awk '{print $1}'):7001"
echo ""