-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_mongo_replication_time_diff
46 lines (37 loc) · 1.42 KB
/
check_mongo_replication_time_diff
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
#!/bin/bash
# local check for the oplog age.
# A locally modified version of check_mongodb.py can also output this data
# If you do that, don't use this script, and instead add the 'oplog' check to MRPE
# for creds
MONGO_AUTH_FILE=/root/.mongorc.js
# use github repo version
NAGIOS_PLUGIN_SCRIPT=/root/nagios-plugin-mongodb/check_mongodb.py
# can use the host from rs.status() here but is not required
MONGO_ADDRESS=localhost
mongouser=$(grep db.auth $MONGO_AUTH_FILE |cut -f2 -d "'")
mongopass=$(grep db.auth $MONGO_AUTH_FILE |cut -f4 -d "'")
NAGIOS_OPTIONS="-u $mongouser -p $mongopass -H $MONGO_ADDRESS -D"
#NAGIOS_OPTIONS="-H $MONGO_ADDRESS"
timeDiffHoursOut=$(mongo /root/getReplInfo.js |grep timeDiffHours|cut -f3 -d ' '|cut -f1 -d ',')
timeDiffHours=$(mongo /root/getReplInfo.js |grep timeDiffHours|cut -f3 -d ' '|cut -f1 -d '.' | cut -f1 -d ',')
cmdStatus=$?
timeDiffHoursState=3
timeDiffHoursTxt='UNKNOWN'
timeDiffWarn=192
timeDiffCrit=24
if (( $timeDiffHours < $timeDiffWarn ))
then
timeDiffHoursState=1
timeDiffHoursTxt='WARNING'
fi
if (( $timeDiffHours < $timeDiffCrit ))
then
timeDiffHoursState=2
timeDiffHoursTxt='CRITICAL'
fi
if (( $timeDiffHours > $timeDiffWarn - 1))
then
timeDiffHoursState=0
timeDiffHoursTxt='OK'
fi
echo "$timeDiffHoursState mongo_replication_time_diff timeDiffHours=$timeDiffHours;$timeDiffWarn;$timeDiffCrit; $timeDiffHoursTxt replication time difference is $timeDiffHours hours"