Class: Wavefront::Dashboard

Inherits:
CoreApi
  • Object
show all
Defined in:
lib/wavefront-sdk/dashboard.rb

Overview

View and manage dashboards.

Instance Attribute Summary

Attributes inherited from CoreApi

#api, #creds, #logger, #opts

Instance Method Summary collapse

Methods inherited from CoreApi

#api_base, #api_path, #hash_for_update, #initialize, #setup_api, #time_to_ms

Methods included from Mixins

#log, #parse_relative_time, #parse_time, #relative_time, #time_multiplier, #valid_relative_time?

Methods included from Validators

#uuid?, #wf_alert_id?, #wf_alert_severity?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_point?, #wf_point_tag?, #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_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::CoreApi

Instance Method Details

#acl_add(id, view = [], modify = []) ⇒ Wavefront::Response

POST /api/v2/dashboard/acl/add Adds the specified ids to the given dashboards’ ACL

Parameters:

  • id (String)

    ID of dashboard

  • view (Array[Hash]) (defaults to: [])

    array of entities allowed to view the dashboard. Entities may be users or groups, and are defined as a Hash with keys :id and :name. For users the two will be the same, for groups, not.

  • modify (Array[Hash]) (defaults to: [])

    array of entities allowed to view and modify the dashboard. Same rules as @view.

Returns:



204
205
206
207
208
# File 'lib/wavefront-sdk/dashboard.rb', line 204

def acl_add(id, view = [], modify = [])
  api.post(%w[acl add].uri_concat,
           acl_body(id, view, modify),
           'application/json')
end

#acl_delete(id, view = [], modify = []) ⇒ Object

POST /api/v2/dashboard/acl/remove Removes the specified ids from the given dashboards’ ACL

Though the API method is ‘remove’, the acl method names have been chosen to correspond with the tag methods.



216
217
218
219
220
# File 'lib/wavefront-sdk/dashboard.rb', line 216

def acl_delete(id, view = [], modify = [])
  api.post(%w[acl remove].uri_concat,
           acl_body(id, view, modify),
           'application/json')
end

#acl_set(id, view = [], modify = []) ⇒ Object

PUT /api/v2/dashboard/acl/set Set ACL for the specified dashboards



225
226
227
# File 'lib/wavefront-sdk/dashboard.rb', line 225

def acl_set(id, view = [], modify = [])
  api.put(%w[acl set].uri_concat, acl_body(id, view, modify))
end

#acls(id_list) ⇒ Wavefront::Response

GET /api/v2/dashboard/acl Get list of Access Control Lists for the specified dashboards

Parameters:

Returns:



188
189
190
191
# File 'lib/wavefront-sdk/dashboard.rb', line 188

def acls(id_list)
  id_list.each { |id| wf_dashboard_id?(id) }
  api.get_flat_params('acl', id: id_list)
end

#create(body) ⇒ Wavefront::Response

POST /api/v2/dashboard Create a specific dashboard. Refer to the Swagger API docs for valid keys.

Parameters:

  • body (Hash)

    description of dashboard

Returns:

Raises:

  • (ArgumentError)


30
31
32
33
# File 'lib/wavefront-sdk/dashboard.rb', line 30

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

#delete(id) ⇒ Wavefront::Response

DELETE /api/v2/dashboard/id Delete a specific dashboard. Deleting an active dashboard moves it to ‘trash’, from where it can be restored with an #undelete operation. Deleting a dashboard in ‘trash’ removes it for ever.

Parameters:

  • id (String)

    ID of the dashboard

Returns:



44
45
46
47
# File 'lib/wavefront-sdk/dashboard.rb', line 44

def delete(id)
  wf_dashboard_id?(id)
  api.delete(id)
end

#describe(id, version = nil) ⇒ Wavefront::Response

GET /api/v2/dashboard/id Get a specific dashboard / Get a specific historical version of a specific dashboard.

Parameters:

  • id (String)

    ID of the dashboard

  • version (Integer) (defaults to: nil)

    version of dashboard

Returns:



57
58
59
60
61
62
63
# File 'lib/wavefront-sdk/dashboard.rb', line 57

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

#favorite(id) ⇒ Wavefront::Response Also known as: favourite

POST /api/v2/dashboard/id/favorite Mark a dashboard as favorite

