also check if NTP is enabled
authorPeter Palfrader <peter@palfrader.org>
Fri, 9 Dec 2016 10:31:26 +0000 (11:31 +0100)
committerPeter Palfrader <peter@palfrader.org>
Fri, 9 Dec 2016 10:31:26 +0000 (11:31 +0100)
dsa-nagios-checks/checks/dsa-check-timedatectl

index 88c1771..700d857 100755 (executable)
@@ -31,8 +31,8 @@ temp="$(mktemp)"
 trap "rm -f '$temp'" EXIT
 
 timedatectl > "$temp"
-ut=$(sed '/Universal time:/ { s/^[^:]*: *//; p}; d' t)
-rtc=$(sed '/RTC time:/ { s/^[^:]*: *//; p}; d' t)
+ut=$(sed '/Universal time:/ { s/^[^:]*: *//; p}; d' "$temp")
+rtc=$(sed '/RTC time:/ { s/^[^:]*: *//; p}; d' "$temp")
 
 uts=$(date -d "$ut" +%s)
 rtcs=$(date -d "$rtc" +%s)
@@ -46,8 +46,14 @@ if [ "$d" -lt "-$MAX" ] ||
 fi
 
 
-sced=$(sed '/NTP synchronized:/ { s/^[^:]*: *//; p}; d' t)
-if [ "$sced" != "yes" ]; then
+bool=$(sed '/NTP enabled:/ { s/^[^:]*: *//; p}; d' "$temp")
+if [ "$bool" != "yes" ]; then
+       echo "Warning: NTP not enabled!"
+       exit 1
+fi
+
+bool=$(sed '/NTP synchronized:/ { s/^[^:]*: *//; p}; d' "$temp")
+if [ "$bool" != "yes" ]; then
        echo "Warning: not synced with NTP (but clock is OK for now)."
        exit 1
 fi