Class: WavefrontCli::Dashboard

Inherits:
Base
  • Object
show all
Includes:
Mixin::Acl, Mixin::Tag
Defined in:
lib/wavefront-cli/dashboard.rb

Overview

CLI coverage for the v2 ‘dashboard’ API.

Constant Summary

Constants included from Constants

Constants::ALL_PAGE_SIZE, Constants::DEFAULT_CONFIG, Constants::DEFAULT_OPTS, Constants::EVENT_STATE_DIR, Constants::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS, Constants::SEARCH_SPLIT

Instance Attribute Summary

Attributes inherited from Base

#klass, #klass_word, #options, #wf

Instance Method Summary collapse

Methods included from Mixin::Acl

#_acl_action, #do_acl_clear, #do_acl_grant, #do_acl_revoke, #do_acls, #everyone_id, #grant_modify, #grant_view, #print_status, #revoke_modify, #revoke_view

Methods included from Mixin::Tag

#do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_pathsearch, #do_tag_set, #do_tags

Methods inherited from Base

#_sdk_class, #cannot_noop!, #check_response_blocks, #check_status, #cli_output_class, #conds_to_query, #descriptive_name, #dispatch, #display, #display_api_error, #display_class, #display_no_api_response, #do_dump, #do_import, #do_list, #do_search, #do_set, #do_undelete, #dump_json, #dump_yaml, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #import_to_create, #initialize, #item_dump_call, #load_display_class, #matching_method, #method_word_list, #mk_creds, #mk_opts, #name_of_do_method, #no_api_response, #ok_exit, #one_or_all, #options_and_exit, #parseable_output, #range_hash, #require_sdk_class, #run, #search_key, #smart_delete, #smart_delete_message, #status_error_handler, #unsupported_format_message, #validate_id, #validate_input, #validate_opts, #validate_tags, #validator_exception, #validator_method, #warning_message

Constructor Details

This class inherits a constructor from WavefrontCli::Base

Instance Method Details

#do_deleteObject



25
26
27
# File 'lib/wavefront-cli/dashboard.rb', line 25

def do_delete
  smart_delete
end

#do_describeObject



21
22
23
# File 'lib/wavefront-cli/dashboard.rb', line 21

def do_describe
  wf.describe(options[:'<id>'], options[:version])
end

#do_favObject



50
51
52
53
# File 'lib/wavefront-cli/dashboard.rb', line 50

def do_fav
  wf.favorite(options[:'<id>'])
  do_favs
end

#do_favsObject



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

def do_favs
  require 'wavefront-sdk/search'
  wfs = Wavefront::Search.new(mk_creds, mk_opts)
  query = conds_to_query(['favorite=true'])
  wfs.search(:dashboard, query, limit: :all, sort_field: :id)
end

#do_historyObject



29
30
31
# File 'lib/wavefront-cli/dashboard.rb', line 29

def do_history
  wf.history(options[:'<id>'])
end

#do_queriesObject



33
34
35
36
37
38
39
40
41
# File 'lib/wavefront-cli/dashboard.rb', line 33

def do_queries
  resp, data = one_or_all

  queries = data.each_with_object({}) do |d, a|
    a[d.id] = extract_values(d, 'query')
  end

  resp.tap { |r| r.response.items = queries }
end

#do_unfavObject



55
56
57
58
# File 'lib/wavefront-cli/dashboard.rb', line 55

def do_unfav
  wf.unfavorite(options[:'<id>'])
  do_favs
end

#list_filter(list) ⇒ Object



15
16
17
18
19
# File 'lib/wavefront-cli/dashboard.rb', line 15

def list_filter(list)
  return list unless options[:nosystem]

  list.tap { |l| l.response.items.delete_if { |d| d[:systemOwned] } }
end

#preprocess_rawfile(raw) ⇒ Object

Dashboards are, AFAIK, unique in that they do NOT require an ID. They can have a URL instead: the two are equivalent. The easiest workaround for this is to copy the URL to the ID if we only have the former.



65
66
67
68
# File 'lib/wavefront-cli/dashboard.rb', line 65

def preprocess_rawfile(raw)
  raw[:id] = raw[:url] if raw.key?(:url) && !raw.key?(:id)
  raw
end