Skip to content

Commit

Permalink
Merge pull request #5 from BedeGaming/FAB-7030/grafana_upgrade_api
Browse files Browse the repository at this point in the history
[Minor][FAB-7030] Update grafana API endpoints [WIP]
  • Loading branch information
hristodragolovbede authored Jun 30, 2023
2 parents 13c2226 + e708cb4 commit 6ce67d5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/puppet/provider/grafana_dashboard/grafana.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def dashboards

# Return the dashboard matching with the resource's title
def find_dashboard
return unless dashboards.find { |x| x['title'] == resource[:title] }
db = dashboards.find { |x| x['title'] == resource[:title] }
return if db.nil?

response = send_request('GET', format('/api/dashboards/db/%s', slug))
response = send_request('GET', format('/api/dashboards/uid/%s', db['uid']))
if response.code != '200'
raise format('Fail to retrieve dashboard %s (HTTP response: %s/%s)', resource[:title], response.code, response.body)
end
Expand Down Expand Up @@ -84,7 +85,10 @@ def create
end

def destroy
response = send_request('DELETE', format('/api/dashboards/db/%s', slug))
db = dashboards.find { |x| x['title'] == resource[:title] }
raise Puppet::Error, format('Failed to delete dashboard %s, dashboard not found', resource[:title]) if db.nil?

response = send_request('DELETE', format('/api/dashboards/uid/%s', db['uid']))

return unless response.code != '200'
raise Puppet::Error, format('Failed to delete dashboard %s (HTTP response: %s/%s', resource[:title], response.code, response.body)
Expand Down

0 comments on commit 6ce67d5

Please sign in to comment.