115 lines
3.6 KiB
Bash
Executable File
115 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
################################################################################
|
|
# BSD 3-Clause License
|
|
#
|
|
# Copyright © 2019 Aurélien Grimal - aurelien.grimal@tech-tips.fr
|
|
# All rights reserved.
|
|
#
|
|
# Please see license file on root of this directory
|
|
################################################################################
|
|
|
|
# !! GIT FILE !!
|
|
# https://framagit.org/zorval/scripts/check-nrpe
|
|
|
|
################################################################################
|
|
|
|
WARNING_SECONDS=0.5
|
|
CRITICAL_SECONDS=5
|
|
|
|
VAR_FILE=/etc/zorval/env_check_chrony
|
|
[ -f $VAR_FILE ] && source $VAR_FILE
|
|
|
|
DEBUG=${DEBUG:false}
|
|
|
|
cmd="chronyc -c tracking"
|
|
CHRONYC_TRACKING=$($cmd)
|
|
RC=$?
|
|
|
|
if [ $RC -ne 0 ]; then
|
|
echo "[CRITICAL] Le code retour de '$cmd' vaut $RC !"
|
|
exit 2
|
|
fi
|
|
|
|
cmd="chronyc -c sources"
|
|
CHRONYC_SOURCES=$($cmd)
|
|
RC=$?
|
|
|
|
if [ $RC -ne 0 ]; then
|
|
echo "[CRITICAL] Le code retour de '$cmd' vaut $RC !"
|
|
exit 2
|
|
fi
|
|
|
|
if echo "$CHRONYC_SOURCES" | grep -q ',\*,'; then
|
|
CHRONYC_SOURCES=$(echo "$CHRONYC_SOURCES" | grep ',\*,')
|
|
else
|
|
CHRONYC_SOURCES=$(echo "$CHRONYC_SOURCES" | head -n 1)
|
|
fi
|
|
|
|
read -r Reference_ID Reference_IP Stratum Ref_time System_time Last_offset RMS_offset \
|
|
Frequency Residual_freq Skew Root_delay Root_dispersion Update_interval Leap_status \
|
|
<<< $(echo "$CHRONYC_TRACKING" | sed 's/,/ /g')
|
|
|
|
read -r Source_mode Source_state Name_or_IP_address Stratum Poll Reach LastRx \
|
|
Last_sample_adjusted_offset Last_sample_measured_offset Last_sample_estimated_error \
|
|
<<< $(echo "$CHRONYC_SOURCES" | sed 's/,/ /g')
|
|
|
|
if [ "$DEBUG" = true ]; then
|
|
echo "================="
|
|
echo "CHRONYC_TRACKING=$CHRONYC_TRACKING"
|
|
echo "================="
|
|
echo "Reference_ID=$Reference_ID"
|
|
echo "Reference_IP=$Reference_IP"
|
|
echo "Stratum=$Stratum"
|
|
echo "Ref_time=$Ref_time"
|
|
echo "System_time=$System_time"
|
|
echo "Last_offset=$Last_offset"
|
|
echo "RMS_offset=$RMS_offset"
|
|
echo "Frequency=$Frequency"
|
|
echo "Residual_freq=$Residual_freq"
|
|
echo "Skew=$Skew"
|
|
echo "Root_delay=$Root_delay"
|
|
echo "Root_dispersion=$Root_dispersion"
|
|
echo "Update_interval=$Update_interval"
|
|
echo "Leap_status=$Leap_status"
|
|
echo "================"
|
|
echo "CHRONYC_SOURCES=$CHRONYC_SOURCES"
|
|
echo "================"
|
|
echo "Source_mode=$Source_mode"
|
|
echo "Source_state=$Source_state"
|
|
echo "Name_or_IP_address=$Name_or_IP_address"
|
|
echo "Stratum=$Stratum"
|
|
echo "Poll=$Poll"
|
|
echo "Reach=$Reach"
|
|
echo "LastRx=$LastRx"
|
|
echo "Last_sample_adjusted_offset=$Last_sample_adjusted_offset"
|
|
echo "Last_sample_measured_offset=$Last_sample_measured_offset"
|
|
echo "Last_sample_estimated_error=$Last_sample_estimated_error"
|
|
fi
|
|
|
|
if [ "$Leap_status" != Normal ]; then
|
|
echo "[CRITICAL] Leap status vaut '$Leap_status' au lieu de 'Normal' !"
|
|
exit 2
|
|
fi
|
|
|
|
if [ "$Source_mode" != '^' ]; then
|
|
echo "[CRITICAL] Source mode vaut '$Source_mode' au lieu de '^' !"
|
|
exit 2
|
|
fi
|
|
|
|
if [ "$Source_state" != '*' ]; then
|
|
echo "[CRITICAL] Source state vaut '$Source_state' au lieu de '*' !"
|
|
exit 2
|
|
fi
|
|
|
|
if (( $(echo "$System_time > $CRITICAL_SECONDS" | bc -l) )) || (( $(echo "$System_time < -$CRITICAL_SECONDS" | bc -l) )); then
|
|
echo "[CRITICAL] Ce serveur a un décalage de $System_time secondes avec le serveur NTP !"
|
|
exit 2
|
|
elif (( $(echo "$System_time > $WARNING_SECONDS" | bc -l) )) || (( $(echo "$System_time < -$WARNING_SECONDS" | bc -l) )); then
|
|
echo "[WARNING] Ce serveur a un décalage de $System_time secondes avec le serveur NTP !"
|
|
exit 1
|
|
else
|
|
echo "[OK] Ce serveur a un décalage de $System_time secondes avec le serveur NTP"
|
|
exit 0
|
|
fi
|