From 57a3ec7eaa99fafb7b92b1f935a075c9f750c455 Mon Sep 17 00:00:00 2001
From: Martin <martin.gasser@protonmail.com>
Date: Thu, 19 Aug 2021 16:12:18 +0200
Subject: [PATCH] check_timesync for centos8

---
 check_timesync | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/check_timesync b/check_timesync
index 4ac54f8..3c22b2f 100755
--- a/check_timesync
+++ b/check_timesync
@@ -36,16 +36,16 @@ fi
 # ph.execIfReady "timedatectl status | grep '^NTP synchronized'" >/dev/null
 # echo ----- output of timedatectl status >$tmpfile
 # timedatectl status >>$tmpfile
-ph.execIfReady "timedatectl status >$tmpfile; grep '^NTP synchronized' $tmpfile >/dev/null"
+ph.execIfReady "timedatectl show >$tmpfile; grep '^NTPSynchronized' $tmpfile >/dev/null"
 
-cat $tmpfile | grep "^NTP synchronized" >/dev/null
+cat $tmpfile | grep "^NTPSynchronized" >/dev/null
 if [ $? -ne 0 ]; then
   ph.setStatus "unknown"
   # ph.status "timesync: timedatectl has no line NTP synchronized ... maybe your OS ${myos} is not supported"
   ph.status "timesync: timedatectl has no line NTP synchronized"
   cat $tmpfile
 else
-  cat $tmpfile | grep "^NTP synchronized: yes" >/dev/null
+  cat $tmpfile | grep "^NTPSynchronized=yes" >/dev/null
   if [ $? -eq 0 ]; then
     ph.status "timesync: a timesync service is active on this ${myos} host"
   else
@@ -66,6 +66,9 @@ fi
 if [ -f /etc/chrony.conf ]; then
   sSyncService="chronyd"
 fi
+if [ -f /etc/chrony/chrony.conf ]; then
+  sSyncService="chronyd"
+fi
 if [ -z $sSyncService ]; then
   echo "REMARK: no sync service detected ... or this sensu check does not support it" >>$tmpfile
 else
@@ -78,7 +81,7 @@ fi
 # output & exit
 # ----------------------------------------------------------------------
 
-cat $tmpfile | grep "^NTP synchronized"
+cat $tmpfile | grep "^NTPSynchronized"
 echo
 cat $tmpfile
 
@@ -86,4 +89,4 @@ rm -f $tmpfile
 
 ph.exit
 
-# ----------------------------------------------------------------------
+# ----------------------------------------------------------------------
\ No newline at end of file
-- 
GitLab