Class: Wavefront::Source

Inherits:
Base
  • Object
show all
Defined in:
lib/wavefront-sdk/source.rb

Overview

View and manage source metadata.

Instance Attribute Summary

Attributes inherited from Base

#api_base, #conn, #debug, #logger, #net, #noop, #opts, #update_keys, #verbose

Instance Method Summary collapse

Methods inherited from Base

#api_delete, #api_get, #api_post, #api_put, #hash_for_update, #initialize, #log, #mk_conn, #respond, #time_to_ms

Methods included from Mixins

#parse_time

Methods included from Validators

#wf_alert_id?, #wf_alert_severity?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_point?, #wf_point_tags?, #wf_proxy_id?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_source_id?, #wf_string?, #wf_tag?, #wf_ts?, #wf_user_id?, #wf_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::Base

Instance Method Details

#create(body) ⇒ Hash

POST /api/v2/source Create metadata (description or tags) for a specific source.

Refer to the Swagger API docs for valid keys.

Parameters:

  • body (Hash)

    description of source

Returns:

Raises:

  • (ArgumentError)


28
29
30
31
# File 'lib/wavefront-sdk/source.rb', line 28

def create(body)
  raise ArgumentError unless body.is_a?(Hash)
  api_post('', body, 'application/json')
end

#delete(id) ⇒ Hash

DELETE /api/v2/source/id Delete metadata (description and tags) for a specific source.

Parameters:

  • id (String)

    ID of the source

Returns:



39
40
41
42
# File 'lib/wavefront-sdk/source.rb', line 39

def delete(id)
  wf_source_id?(id)
  api_delete(id)
end

#describe(id, version = nil) ⇒ Hash

GET /api/v2/source/id Get a specific source for a customer.

Parameters:

  • id (String)

    ID of the source

Returns:



50
51
52
53
54
55
56
# File 'lib/wavefront-sdk/source.rb', line 50

def describe(id, version = nil)
  wf_source_id?(id)
  wf_version?(version) if version
  fragments = [id]
  fragments += ['history', version] if version
  api_get(fragments.uri_concat)
end

#list(offset = 0, limit = 100) ⇒ Hash

GET /api/v2/source Get all sources for a customer

Parameters:

  • offset (Int) (defaults to: 0)

    source at which the list begins

  • limit (Int) (defaults to: 100)

    the number of sources to return

Returns:



16
17
18
# File 'lib/wavefront-sdk/source.rb', line 16

def list(offset = 0, limit = 100)
  api_get('', { offset: offset, limit: limit })
end

#tag_add(id, tag) ⇒ Hash

PUT /api/v2/source/id/tag/tagValue Add a tag to a specific source

Parameters:

  • id (String)

    ID of the source

  • tag (String)

    tag to set.

Returns:

  • (Hash)

    object with ‘status’ key and empty ‘repsonse’



119
120
121
122
123
# File 'lib/wavefront-sdk/source.rb', line 119

def tag_add(id, tag)
  wf_source_id?(id)
  wf_string?(tag)
  api_put([id, 'tag', tag].uri_concat)
end

#tag_delete(id, tag) ⇒ Hash

DELETE /api/v2/source/id/tag/tagValue Remove a tag from a specific source.

Parameters:

  • id (String)

    ID of the source

  • tag (String)

    tag to delete

Returns:

  • (Hash)

    object with ‘status’ key and empty ‘repsonse’



106
107
108
109
110
# File 'lib/wavefront-sdk/source.rb', line 106

def tag_delete(id, tag)
  wf_source_id?(id)
  wf_string?(tag)
  api_delete([id, 'tag', tag].uri_concat)
end

#tag_set(id, tags) ⇒ Hash

POST /api/v2/source/id/tag Set all tags associated with a specific source.

Parameters:

  • id (String)

    ID of the source

  • tags (Array)

    list of tags to set.

Returns:

  • (Hash)

    object describing the source with status and response keys



92
93
94
95
96
97
# File 'lib/wavefront-sdk/source.rb', line 92

def tag_set(id, tags)
  wf_source_id?(id)
  tags = Array(tags)
  tags.each { |t| wf_string?(t) }
  api_post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
end

#tags(id) ⇒ Hash

GET /api/v2/source/id/tag Get all tags associated with a specific source.

Parameters:

  • id (String)

    ID of the source

Returns:

  • (Hash)

    object describing the source with status and response keys



79
80
81
82
# File 'lib/wavefront-sdk/source.rb', line 79

def tags(id)
  wf_source_id?(id)
  api_get([id, 'tag'].uri_concat)
end

#update(id, body) ⇒ Hash

PUT /api/v2/source/id Update metadata (description or tags) for a specific source.

Refer to the Swagger API docs for valid keys.

Parameters:

  • body (Hash)

    description of source

Returns:

Raises:

  • (ArgumentError)


66
67
68
69
70
# File 'lib/wavefront-sdk/source.rb', line 66

def update(id, body)
  wf_source_id?(id)
  raise ArgumentError unless body.is_a?(Hash)
  api_put(id, body)
end