-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnagiosAlarm.sh
executable file
·66 lines (52 loc) · 1.44 KB
/
nagiosAlarm.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
tsNow=$(date +%s)
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
########################################
USAGE="Usage: $(basename $0) [-h] [-n nagios log] [-t time interval]\n
-n [FILE] Path to nagios log - zimbraSnapshot.log.\n
-t [INT] Time interval between executions.\n
Please use full paths!
"
if [ "$1" == "-h" ] || [ "$1" == "" ] || [ "$#" != 4 ]; then
echo -e $USAGE
exit $STATE_UNKNOWN
fi
while getopts n:t: option
do
case "${option}"
in
n) nagiosLog=${OPTARG};;
t) timeNotStartedTreshold=${OPTARG};;
esac
done
if [ ! -f $nagiosLog ]
then
echo "WARNING file not found $nagiosLog"
exit $STATE_CRITICAL
fi
log_last=$(tail -n 1 $nagiosLog)
log_date=$(echo $log_last | cut -d " " -f 1,2)
log_status=$(echo $log_last | cut -d " " -f 3)
log_action=$(echo $log_last | cut -d " " -f 4)
log_timestamp=$(date -d "$log_date" +%s)
date_ref=$(date -d "-$timeNotStartedTreshold hour" +%s)
if [[ $log_timestamp -lt $date_ref ]]
then
echo "WARNING last script execution was before $log_date"
exit $STATE_WARNING
fi
if [ $log_status = 'ERROR' ]
then
echo "WARNING backup script exitetd with ERRORS"
exit $STATE_WARNING
fi
if [ $log_action = 'RUN' ] && [[ $log_timestamp -gt $date_ref ]]
then
echo "OK backup script is running"
exit $STATE_OK
fi
echo "OK backup script finished correctly"
exit $STATE_OK