Parameters:

  • id (String)

    ID of the dashboard

Returns:



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

def favorite(id)
  wf_dashboard_id?(id)
  api.post([id, 'favorite'].uri_concat)
end

#history(id) ⇒ Wavefront::Response

GET /api/v2/dashboard/id/history Get the version history of a dashboard.

Parameters:

  • id (String)

    ID of the dashboard

Returns:



104
105
106
107
# File 'lib/wavefront-sdk/dashboard.rb', line 104

def history(id)
  wf_dashboard_id?(id)
  api.get([id, 'history'].uri_concat)
end

#list(offset = 0, limit = 100) ⇒ Wavefront::Response

GET /api/v2/dashboard Get all dashboards for a customer.

Parameters:

  • offset (Int) (defaults to: 0)

    dashboard at which the list begins

  • limit (Int) (defaults to: 100)

    the number of dashboards to return

Returns:



19
20
21
# File 'lib/wavefront-sdk/dashboard.rb', line 19

def list(offset = 0, limit = 100)
  api.get('', offset: offset, limit: limit)
end

#tag_add(id, tag) ⇒ Wavefront::Response

PUT /api/v2/dashboard/id/tag/tagValue Add a tag to a specific dashboard.

Parameters:

  • id (String)

    ID of the dashboard

  • tag (String)

    tag to set.

Returns:



154
155
156
157
158
# File 'lib/wavefront-sdk/dashboard.rb', line 154

def tag_add(id, tag)
  wf_dashboard_id?(id)
  wf_string?(tag)
  api.put([id, 'tag', tag].uri_concat)
end

#tag_delete(id, tag) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the dashboard

  • tag (String)

    tag to delete

Returns:



141
142
143
144
145
# File 'lib/wavefront-sdk/dashboard.rb', line 141

def tag_delete(id, tag)
  wf_dashboard_id?(id)
  wf_string?(tag)
  api.delete([id, 'tag', tag].uri_concat)
end

#tag_set(id, tags) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the dashboard

  • tags (Array)

    list of tags to set.

Returns:



127
128
129
130
131
132
# File 'lib/wavefront-sdk/dashboard.rb', line 127

def tag_set(id, tags)
  wf_dashboard_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) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the dashboard

Returns:



115
116
117
118
# File 'lib/wavefront-sdk/dashboard.rb', line 115

def tags(id)
  wf_dashboard_id?(id)
  api.get([id, 'tag'].uri_concat)
end

#undelete(id) ⇒ Wavefront::Response

POST /api/v2/dashboard/id/undelete Move a dashboard from ‘trash’ back into active service.

Parameters:

  • id (String)

    ID of the dashboard

Returns:



166
167
168
169
# File 'lib/wavefront-sdk/dashboard.rb', line 166

def undelete(id)
  wf_dashboard_id?(id)
  api.post([id, 'undelete'].uri_concat)
end

#unfavorite(id) ⇒ Wavefront::Response Also known as: unfavourite

POST /api/v2/dashboard/id/unfavorite Unmark a dashboard as favorite

Parameters:

  • id (String)

    ID of the dashboard

Returns:



177
178
179
180
# File 'lib/wavefront-sdk/dashboard.rb', line 177

def unfavorite(id)
  wf_dashboard_id?(id)
  api.post([id, 'unfavorite'].uri_concat)
end

#update(id, body, modify = true) ⇒ Wavefront::Response

PUT /api/v2/dashboard/id Update a specific dashboard.

Parameters:

  • id (String)

    a Wavefront alert ID

  • body (Hash)

    key-value hash of the parameters you wish to change

  • modify (true, false) (defaults to: true)

    if true, use #describe() to get a hash describing the existing object, and modify that with the new body. If false, pass the new body straight through.

Returns:

Raises:

  • (ArgumentError)


76
77
78
79
80
81
82
83
84
# File 'lib/wavefront-sdk/dashboard.rb', line 76

def update(id, body, modify = true)
  wf_dashboard_id?(id)
  raise ArgumentError unless body.is_a?(Hash)

  return api.put(id, body, 'application/json') unless modify

  api.put(id, hash_for_update(describe(id).response, body),
          'application/json')
end

#update_keysObject



8
9
10
# File 'lib/wavefront-sdk/dashboard.rb', line 8

def update_keys
  i[id name url description sections]
end