diff --git a/CHANGELOG.md b/CHANGELOG.md index 635cb6c06..eb43bee59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ Monitoring Plugins: * about-me: Throws exception for openvas ([#749](https://github.com/Linuxfabrik/monitoring-plugins/issues/749)) * infomaniak-events: Fix `UnboundLocalError: local variable 'keys' referenced before assignment` * nextcloud-stats: KeyError: apps ([#731](https://github.com/Linuxfabrik/monitoring-plugins/issues/731)) +* ntp-ntpd: Fixed unpacking of ntpq -p values ([PR #758](https://github.com/Linuxfabrik/monitoring-plugins/pull/758), thanks to [Leo Pempera](https://github.com/leo-pempera)) * ntp-w32tm: Fix `UnboundLocalError: local variable 'clock_rate' referenced before assignment` diff --git a/check-plugins/ntp-ntpd/ntp-ntpd b/check-plugins/ntp-ntpd/ntp-ntpd index fe7224506..f00a63537 100755 --- a/check-plugins/ntp-ntpd/ntp-ntpd +++ b/check-plugins/ntp-ntpd/ntp-ntpd @@ -23,7 +23,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413 STATE_UNKNOWN, STATE_WARN) __author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' -__version__ = '2023112901' +__version__ = '2024050301' DESCRIPTION = '''This plugin checks the clock offset of ntpd in milliseconds compared to ntp servers.''' @@ -102,9 +102,9 @@ def main(): peer_used = True try: # line of peer in the form [tally]remote refid st t when pool reach delay offset jitter - split_line = line[1:].split() + split_line = line[1:].split() # remove '*' and split - # Get numeric values via negativ index as there might be multiple whitespaces in remote + # get numeric values via negative index as there might be multiple whitespaces in remote peer = split_line[0] stratum = int(split_line[-8]) delay = split_line[-3] @@ -113,6 +113,10 @@ def main(): except: pass + try: + offset + except: + lib.base.oao('No NTP server used.', STATE_WARN) if not peer_used: lib.base.oao('No NTP server used.', STATE_WARN) if peer == '': diff --git a/check-plugins/ntp-ntpd/unit-test/run b/check-plugins/ntp-ntpd/unit-test/run index acef44f11..d8899868d 100755 --- a/check-plugins/ntp-ntpd/unit-test/run +++ b/check-plugins/ntp-ntpd/unit-test/run @@ -45,7 +45,7 @@ class TestCheck(unittest.TestCase): def test_if_check_runs_EXAMPLE03(self): stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --test=stdout/EXAMPLE03,,0')) - self.assertIn('No NTP server found.', stdout) + self.assertIn('No NTP server used.', stdout) self.assertEqual(stderr, '') self.assertEqual(retc, STATE_WARN) @@ -55,6 +55,15 @@ class TestCheck(unittest.TestCase): self.assertEqual(stderr, '') self.assertEqual(retc, STATE_WARN) + def test_if_check_runs_EXAMPLE05(self): + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --test=stdout/EXAMPLE05,,0')) + self.assertIn('NTP offset is -0.182ms, Stratum is 2', stdout) + self.assertIn('remote refid st t when poll reach delay offset jitter', stdout) + self.assertIn('==============================================================================', stdout) + self.assertIn('*185.232.69.65 ( 79.133.44.146 2 u 232 256 377 0.398 -0.182 0.170', stdout) + self.assertEqual(stderr, '') + self.assertEqual(retc, STATE_OK) + if __name__ == '__main__': unittest.main() diff --git a/check-plugins/ntp-ntpd/unit-test/stdout/EXAMPLE05 b/check-plugins/ntp-ntpd/unit-test/stdout/EXAMPLE05 new file mode 100644 index 000000000..73197533a --- /dev/null +++ b/check-plugins/ntp-ntpd/unit-test/stdout/EXAMPLE05 @@ -0,0 +1,12 @@ + remote refid st t when poll reach delay offset jitter +============================================================================== + 0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 + 1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 + 2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 + 3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 + ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000 ++mail.gunnarhofm 192.53.103.103 2 u 110 256 377 2.793 -0.228 0.157 +-gps.s-buettgen. 131.188.3.222 2 u 164 256 377 3.311 0.129 0.534 ++ntp1.kashra-ser 192.168.100.15 2 u 174 256 377 13.709 -0.834 0.278 +-47.ip-51-75-67. 17.253.14.251 2 u 156 256 217 4.930 -0.049 0.111 +*185.232.69.65 ( 79.133.44.146 2 u 232 256 377 0.398 -0.182 0.170 \ No newline at end of file