dsa-check-timedatectl: buster adaptions
authorPeter Palfrader <peter@palfrader.org>
Wed, 8 May 2019 09:06:44 +0000 (11:06 +0200)
committerPeter Palfrader <peter@palfrader.org>
Wed, 8 May 2019 09:06:53 +0000 (11:06 +0200)
dsa-nagios-checks/checks/dsa-check-timedatectl
dsa-nagios-checks/debian/changelog

index 4bb6247..bc97862 100755 (executable)
@@ -61,11 +61,32 @@ fi
 temp="$(mktemp)"
 trap "rm -f '$temp'" EXIT
 
-LC_ALL=C timedatectl > "$temp"
-ut=$(sed '/Universal time:/ { s/^[^:]*: *//; p}; d' "$temp")
-rtc=$(sed '/RTC time:/ { s/^[^:]*: *//; p}; d' "$temp")
-ntpenabled=$(sed '/\(NTP enabled\|Network time on\|NTP service\):/ { s/^[^:]*: *//; p}; d' "$temp")
-ntpsynced=$(sed '/\(NTP synchronized\|System clock synchronized\):/ { s/^[^:]*: *//; p}; d' "$temp")
+systemdversion="$(timedatectl --version | head -n1 | awk '{print $2}')"
+if [ -z "$systemdversion" ]; then
+       echo "Unknown: Cannot get systemd version"
+       exit 3
+fi
+if [ "$systemdversion" -lt 241 ] ; then # before buster (Debian 10)
+       LC_ALL=C timedatectl > "$temp"
+       ut=$(sed '/Universal time:/ { s/^[^:]*: *//; p}; d' "$temp")
+       rtc=$(sed '/RTC time:/ { s/^[^:]*: *//; p}; d' "$temp")
+       ntpenabled=$(sed '/\(NTP enabled\|Network time on\|NTP service\):/ { s/^[^:]*: *//; p}; d' "$temp")
+       ntpsynced=$(sed '/\(NTP synchronized\|System clock synchronized\):/ { s/^[^:]*: *//; p}; d' "$temp")
+else
+       LC_ALL=C timedatectl show > "$temp"
+       ut=$(sed '/^TimeUSec=/ { s/^[^=]*=//; p}; d' "$temp")
+       rtc=$(sed '/^RTCTimeUSec=/ { s/^[^=]*=//; p}; d' "$temp")
+       ntpenabled=$(sed '/^NTP=/ { s/^[^=]*=//; p}; d' "$temp")
+       ntpsynced=$(sed '/^NTPSynchronized=/ { s/^[^=]*=//; p}; d' "$temp")
+       if [ "$ntpenabled" = "no" ]; then # in buster (Debian 10) ntpenabled no longer also considers the ntp service
+               ntp_status=$(systemctl is-enabled 'ntp.service' 2>/dev/null) && rc=$? || rc=$?
+               if [ "$rc" = 0 ] && [ "$ntp_status" = "enabled" ] ; then
+                       if systemctl --quiet is-active ntp.service; then
+                               ntpenabled=yes
+                       fi
+               fi
+       fi
+fi
 
 uts=$(TZ=UTC date -d "$ut" +%s)
 rtcs=$(TZ=UTC date -d "$rtc" +%s 2>/dev/null || echo "N/A")
index 6e48599..703fece 100644 (file)
@@ -1,7 +1,14 @@
 dsa-nagios-checks (118) UNRELEASED; urgency=medium
 
+  [ Aurelien Jarno ]
   * 
 
+  [ Peter Palfrader ]
+  * dsa-check-timedatectl:
+    - in buster, timedatectl no longer considers the ntp status of
+      the ntp.service.  So we manually do that now.
+    - also switch to parsing the machine readable output in buster.
+
  -- Aurelien Jarno <aurel32@debian.org>  Mon, 01 Apr 2019 10:09:25 +0200
 
 dsa-nagios-checks (117) unstable; urgency=medium