forked from OpenSecureCo/Demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwazuh_healthcheck.sh
173 lines (164 loc) · 5.95 KB
/
wazuh_healthcheck.sh
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
#!/bin/sh
host=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
#Check wazuh-Authd processes
if [ -n "$(pgrep wazuh-authd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-authd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-authd", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-authd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-authd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-authd", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check wazuh-db processes
if [ -n "$(pgrep wazuh-db)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-db", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-db", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-db)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-db", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-db", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check wazuh-execd processes
if [ -n "$(pgrep wazuh-execd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-execd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-execd", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-execd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-execd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-execd", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check wazuh-analysisd wazuhprocesses
if [ -n "$(pgrep wazuh-analysisd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-analysisd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-analysisd", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-analysisd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-analysisd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-analysisd", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check wazuh-syscheckd wazuhprocesses
if [ -n "$(pgrep wazuh-syscheckd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-syscheckd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-syscheckd", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-syscheckd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-syscheckd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-syscheckd", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check ossec-remoted wazuhprocesses
if [ -n "$(pgrep ossec-remoted)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"ossec-remoted", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-remoted", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-remoted)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-remoted", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-remoted", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check wazuh-logcollector wazuhprocesses
if [ -n "$(ps -ef | grep wazuh-logcollector | grep -v grep | awk '{print $2}')" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-logcollector", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-logcollector", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(ps -ef | grep wazuh-logcollector | grep -v grep | awk '{print $2}')" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-logcollector", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-logcollector", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check wazuh-monitord wazuhprocesses
if [ -n "$(pgrep wazuh-monitord)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-monitord", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-monitord", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-monitord)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-monitord", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-monitord", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi
#Check wazuh-modulesd wazuhprocesses
if [ -n "$(pgrep wazuh-modulesd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-modulesd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
#Attempt a restart
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-modulesd", "healthy":"attempting_restart"}'
echo -e "$json" >> /tmp/health.json
service wazuh-manager restart
sleep 5
if [ -n "$(pgrep wazuh-modulesd)" ]; then
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-modulesd", "healthy":"yes"}'
echo -e "$json" >> /tmp/health.json
else
json='{"host":"'"$host"'", "wazuhprocess":"wazuh-modulesd", "healthy":"no"}'
echo -e "$json" >> /tmp/health.json
fi
fi