Skip to content

Commit

Permalink
Merge pull request mej#6 from itkovian/check-chrony
Browse files Browse the repository at this point in the history
Check chrony
  • Loading branch information
wdpypere authored Oct 26, 2020
2 parents 233d217 + 72f1015 commit 573e997
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion nhc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@
###
### Check that the time has not drifted too much.
### Only actually checks if the env var is defined (in /etc/sysconfig/nhc)
* || [ ! -z "${NHC_PTPD_STATUS+x}" ] && check_ptpd_drift
* || if [ ! -z "${NHC_PTPD_STATUS+x}" ]; then check_ptpd_drift; fi
* || if [ ! -z "${NHC_CHRONYC_MAX_DRIFT+x}" ]; then check_chrony_drift; fi

#######################################################################
###
Expand Down
32 changes: 32 additions & 0 deletions scripts/lbnl_time.nhc
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,35 @@ function check_ptpd_drift() {
return 0
}

function check_chrony_drift() {
local DRIFT=0

DRIFT=$(chronyc tracking | grep "Last offset *:" | tr -s " " | cut -d" " -f5 | sed 's/^[-+]//')
dbg "$FUNCNAME: drift is $DRIFT"

if [ -z "${DRIFT}" ]; then
dbg "Could not find drift line, sleeping 5 seconds"
sleep 5

DRIFT=$(chronyc tracking | grep "Last offset *:" | tr -s " " | cut -d" " -f5 | sed 's/^[-+]//')
dbg "$FUNCNAME: drift is $DRIFT"

if [ -z "${DRIFT}" ]; then
die 1 "$FUNCNAME: No drift line found in chronyc output after 5 second sleep"
return 1
fi
fi

if (( $(echo "${DRIFT#-} > $NHC_CHRONYC_MAX_DRIFT " | bc -l) )); then
die 1 "$FUNCNAME: CHRONY drift too high: ${DRIFT} with threshold $NHC_CHRONYC_MAX_DRIFT"
return 1
fi

return 0


}




3 changes: 2 additions & 1 deletion test/test_lbnl_time.nhc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Tests for lbnl_time.nhc

plan $((1)) "lbnl_fs.nhc" && {
plan 2 "lbnl_time.nhc" && {
is "`type -t check_ptpd_drift 2>&1`" 'function' 'check_ptpd_drift() loaded properly'
is "`type -t check_chrony_drift 2>&1`" 'function' 'check_chrony_drift() loaded properly'

local OLD_SHELL="$SHELL"
SHELL=:
Expand Down

0 comments on commit 573e997

Please sign in to comment.