Module: Grafana::Dashboard
- Included in:
- Client
- Defined in:
- lib/grafana/dashboard.rb
Instance Method Summary collapse
- #create_dashboard(properties = {}) ⇒ Object
- #create_slug(text) ⇒ Object
- #delete_dashboard(name) ⇒ Object
- #get_dashboard(name = '') ⇒ Object
- #get_dashboard_tags ⇒ Object
- #get_home_dashboard ⇒ Object
- #search_dashboards(params = {}) ⇒ Object
Instance Method Details
#create_dashboard(properties = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/grafana/dashboard.rb', line 24 def create_dashboard(properties={}) endpoint = "/api/dashboards/db" dashboard = self.build_template(properties) @logger.info("Creating dashboard: #{properties['title']} (POST /api/dashboards/db)") if @debug return post_request(endpoint, dashboard) end |
#create_slug(text) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/grafana/dashboard.rb', line 6 def create_slug(text) if text =~ /\s/ if text =~ /-/ text = text.gsub(/\s+/, "").downcase else text = text.gsub(/\s+/, "-").downcase end end return text end |
#delete_dashboard(name) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/grafana/dashboard.rb', line 31 def delete_dashboard(name) name = self.create_slug(name) endpoint = "/api/dashboards/db/#{name}" @logger.info("Deleting dahsboard ID #{id} (DELETE #{endpoint})") if @debug return delete_request(endpoint) end |
#get_dashboard(name = '') ⇒ Object
17 18 19 20 21 22 |
# File 'lib/grafana/dashboard.rb', line 17 def get_dashboard(name='') endpoint = "/api/dashboards/db/#{name}" name = self.create_slug(name) @logger.info("Attempting to get dashboard (GET /api/dashboards/db/#{name})") if @debug return get_request(endpoint) end |
#get_dashboard_tags ⇒ Object
44 45 46 47 48 |
# File 'lib/grafana/dashboard.rb', line 44 def () endpoint = "/api/dashboards/tags" @logger.info("Attempting to get dashboard tags(GET #{endpoint})") if @debug return get_request(endpoint) end |
#get_home_dashboard ⇒ Object
38 39 40 41 42 |
# File 'lib/grafana/dashboard.rb', line 38 def get_home_dashboard() endpoint = "/api/dashboards/home" @logger.info("Attempting to get home dashboard (GET #{endpoint})") if @debug return get_request(endpoint) end |
#search_dashboards(params = {}) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/grafana/dashboard.rb', line 50 def search_dashboards(params={}) params['query'] = (params['query'].length >= 1 ? CGI::escape(params['query']) : '' ) params['starred'] = (params['starred'] ? 'true' : 'false') endpoint = "/api/search/?query=#{params['query']}&starred=#{params['starred']}&tag=#{params['tags']}" @logger.info("Attempting to search for dashboards (GET #{endpoint})") if @debug return get_request(endpoint) end |