Skip to content

Commit

Permalink
improve dashboard lwrp error logging (ref #64)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanyonm committed Jul 17, 2015
1 parent b474c2e commit b75e6bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .rubocop.yml
Expand Up @@ -8,7 +8,7 @@ AlignParameters:
Enabled: false

LineLength:
Max: 200
Max: 275

Documentation:
Enabled: false
Expand All @@ -22,6 +22,9 @@ Metrics/MethodLength:
Metrics/ModuleLength:
Max: 120

Metrics/PerceivedComplexity:
Max: 8

Style/AsciiComments:
Enabled: false

Expand Down
10 changes: 8 additions & 2 deletions libraries/dashboard_api.rb
Expand Up @@ -92,11 +92,17 @@ def dashboard_sanity(dashboard_options)
dashboard_source_file = File.expand_path("#{Chef::Config[:file_cache_path]}/cookbooks/#{dashboard_options[:cookbook]}/files/default/#{dashboard_options[:source]}.json", File.dirname(__FILE__))
end
unless File.exist?(dashboard_source_file)
fail "#{dashboard_options[:source]} was specified, but #{dashboard_source_file} does not exist!"
if !dashboard_options[:path].nil?
err_msg_prt = "#{dashboard_options[:path]} path"
else
err_msg_prt = "#{dashboard_options[:source]} source"
end
fail "dashboard_sanity failure: #{err_msg_prt} was specified, but #{dashboard_source_file} does not exist!"
end
dash_json = JSON.parse(File.read(dashboard_source_file))

fail "#{dashboard_options[:name]} did not match the name (#{dash_json['title']}) in the json" if dash_json['title'].gsub('.', '-').gsub(' ', '-').downcase != dashboard_options[:name]
dash_json_title = dash_json['title'].gsub('.', '-').gsub(' ', '-').downcase
fail "dashboard_sanity failure: #{dashboard_options[:name]} did not match a valid Grafana slug (#{dash_json_title}) in the json. See http://docs.grafana.org/reference/http_api/#get-dashboard for more details." if dash_json_title != dashboard_options[:name]
rescue BackendError
nil
end
Expand Down

0 comments on commit b75e6bd

Please sign in to comment.