bin/check-stale-results.rb in sensu-plugins-sensu-3.0.0 vs bin/check-stale-results.rb in sensu-plugins-sensu-4.0.0

- old
+ new

@@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: false + # # check-stale-results.rb # # Author: Matteo Cerutti <matteo.cerutti@hotmail.co.uk> # @@ -52,11 +54,11 @@ @results = results end def humanize(secs) [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map do |count, name| - if secs > 0 + if secs.positive? secs, n = secs.divmod(count) "#{n.to_i} #{name}" end end.compact.reverse.join(' ') end @@ -67,11 +69,15 @@ URI("#{protocol}://#{host}:#{settings['api']['port']}#{path}") end def api_request(method, path) unless settings.key?('api') - raise 'api.json settings not found.' + unknown <<~HEREDOC + sensu does not have an api config stanza set, please configure it in + either /etc/sensu/config.json or in any config that is loaded by sensu + such as /etc/sensu/conf.d/api.json + HEREDOC end uri = get_uri(path) Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| request = net_http_req_class(method).new(path) if settings['api']['user'] && settings['api']['password'] @@ -83,10 +89,10 @@ end def results res = [] req = api_request(:GET, '/results') - res = JSON.parse(req.body) if req && req.code == '200' + res = JSON.parse(req.body) if req&.code == '200' res end def run stale = 0