Module: Grafana::Datasource

Included in:
Client
Defined in:
lib/grafana/datasource.rb

Instance Method Summary collapse

Instance Method Details

#create_data_source(ds = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/grafana/datasource.rb', line 40

def create_data_source(ds={})
  if ds == {} || !ds.has_key?('name') || !ds.has_key?('database')
    @logger.error("Error: missing 'name' and 'database' values!") if @debug
    return false
  end
  endpoint = "/api/datasources"
  @logger.info("Creating data source: #{ds['name']} (database: #{ds['database']})") if @debug
  return post_request(endpoint, ds.to_json)
end

#delete_data_source(id) ⇒ Object



50
51
52
53
54
# File 'lib/grafana/datasource.rb', line 50

def delete_data_source(id)
  endpoint = "/api/datasources/#{id}"
  @logger.info("Deleting data source #{id} (DELETE #{endpoint})") if @debug
  return delete_request(endpoint)
end

#get_available_data_source_typesObject



56
57
58
59
60
# File 'lib/grafana/datasource.rb', line 56

def get_available_data_source_types()
  endpoint = '/api/datasources/plugins'
  @logger.info("Attempting to get existing data source types (GET #{endpoint})") if @debug
  return get_request(endpoint)
end

#get_cw_namespaces(datasource_id) ⇒ Object



6
7
8
9
10
# File 'lib/grafana/datasource.rb', line 6

def get_cw_namespaces(datasource_id)
  endpoint = "/api/datasources/proxy/#{datasource_id}"
  @logger.info("Getting data source namespaces (POST /api/datasources/proxy/#{datasource_id})") if @debug
  return post_request(endpoint, {"action" => "__GetNamespaces"}.to_json)
end

#get_data_source(id) ⇒ Object



26
27
28
29
30
# File 'lib/grafana/datasource.rb', line 26

def get_data_source(id)
  endpoint = "/api/datasources/#{id}"
  @logger.info("Attempting to get existing data source ID #{id}") if @debug
  return get_request(endpoint)
end

#get_data_sourcesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/grafana/datasource.rb', line 12

def get_data_sources()
  endpoint = "/api/datasources"
  @logger.info("Attempting to get existing data sources (GET #{endpoint})") if @debug
  data_sources = get_request(endpoint)
  if !data_sources
    return false
  end
  data_source_map = {}
  data_sources.each { |ds|
    data_source_map[ds['id']] = ds
  }
  return data_source_map
end

#update_data_source(id, ds = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/grafana/datasource.rb', line 32

def update_data_source(id, ds={})
  existing_ds = self.get_data_source(id)
  ds = existing_ds.merge(ds)
  endpoint = "/api/datasources/#{id}"
  @logger.info("Updating data source ID #{id}") if @debug
  return put_request(endpoint, ds.to_json)
end