Skip to content

Commit

Permalink
Fix time out
Browse files Browse the repository at this point in the history
When there are lots of virtual network interfaces `ntpq` is somehow confused and returns this error:
> localhost: timed out, nothing received
> ***Request timed out CheckNTP UNKNOWN: NTP command Failed

Defining 127.0.0.1 host at end of `ntpq` command fixed this problem.
  • Loading branch information
mdzidic authored and majormoses committed Jan 4, 2018
1 parent 16bbebf commit d0008ab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/check-ntp.rb
Expand Up @@ -59,10 +59,10 @@ class CheckNTP < Sensu::Plugin::Check::CLI

def run
begin
output = `ntpq -c "rv 0 stratum,offset"`.split("\n").find { |line| line.start_with?('stratum') }
output = `ntpq -c "rv 0 stratum,offset" 127.0.0.1`.split("\n").find { |line| line.start_with?('stratum') }
stratum = output.split(',')[0].split('=')[1].strip.to_i
offset = output.split(',')[1].split('=')[1].strip.to_f
source_field_status = config[:unsynced_status] == 'ok' ? 6 : /status=[0-9a-f]([0-9])[0-9a-f]{2}/.match(`ntpq -c "rv 0"`)[1].to_i
source_field_status = config[:unsynced_status] == 'ok' ? 6 : /status=[0-9a-f]([0-9])[0-9a-f]{2}/.match(`ntpq -c "rv 0" 127.0.0.1`)[1].to_i
rescue
unknown 'NTP command Failed'
end
Expand Down

0 comments on commit d0008ab

Please sign in to comment.