Class: Grafana::Client
- Includes:
- Admin, Alerts, Annotations, Dashboard, DashboardPermissions, DashboardVersions, Datasource, Folder, FolderPermissions, FolderSearch, Login, Network, Organization, Organizations, Playlist, Preferences, Snapshot, Teams, Tools, User, Users, Validator, Version, Logging
- Defined in:
- lib/grafana/client.rb
Overview
Abstract base class for the API calls. Provides some helper methods
Constant Summary
Constants included from Version
Version::MAJOR, Version::MINOR, Version::TINY
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(settings) ⇒ Client
constructor
Create a new instance of Class.
-
#settings ⇒ Object
Get Settings.
- #version ⇒ Object
Methods included from Playlist
#create_playlist, #delete_playlist, #playlist, #playlist_dashboards, #playlist_items, #playlists, #update_playlist
Methods included from FolderSearch
Methods included from FolderPermissions
#folder_permissions, #update_folder_permissions
Methods included from Folder
#create_folder, #delete_folder, #folder, #folders, #update_folder
Methods included from Alerts
#alert, #alert_notifications, #alert_pause, #alerts, #create_alert_notification, #delete_alert_notification, #update_alert_notification
Methods included from Snapshot
#create_snapshot, #delete_snapshot, #snapshot
Methods included from DashboardPermissions
#dashboard_permissions, #update_dashboad_permissions
Methods included from DashboardVersions
#compare_dashboard_version, #dashboard_all_versions, #dashboard_version, #restore_dashboard
Methods included from Dashboard
#create_dashboard, #dashboard, #dashboard_by_uid, #dashboard_tags, #delete_dashboard, #home_dashboard, #import_dashboards_from_directory, #search_dashboards
Methods included from Organizations
#add_user_to_organization, #create_organisation, #delete_organisation, #delete_user_from_organization, #organization, #organization_users, #organizations, #update_organization, #update_organization_user
Methods included from Organization
#add_user_to_current_organization, #current_organization, #current_organization_users, #update_current_organization
Methods included from Datasource
#create_datasource, #datasource, #datasources, #delete_datasource, #update_datasource
Methods included from Teams
#add_team, #add_team_member, #delete_team, #remove_team_member, #search_team, #team, #team_members, #update_team
Methods included from Users
#search_for_users_by, #update_user, #user, #user_organizations, #users
Methods included from User
#add_dashboard_star, #current_user, #current_user_oganizations, #remove_dashboard_star, #switch_current_user_organization, #update_current_user_password
Methods included from Preferences
#org_preferences, #update_org_preferences, #update_user_preferences, #user_preferences
Methods included from Annotations
#create_annotation, #create_annotation_graphite, #delete_annotation, #delete_annotation_by_region, #find_annotation, #update_annotation
Methods included from Admin
#add_user, #admin_settings, #admin_stats, #delete_user, #pause_all_alerts, #update_user_password, #update_user_permissions
Methods included from Tools
#regenerate_template_ids, #slug, #valid_json?
Methods included from Network
#delete, #get, #patch, #post, #put
Methods included from Login
#headers, #login, #ping_session
Methods included from Validator
Methods included from Logging
configure_logger_for, #logger, logger_for
Constructor Details
#initialize(settings) ⇒ Client
Create a new instance of Class
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/grafana/client.rb', line 103 def initialize( settings ) raise ArgumentError.new('only Hash are allowed') unless( settings.is_a?(Hash) ) raise ArgumentError.new('missing settings') if( settings.size.zero? ) host = settings.dig(:grafana, :host) || 'localhost' port = settings.dig(:grafana, :port) || 3000 url_path = settings.dig(:grafana, :url_path) || '' ssl = settings.dig(:grafana, :ssl) || false @timeout = settings.dig(:grafana, :timeout) || 5 @open_timeout = settings.dig(:grafana, :open_timeout) || 5 @http_headers = settings.dig(:grafana, :http_headers) || {} @debug = settings.dig(:debug) || false @headers = {} raise ArgumentError.new('missing \'host\'') if( host.nil? ) raise ArgumentError.new(format('wrong type. \'port\' must be an Integer, given \'%s\'', port.class.to_s)) unless( port.is_a?(Integer) ) raise ArgumentError.new(format('wrong type. \'url_path\' must be an String, given \'%s\'', url_path.class.to_s)) unless( url_path.is_a?(String) ) raise ArgumentError.new(format('wrong type. \'ssl\' must be an Boolean, given \'%s\'', ssl.class.to_s)) unless( ssl.is_a?(Boolean) ) raise ArgumentError.new(format('wrong type. \'timeout\' must be an Integer, given \'%s\'', @timeout.class.to_s)) unless( @timeout.is_a?(Integer) ) raise ArgumentError.new(format('wrong type. \'open_timeout\' must be an Integer, given \'%s\'', @open_timeout.class.to_s)) unless( @open_timeout.is_a?(Integer) ) protocoll = ssl == true ? 'https' : 'http' @url = format( '%s://%s:%d%s', protocoll, host, port, url_path ) end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
74 75 76 |
# File 'lib/grafana/client.rb', line 74 def debug @debug end |
Class Method Details
.logger ⇒ Object
152 153 154 |
# File 'lib/grafana/client.rb', line 152 def self.logger @@logger ||= defined?(Logging) ? Logging.logger : Logger.new(STDOUT) end |
.logger=(logger) ⇒ Object
156 157 158 |
# File 'lib/grafana/client.rb', line 156 def self.logger=(logger) @@logger = logger end |
Instance Method Details
#settings ⇒ Object
Get Settings
136 137 138 139 140 |
# File 'lib/grafana/client.rb', line 136 def settings endpoint = '/api/frontend/settings' @logger.debug("Getting all settings (GET #{endpoint})") if @debug get(endpoint) end |
#version ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/grafana/client.rb', line 143 def version s = settings @version = s.dig('buildInfo','version') @major_version = @version.split('.').first.to_i {version: @version, major_version: @major_version} end |