Class: Wavefront::Dashboards
- Inherits:
-
Object
- Object
- Wavefront::Dashboards
show all
- Includes:
- Constants, Mixins
- Defined in:
- lib/wavefront/dashboards.rb
Overview
Wrappers around the v1 dashboards API
Constant Summary
collapse
- DEFAULT_PATH =
'/api/dashboard/'.freeze
Constants included
from Constants
Constants::ALERT_FORMATS, Constants::DASH_FORMATS, Constants::DEFAULT_ALERT_FORMAT, Constants::DEFAULT_DASH_FORMAT, Constants::DEFAULT_FORMAT, Constants::DEFAULT_HOST, Constants::DEFAULT_INFILE_FORMAT, Constants::DEFAULT_OBSOLETE_METRICS, Constants::DEFAULT_OPTS, Constants::DEFAULT_PERIOD_SECONDS, Constants::DEFAULT_PREFIX_LENGTH, Constants::DEFAULT_PROXY, Constants::DEFAULT_PROXY_PORT, Constants::DEFAULT_SOURCE_FORMAT, Constants::DEFAULT_STRICT, Constants::EVENT_LEVELS, Constants::EVENT_STATE_DIR, Constants::FORMATS, Constants::GRANULARITIES, Constants::SOURCE_FORMATS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#clone(source_id, dest_id, dest_name, source_ver = nil) ⇒ Object
-
#create(id, name) ⇒ Object
-
#create_uri(options = {}) ⇒ Object
-
#debug(enabled) ⇒ Object
-
#delete(id) ⇒ Object
-
#export(id, version = nil) ⇒ Object
-
#history(id, start = 100, limit = nil) ⇒ Object
-
#import(schema, force = false) ⇒ Object
-
#initialize(token, host = DEFAULT_HOST, debug = false, options = {}) ⇒ Dashboards
constructor
A new instance of Dashboards.
-
#list(opts = {}) ⇒ Object
-
#undelete(id) ⇒ Object
Methods included from Mixins
#call_delete, #call_get, #call_post, #hash_to_qs, #interpolate_schema, #load_file, #parse_time, #time_to_ms, #uri_concat
Constructor Details
#initialize(token, host = DEFAULT_HOST, debug = false, options = {}) ⇒ Dashboards
Returns a new instance of Dashboards.
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/wavefront/dashboards.rb', line 20
def initialize(token, host = DEFAULT_HOST, debug = false, options = {})
@headers = { :'X-AUTH-TOKEN' => token }
@endpoint = host
debug(debug)
@noop = options[:noop]
@verbose = options[:verbose]
end
|
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
18
19
20
|
# File 'lib/wavefront/dashboards.rb', line 18
def endpoint
@endpoint
end
|
Returns the value of attribute headers.
18
19
20
|
# File 'lib/wavefront/dashboards.rb', line 18
def
@headers
end
|
#noop ⇒ Object
Returns the value of attribute noop.
18
19
20
|
# File 'lib/wavefront/dashboards.rb', line 18
def noop
@noop
end
|
#verbose ⇒ Object
Returns the value of attribute verbose.
18
19
20
|
# File 'lib/wavefront/dashboards.rb', line 18
def verbose
@verbose
end
|
Instance Method Details
#clone(source_id, dest_id, dest_name, source_ver = nil) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/wavefront/dashboards.rb', line 39
def clone(source_id, dest_id, dest_name, source_ver = nil)
qs = hash_to_qs(name: dest_name, url: dest_id)
qs.<< "&v=#{source_ver}" if source_ver
call_post(create_uri(path: uri_concat(source_id, 'clone')), qs,
'application/x-www-form-urlencoded')
end
|
#create(id, name) ⇒ Object
81
82
83
84
85
|
# File 'lib/wavefront/dashboards.rb', line 81
def create(id, name)
call_post(create_uri(path: uri_concat([id, 'create'])),
"name=#{URI.encode(name)}",
'application/x-www-form-urlencoded')
end
|
#create_uri(options = {}) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/wavefront/dashboards.rb', line 87
def create_uri(options = {})
options[:host] ||= endpoint
options[:path] ||= ''
options[:qs] ||= nil
URI::HTTPS.build(
host: options[:host],
path: uri_concat(DEFAULT_PATH, options[:path]),
query: options[:qs]
)
end
|
#debug(enabled) ⇒ Object
102
103
104
|
# File 'lib/wavefront/dashboards.rb', line 102
def debug(enabled)
RestClient.log = 'stdout' if enabled
end
|
#delete(id) ⇒ Object
71
72
73
|
# File 'lib/wavefront/dashboards.rb', line 71
def delete(id)
call_post(create_uri(path: uri_concat(id, 'delete')))
end
|
#export(id, version = nil) ⇒ Object
75
76
77
78
79
|
# File 'lib/wavefront/dashboards.rb', line 75
def export(id, version = nil)
path = version ? uri_concat(id, version) : id
resp = call_get(create_uri(path: path)) || '{}'
JSON.parse(resp)
end
|
#history(id, start = 100, limit = nil) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/wavefront/dashboards.rb', line 51
def history(id, start = 100, limit = nil)
qs = "start=#{start}"
qs.<< "&limit=#{limit}" if limit
call_get(create_uri(path: uri_concat(id, 'history'), qs: qs))
end
|
#import(schema, force = false) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/wavefront/dashboards.rb', line 31
def import(schema, force = false)
qs = force ? nil : 'rejectIfExists=true'
call_post(create_uri(qs: qs), schema, 'application/json')
end
|
#list(opts = {}) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/wavefront/dashboards.rb', line 58
def list(opts = {})
qs = []
opts[:private].map { |t| qs.<< "userTag=#{t}" } if opts[:private]
opts[:shared].map { |t| qs.<< "customerTag=#{t}" } if opts[:shared]
call_get(create_uri(qs: qs.join('&')))
end
|
#undelete(id) ⇒ Object
67
68
69
|
# File 'lib/wavefront/dashboards.rb', line 67
def undelete(id)
call_post(create_uri(path: uri_concat(id, 'undelete')))
end
|