-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfluence_montior_apache.sh
66 lines (50 loc) · 1.77 KB
/
confluence_montior_apache.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
#!/bin/bash
#date: 8/25/2020
#author: Theodore Knab
#filename: confluence_montior_apache.sh
#description: simple monitoring script for apache error logs and restart when failure is logged
monitoring_time=10 #monitoring interval
apache_log="/var/log/httpd/error_log " #apache log to monitor
regex_search_string="The timeout specified has expired: AH01030: ajp_ilink_receive"
services="httpd confluence"
#while list_of_minutes
#start_of_monitoring_time
echo "pysdo code:"
echo "...generate a list of time step through the logs (complete)"
echo "...parse logs using list times (complete)"
echo "...if any matches of desired exsit restart services (complete)"
restart_services() {
for service in services
do
echo stopping $service
systemctl stop $service
echo starting $service
systemctl start $service
done
exit 0 #only one restart
}
counter=1
let monitoring_time=monitoring_time+1
#this loop does a count backwards to target time
#if there on any matches it restarts the services
#if nothing is found it exits with no problem found output
echo "...generate a list of times step through the logs"
while [ $monitoring_time -ne $counter ];
do
time_to_check=$(date -d "now - $counter minutes" +"%a %h %d %H:%M")
#check for log entry at this time
log_hits=$(grep -i "$time_to_check" $apache_log)
#if not empty move on
if [[ ! -z $log_hits ]]; then
#if non empty string is equal to our regex_search_string then restart services
if [[ $log_hits =~ "$regex_search_string" ]]; then
echo $counter: $time_to_check
echo $log_hits
echo "match found restart services"
restart_services
fi
fi
let counter=counter+1
done
echo "no problems found... nothing was restarted"
#count backwards in time