check_ntpmon.py tries to divide by 0 if there is no peer in sync

Bug #1441704 reported by Junien Fridrick
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
ntp (Juju Charms Collection)
Fix Released
Medium
Paul Gear

Bug Description

$ sudo ntpq -pn
     remote refid st t when poll reach delay offset jitter
==============================================================================
 10.35.60.40 .INIT. 16 u 505 1024 0 0.000 0.000 0.000
 10.35.60.41 .INIT. 16 u 471 1024 0 0.000 0.000 0.000

$ sudo /usr/local/lib/nagios/plugins/check_ntpmon.py --check sync
Traceback (most recent call last):
  File "/usr/local/lib/nagios/plugins/check_ntpmon.py", line 360, in <module>
    main()
  File "/usr/local/lib/nagios/plugins/check_ntpmon.py", line 337, in main
    ntp = NTPPeers(lines, checkntpmon)
  File "/usr/local/lib/nagios/plugins/check_ntpmon.py", line 214, in __init__
    self.ntpdata['reachability'] = float(self.ntpdata['totalreach']) * 100 / self.ntpdata['peers'] / 8
ZeroDivisionError: float division by zero

Related branches

Revision history for this message
Nick Moffitt (nick-moffitt) wrote :

We've got a float to start with, so we could probably just add sys.float_info.epsilon to that peers number.

Paul Gear (paulgear)
Changed in ntp (Juju Charms Collection):
assignee: nobody → Paul Gear (paulgear)
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Paul Gear (paulgear) wrote :

Committed fixed version of check_ntpmon.py to upstream repo (https://github.com/paulgear/ntpmon). The update includes new tests which ensure that the demo data (including this example, newly-added) is parsed correctly.

Paul Gear (paulgear)
Changed in ntp (Juju Charms Collection):
status: Confirmed → Fix Committed
Paul Gear (paulgear)
Changed in ntp (Juju Charms Collection):
importance: High → Medium
Paul Gear (paulgear)
Changed in ntp (Juju Charms Collection):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.