Check timesync

Script: check_timesync

check_timesync is a plugin to check if the time syncronisation is active.

Requirements

  • timedatectl
  • ntp deamon: systemd timesyncd or chronyd

Standalone installation

From this repository you need next to this script:

  • inc_pluginfunctions shared function for all IML checks written in bash

Syntax

Start the script with -h or --help to get the help.

______________________________________________________________________

CHECK_TIMESYNC
v1.5

(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3

https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_timesync.html
______________________________________________________________________

Check if time snychronisation is active.
It uses timedatectl and detects systemd timesyncd and chronyd.

SYNTAX:

  check_timesync [-h]

OPTIONS:

  -h or --help   show this help.

PARAMETERS:

  None.

Examples

No parameter is needed.

./check_timesync

returns

OK: timesync: a timesync service is active on this manjaro host
NTPSynchronized=yes

Timezone=Europe/Zurich
LocalRTC=no
CanNTP=yes
NTP=yes
NTPSynchronized=yes
TimeUSec=Wed 2025-02-19 15:58:54 CET
RTCTimeUSec=Wed 2025-02-19 15:58:55 CET

----- output of systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-02-19 08:40:28 CET; 7h ago
 Invocation: 46d0b3bfae1042e0b650fe8f993b5004
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 531 (systemd-timesyn)
     Status: "Contacted time server 185.54.81.25:123 (2.manjaro.pool.ntp.org)."
      Tasks: 2 (limit: 36694)
     Memory: 2.2M (peak: 3.4M)
        CPU: 117ms
     CGroup: /system.slice/systemd-timesyncd.service
             └─531 /usr/lib/systemd/systemd-timesyncd

Feb 19 08:40:28 axels-laptop systemd[1]: Started Network Time Synchronization.
Feb 19 08:40:29 axels-laptop systemd-timesyncd[531]: Network configuration changed, trying to establish connection.
Feb 19 08:40:29 axels-laptop systemd-timesyncd[531]: Network configuration changed, trying to establish connection.
Feb 19 08:40:29 axels-laptop systemd-timesyncd[531]: Network configuration changed, trying to establish connection.
Feb 19 08:40:29 axels-laptop systemd-timesyncd[531]: Network configuration changed, trying to establish connection.
Feb 19 08:40:30 axels-laptop systemd-timesyncd[531]: Network configuration changed, trying to establish connection.
Feb 19 08:40:30 axels-laptop systemd-timesyncd[531]: Network configuration changed, trying to establish connection.
Feb 19 08:40:30 axels-laptop systemd-timesyncd[531]: Network configuration changed, trying to establish connection.
Feb 19 08:41:00 axels-laptop systemd-timesyncd[531]: Contacted time server 185.54.81.25:123 (2.manjaro.pool.ntp.org).
Feb 19 08:41:00 axels-laptop systemd-timesyncd[531]: Initial clock synchronization to Wed 2025-02-19 08:41:00.942942 CET.