Skip to content

Commit

Permalink
Exit with zero datapoints message if no datapoints exist (#43)
Browse files Browse the repository at this point in the history
* Exit with zero datapoints message if no datapoints exist
  • Loading branch information
ynnt authored and sstarcher committed Jan 9, 2017
1 parent d74050d commit cf81f6f
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions lib/sensu-plugins-graphite/graphite_proxy/proxy.rb
Expand Up @@ -3,10 +3,7 @@
module SensuPluginsGraphite
module GraphiteProxy
class ProxyError < StandardError
attr_accessor :exception

def initialize(msg, args)
self.exception = args[:exception]
def initialize(msg)
super msg
end
end
Expand Down Expand Up @@ -87,24 +84,20 @@ def retrieve_data!
handle = open(url, request_auth_options(config))

@raw_data = handle.gets
if @raw_data == '[]'
unknown 'Empty data received from Graphite - metric probably doesn\'t exists'
else
json_data = JSON.parse(@raw_data)
format_output(json_data)
end
rescue OpenURI::HTTPError => e
raise ProxyError.new('Failed to connect to Graphite server', exception: e)
rescue NoMethodError => e
raise ProxyError.new('No data for time period and/or target', exception: e)
rescue Errno::ECONNREFUSED => e
raise ProxyError.new('Connection refused when connecting to Graphite server', exception: e)
rescue Errno::ECONNRESET => e
raise ProxyError.new('Connection reset by peer when connecting to Graphite server', exception: e)
rescue EOFError => e
raise ProxyError.new('End of file error when reading from Graphite server', exception: e)
json_data = JSON.parse(@raw_data)
format_output(json_data)
rescue OpenURI::HTTPError
raise ProxyError, 'Failed to connect to Graphite server'
rescue NoMethodError, JSON::ParserError
raise ProxyError, 'No data for time period and/or target'
rescue Errno::ECONNREFUSED
raise ProxyError, 'Connection refused when connecting to Graphite server'
rescue Errno::ECONNRESET
raise ProxyError, 'Connection reset by peer when connecting to Graphite server'
rescue EOFError
raise ProxyError, 'End of file error when reading from Graphite server'
rescue => e
raise ProxyError.new("An unknown error occurred: #{e.inspect}", exception: e)
raise ProxyError, "An unknown error occurred: #{e.inspect}"
end
end
end
Expand Down

0 comments on commit cf81f6f

Please sign in to comment.