Skip to content

Commit

Permalink
ntp-ntpd: Fixed unpacking of ntpq -p values (#758)
Browse files Browse the repository at this point in the history
When the chosen ntp Server (maked by *) has one or more whitespaces in its name, the original parsing fails with too many values to unpack.
Example:
'*185.232.69.65 ( 79.133.44.146    2 u  139  256  377    0.401    0.133   0.137'

peer, refid, stratum, _type, when, poll, reach, delay, offset, jitter = line[1:].split()
ValueError: too many values to unpack (expected 10)
  • Loading branch information
leo-pempera authored May 3, 2024
1 parent c0776c2 commit 675f4ba
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions check-plugins/ntp-ntpd/ntp-ntpd
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,14 @@ def main():
peer_used = True
try:
# line of peer in the form [tally]remote refid st t when pool reach delay offset jitter
peer, refid, stratum, _type, when, poll, reach, delay, offset, jitter = line[1:].split() # remove '*' and split
offset = float(offset)
stratum = int(stratum)
split_line = line[1:].split()

# Get numeric values via negativ index as there might be multiple whitespaces in remote
peer = split_line[0]
stratum = int(split_line[-8])
delay = split_line[-3]
offset = float(split_line[-2])
jitter = split_line[-1]
except:
pass

Expand Down

0 comments on commit 675f4ba

Please sign in to comment.