Checks:
1) If NTP server is synchronised or unsynchronised
2) If NTP server is synchronised to an acceptable time level in ms
Below is an image showing example output into mmonit for status coming from the NTP server via the bash script:
ntpsync.sh
Code: Select all
#!/bin/bash
# Configuration
timeaccuracy="200" # Level of accuracy in ms before alert
# Get output
output=$(/usr/bin/ntpstat)
outputrawms=$(echo "$output" | grep -Eo '\w+ ms' | awk '{ print $1 }')
# If NTP server is unsynchronised exit and display error
if [[ $output == *"unsynchronised"* ]]; then
echo "$output"
exit 1
fi
# If NTP server is synchronised within acceptable ms display data and exit
if (( $outputrawms < "$timeaccuracy" )); then
echo "$output"
exit 0
fi
# If NTP server is synchronised output acceptable ms display message and exit
if (( $outputrawms >= "$timeaccuracy" )); then
echo -e "Time accuracy is outside acceptable range of less than $timeaccuracy ms, output:\n$output" >&2
exit 1
fi
Code: Select all
# Check if NTP is synchronised
check program ntp_synchronisation with path "/etc/monit/customscripts/ntpsync.sh"
with timeout 5 seconds
if status != 0 then alert