Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_ntp_server_sync
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
This super simple script checks the synchronization with the time server. Specifies the IP server to which you are synchronized and offset. Requires ntpq. It does not require any parameter. When you start it you should get:
someone@linuxhost:~# ./check_ntp_server_sync.sh
Synchronized with the server: 91.189.89.199 offset: 0.073
or
someone@linuxhost:~# ./check_ntp_server_sync.sh
No synchronization with the time server
someone@linuxhost:~# ./check_ntp_server_sync.sh
Synchronized with the server: 91.189.89.199 offset: 0.073
or
someone@linuxhost:~# ./check_ntp_server_sync.sh
No synchronization with the time server
Reviews (1)
byfmdupre, October 29, 2014
I changed the pluguin to be perfdata:
Now
- It returns 0 if the peer has been declared the system peer and lends its variables to the system variables.
- It returns 1 if the peer is a survivor, but not among the first six peers sorted by synchronization distance.
If the association is ephemeral, it may be demobilized to conserve resources.
- If it returns 2 if the peer is discarded as unreachable, synchronized to this server (synch loop) or outrageous synchronization distance.
#!/bin/sh
#
# michaszek@o2.pl
# Checks if the ntp service synchronises to the server time, gives ntp server IP and offset.
# Tested on Ubuntu 12.04.
/usr/sbin/ntpq -p | tail -1 | cut -c 1 >/tmp/check_ntp_server_sync.tmp
ETAT="$(cat /tmp/check_ntp_server_sync.tmp | cut -c 1)"
if [ "${ETAT}" == "*" ]
then
retour_nagios=0
fi
if [ "${ETAT}" == "#" ]
then
retour_nagios=1
fi
if [ "${ETAT}" == " " ]
then
retour_nagios=2
fi
HOST=$(/usr/sbin/ntpq -pn | tail -1 | awk '{print $1}' | cut -c 2-)
COMMAND=$(/usr/sbin/ntpq -pn | grep -F '*' | awk '{print $1}' | cut -d "*" -f 2)
OFFSET=$(/usr/sbin/ntpq -pn | tail -1 | awk '{print $9}')
if [ -z "$COMMAND" ]
then
echo "No synchronization with the time server : ${HOST} offset: ${OFFSET}; | Offset=${OFFSET}s;;"
exit ${retour_nagios}
else
echo "Synchronized with the time server : ${HOST} offset: ${OFFSET} | Offset=${OFFSET}s;;"
exit ${retour_nagios}
fi
Now
- It returns 0 if the peer has been declared the system peer and lends its variables to the system variables.
- It returns 1 if the peer is a survivor, but not among the first six peers sorted by synchronization distance.
If the association is ephemeral, it may be demobilized to conserve resources.
- If it returns 2 if the peer is discarded as unreachable, synchronized to this server (synch loop) or outrageous synchronization distance.
#!/bin/sh
#
# michaszek@o2.pl
# Checks if the ntp service synchronises to the server time, gives ntp server IP and offset.
# Tested on Ubuntu 12.04.
/usr/sbin/ntpq -p | tail -1 | cut -c 1 >/tmp/check_ntp_server_sync.tmp
ETAT="$(cat /tmp/check_ntp_server_sync.tmp | cut -c 1)"
if [ "${ETAT}" == "*" ]
then
retour_nagios=0
fi
if [ "${ETAT}" == "#" ]
then
retour_nagios=1
fi
if [ "${ETAT}" == " " ]
then
retour_nagios=2
fi
HOST=$(/usr/sbin/ntpq -pn | tail -1 | awk '{print $1}' | cut -c 2-)
COMMAND=$(/usr/sbin/ntpq -pn | grep -F '*' | awk '{print $1}' | cut -d "*" -f 2)
OFFSET=$(/usr/sbin/ntpq -pn | tail -1 | awk '{print $9}')
if [ -z "$COMMAND" ]
then
echo "No synchronization with the time server : ${HOST} offset: ${OFFSET}; | Offset=${OFFSET}s;;"
exit ${retour_nagios}
else
echo "Synchronized with the time server : ${HOST} offset: ${OFFSET} | Offset=${OFFSET}s;;"
exit ${retour_nagios}
fi
Owner's reply
Sup! Great idea!