Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
43f6d6c3
Commit
43f6d6c3
authored
1 month ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
timesync: add help page and doc page
parent
13d0fa56
No related branches found
Branches containing commit
No related tags found
1 merge request
!298
timesync: add help page and doc page
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
check_timesync
+54
-23
54 additions, 23 deletions
check_timesync
docs/20_Checks/_index.md
+1
-1
1 addition, 1 deletion
docs/20_Checks/_index.md
docs/20_Checks/check_timesync.md
+95
-0
95 additions, 0 deletions
docs/20_Checks/check_timesync.md
with
150 additions
and
24 deletions
check_timesync
+
54
−
23
View file @
43f6d6c3
...
...
@@ -15,40 +15,74 @@
# 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-05-13 v1.2 <axel.hahn@iml.unibe.ch> update pre detect output of timedatectl
# 2021-08-19 v1.3 <martin.gasser@iml.unibe.ch> update for chrony with timedatectl
# 2025-02-19 v1.4 <axel.hahn@unibe.ch> update help page
# ======================================================================
.
`
dirname
$0
`
/inc_pluginfunctions
myos
=
`
ph.getOS
`
.
$(
dirname
$0
)
/inc_pluginfunctions
self_APPVERSION
=
1.4
myos
=
"
$(
ph.getOS
)
"
tmpfile
=
/tmp/check_timesync.tmp
# ----------------------------------------------------------------------
#
pre check if timedatectl is available
#
functions
# ----------------------------------------------------------------------
which timedatectl
>
/dev/null
if
[
$?
-ne
0
]
;
then
ph.abort
"timesync UNKNOWN: timedatectl was not found ... maybe your OS
${
myos
}
is not supported"
# show help text
function
showHelp
(){
local
_self
;
_self
=
$(
basename
$0
)
cat
<<
EOF
$(
ph.showImlHelpHeader
)
Check if time snychronisation is active.
It uses timedatectl and detects systemd timesyncd and chronyd.
SYNTAX:
$_self
[-h]
OPTIONS:
-h or --help show this help.
PARAMETERS:
None.
EOF
}
# ----------------------------------------------------------------------
# check params
# ----------------------------------------------------------------------
if
[
"
$1
"
=
"-h"
]
||
[
"
$1
"
=
"--help"
]
;
then
showHelp
exit
0
;
fi
if
[
-n
"
$*
"
]
;
then
echo
"ERROR: no parameter expected."
exit
1
fi
# ----------------------------------------------------------------------
# check output of timedatectl command
# ----------------------------------------------------------------------
# ph.execIfReady "timedatectl status | grep '^NTP synchronized'" >/dev/null
# echo ----- output of timedatectl status >$tmpfile
# timedatectl status >>$tmpfile
ph.require
"timedatectl"
ph.execIfReady
"timedatectl show >
$tmpfile
; grep '^NTPSynchronized'
$tmpfile
>/dev/null"
cat
$tmpfile
|
grep
"^NTPSynchronized"
>
/dev/null
if
[
$?
-ne
0
]
;
then
if
!
cat
$tmpfile
|
grep
"^NTPSynchronized"
>
/dev/null
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
"^NTPSynchronized=yes"
>
/dev/null
if
[
$?
-eq
0
]
;
then
if
cat
$tmpfile
|
grep
"^NTPSynchronized=yes"
>
/dev/null
then
ph.status
"timesync: a timesync service is active on this
${
myos
}
host"
else
ph.setStatus
"critical"
...
...
@@ -60,17 +94,14 @@ fi
# ----------------------------------------------------------------------
# detect sync service and show its output
# ----------------------------------------------------------------------
echo
>>
$tmpfile
sSyncService
=
if
[
-f
/etc/systemd/timesyncd.conf
]
;
then
sSyncService
=
"systemd-timesyncd"
fi
if
[
-f
/etc/chrony.conf
]
;
then
sSyncService
=
"chronyd"
fi
if
[
-f
/etc/chrony/chrony.conf
]
;
then
sSyncService
=
"chronyd"
fi
test
-f
/etc/systemd/timesyncd.conf
&&
sSyncService
=
"systemd-timesyncd"
test
-f
/etc/chrony.conf
&&
sSyncService
=
"chronyd"
test
-f
/etc/chrony/chrony.conf
&&
sSyncService
=
"chronyd"
if
[
-z
$sSyncService
]
;
then
echo
"REMARK: no sync service detected ... or this sensu check does not support it"
>>
$tmpfile
else
...
...
This diff is collapsed.
Click to expand it.
docs/20_Checks/_index.md
+
1
−
1
View file @
43f6d6c3
...
...
@@ -51,6 +51,6 @@
*
[
check_ssl_certs
](
check_ssl_certs.md
)
*
check_systemdservices
*
[
check_systemdunit
](
check_systemdunit.md
)
*
check_timesync
*
[
check_timesync
](
check_timesync.md
)
*
check_uptime
*
hello
This diff is collapsed.
Click to expand it.
docs/20_Checks/check_timesync.md
0 → 100644
+
95
−
0
View file @
43f6d6c3
## 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 ypu 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.
```
txt
______________________________________________________________________
CHECK_TIMESYNC
v1.4
(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
```
txt
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.
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment