Class: Grafana::Client

Inherits:
Object show all
Includes:
Admin, Annotations, Dashboard, DashboardVersions, Datasource, Login, Network, Organization, Organizations, Snapshot, Tools, User, Users, Validator, Version, Logging
Defined in:
lib/grafana/client.rb

Overview

Abstract base class for the API calls. Provides some helper methods

Author:

  • Bodo Schulz

Constant Summary

Constants included from Version

Version::MAJOR, Version::MINOR, Version::TINY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Snapshot

#create_snapshot, #delete_snapshot, #snapshot

Methods included from DashboardVersions

#compare_dashboard_version, #dashboard_all_versions, #dashboard_version, #restore_dashboard

Methods included from Dashboard

#create_dashboard, #dashboard, #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 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 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

#login, #ping_session

Methods included from Validator

#validate

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

#initialize(settings) ⇒ Client

Create a new instance of Class

Examples:

to create an new Instance

config = {
  grafana: {
    host: '192.168.33.5',
    port: 3000,
    url_path: '/grafana',
    ssl: false,
    timeout: 10,
    open_timeout: 10,
    debug: true
}

@grafana = Grafana::Client.new(config)

Parameters:

  • settings (Hash, #read)

    the settings for Grafana

Options Hash (settings):

  • :host (String) — default: 'localhost'

    the Grafana Hostname

  • :port (Integer) — default: 3000

    the Grafana HTTP Port

  • :url_path (String) — default: ''
  • :ssl (Bool) — default: false
  • :timeout (Integer) — default: 5
  • :open_timeout (Integer) — default: 5
  • :http_headers (Hash) — default: {}
  • :debug (Bool) — default: false

Raises:

  • (ArgumentError)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/grafana/client.rb', line 87

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

  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

#debugObject

Returns the value of attribute debug.



58
59
60
# File 'lib/grafana/client.rb', line 58

def debug
  @debug
end

Class Method Details

.loggerObject



114
115
116
# File 'lib/grafana/client.rb', line 114

def self.logger
  @@logger ||= defined?(Logging) ? Logging.logger : Logger.new(STDOUT)
end

.logger=(logger) ⇒ Object



118
119
120
# File 'lib/grafana/client.rb', line 118

def self.logger=(logger)
  @@logger = logger
end