From eca24ed5ed13af0724c8e6f9482bc446cf0b950b Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 8 May 2019 11:06:44 +0200 Subject: [PATCH] dsa-check-timedatectl: buster adaptions --- .../checks/dsa-check-timedatectl | 31 ++++++++++++++++--- dsa-nagios-checks/debian/changelog | 7 +++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/dsa-nagios-checks/checks/dsa-check-timedatectl b/dsa-nagios-checks/checks/dsa-check-timedatectl index 4bb6247..bc97862 100755 --- a/dsa-nagios-checks/checks/dsa-check-timedatectl +++ b/dsa-nagios-checks/checks/dsa-check-timedatectl @@ -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") diff --git a/dsa-nagios-checks/debian/changelog b/dsa-nagios-checks/debian/changelog index 6e48599..703fece 100644 --- a/dsa-nagios-checks/debian/changelog +++ b/dsa-nagios-checks/debian/changelog @@ -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 Mon, 01 Apr 2019 10:09:25 +0200 dsa-nagios-checks (117) unstable; urgency=medium -- 2.20.1