wavefront-client 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjdmYWUzYzk4NjEwYzQ1YzdhNGJjYzViMGRmYjY0ZmNkMGExOWU4MQ==
4
+ YTkyYWUzNzQ3MTVmYjhlNGI3NWZlZDM5YTBjYTAwMzNkMTQ2MjQ0YQ==
5
5
  data.tar.gz: !binary |-
6
- ODgzZGM5ZGMxNzViNjBhYTE5Y2UwZmI1NmZlMWE3MmVlZWQ0NjY5OQ==
6
+ NDNlN2ZiNmYxNDE0NzhlMzdjMTJhNjExZGI4ZjhhY2Q0YWE5YjViMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Zjk2MDYxMWUxODc2MjA2Yzg2ZTQ3NWM5NDZjNzg1ZjA2NDRhY2JhYWVlYTM0
10
- ZTEyMTQ3ODdlMDViNDFlNDkyYjZhMTFiN2VhMjcwMWQ0YWVjMmQ4MjBmZDA5
11
- ZWQ2NmU5MWViYjAyMDkyZjY2YWVmYWJjZmMxMTdiMjdjYmY1N2I=
9
+ YzQxYzE3NGZmNzkwNWRjYzgxYWM0MDBhNDk5OGM1NGZlMjE4MDA2ZWI2YTNi
10
+ YTRhNTQxYTIzYzFhNWRlYTgxYzIyNWI1OTgwNTA1ZWE0NjFmMjY0M2Y2ODg3
11
+ ZmVlOTJmZDk2YTdiYjVkOGEzOTUzYTMwYjk3NTU5NjVkOWRjZjI=
12
12
  data.tar.gz: !binary |-
13
- MTc0YWFjNmQyZGFlOWRjYzQwODdlZWIwYWVkOTFmYWJmODQ1OTVkZWQ4MWY4
14
- ZGZlZDMxYTRkYjgyZDk4YWZhNjE1YWVhM2Q2YTcyODE2NTgxYWQ5N2MxOGFk
15
- ZTI0Y2M3MzAxZGY3MzNkNTIxOGYzOGNmNzcyZDYxMTY0NmJhMjA=
13
+ MDljMjNlYzg3YTJhNjY0YWQ3MDA0Y2M2ZDYyOWVjMzlkOTA5NzEyMjJhMzNl
14
+ NmFhMjVmMjI4MDAyNjEzNTc1OTlmOWE5ZWYyY2Y4MzY2ZDg5ODAzOTI2OGEw
15
+ ZTg0NWFiZGQyOTNhZGRkYmEyNmE3ZGNiMzI2NmIxYjBmNjY1NmE=
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- Wavefront::Client
1
+ Wavefront
2
2
  ==========
3
3
  [![Build Status](https://travis-ci.org/wavefrontHQ/ruby-client.svg?branch=v0.5.2)](https://travis-ci.org/wavefrontHQ/ruby-client)
4
4
 
5
- This is a simple ruby gem for speaking to the [Wavefront][1] monitoring and graphing system.
5
+ This is a ruby gem for speaking to the [Wavefront][1] monitoring and graphing system.
6
6
 
7
7
  ## Usage
8
8
  Within your own ruby code:
@@ -165,11 +165,52 @@ response.highcharts[0]['data'].first # [1436849460000, 517160277.3333333]
165
165
  ```
166
166
 
167
167
  ### Command-line client
168
- A simple command line client is included too. You can see the full list of options by typing `wavefront-client --help` from a prompt.
168
+ A command line client is included too. You can see the full list of options by typing `wavefront --help` from a prompt.
169
169
 
170
170
  ```bash
171
- $ wavefront-client '<TS_EXPRESSION>' --minutes --token <YOUR_TOKEN > # <TS_EXPRESSION> : Placeholder for a valid Wavefront ts() query , <YOUR_TOKEN> : Placeholder for your Wavefront token
172
- response.class # Wavefront::Response::Ruby
171
+ Usage: wavefront COMMAND QUERY (OPTIONS)
172
+ -h, --help Display this message
173
+
174
+ Available commands:
175
+
176
+ ts Query the timeseries
177
+ alerts Query alerts
178
+
179
+ See `<command> --help` for more information on a specific command.
180
+
181
+ $ wavefront ts --help
182
+ Usage: wavefront COMMAND QUERY (OPTIONS)
183
+ -d, --days Query granularity of days
184
+ -D, --debug Enable debug mode
185
+ -m, --minutes Query granularity of minutes
186
+ -H, --hours Query granularity of hours
187
+ -E, --endpoint Connect to alternative cluster endpoint (default: metrics.wavefront.com)
188
+ -S, --seconds Query granularity of seconds
189
+ -s, --start Time in UNIX epoch seconds to begin the query from
190
+ -t, --token Wavefront authentication token
191
+ -e, --end Time in UNIX epoch seconds to query to
192
+ -f, --format Output format (raw, ruby, graphite, highcharts) (default: raw)
193
+ -p, --prefixlength The number of path elements to treat as a prefix when doing schema manipulations (default: 1)
194
+ -X, --strict Flag to not return points outside the query window [q;s) (default: true)
195
+ -O, --includeObsoleteMetrics Flag to include metrics that have not been reporting for more than 4 weeks,defaults to false
196
+ -h, --help Display this message
197
+
198
+ $ wavefront ts "ts(my.metric.path.host.cpu-0.percent-idle)" -t SECRET -m -f ruby
199
+ #<Wavefront::Response::Ruby:0x007f02f6bf9d70
200
+ @granularity=60,
201
+ @name="Unknown",
202
+ @options=
203
+ {:response_format=>:ruby,
204
+ :prefix_length=>1,
205
+
206
+ ...
207
+
208
+ $ wavefront alerts snoozed -t TOKEN -f json --shared ops
209
+ [
210
+ {
211
+ "customerTagsWithCounts": {
212
+
213
+ ...
173
214
  ```
174
215
 
175
216
 
data/bin/wavefront ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2015 Wavefront Inc.
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'wavefront/client'
17
+ require 'slop'
18
+
19
+ options = Slop.parse(strict: true) do
20
+ banner 'Usage: wavefront COMMAND QUERY (OPTIONS)'
21
+ on 'h', 'help', 'Display this message'
22
+
23
+ command 'ts' do
24
+ description "Query the timeseries"
25
+ on 'd', 'days', 'Query granularity of days'
26
+ on 'D', 'debug', 'Enable debug mode'
27
+ on 'm', 'minutes', 'Query granularity of minutes'
28
+ on 'H', 'hours', 'Query granularity of hours'
29
+ on 'E', 'endpoint=', 'Connect to alternative cluster endpoint', default: Wavefront::Client::DEFAULT_HOST.to_s
30
+ on 'S', 'seconds', 'Query granularity of seconds'
31
+ on 's', 'start=', 'Time in UNIX epoch seconds to begin the query from'
32
+ on 't', 'token=', 'Wavefront authentication token'
33
+ on 'e', 'end=', 'Time in UNIX epoch seconds to query to'
34
+ on 'f', 'format=', "Output format (#{Wavefront::Client::FORMATS.join(', ')})", default: Wavefront::Client::DEFAULT_FORMAT.to_s
35
+ on 'p', 'prefixlength=', 'The number of path elements to treat as a prefix when doing schema manipulations', default: Wavefront::Client::DEFAULT_PREFIX_LENGTH
36
+ on 'X', 'strict=','Flag to not return points outside the query window [q;s) ', default: Wavefront::Client::DEFAULT_STRICT
37
+ on 'O', 'includeObsoleteMetrics=', 'Flag to include metrics that have not been reporting for more than 4 weeks,defaults to false', default: Wavefront::Client::DEFAULT_OBSOLETE_METRICS
38
+ on 'h', 'help', 'Display this message'
39
+ run do |options, arguments|
40
+ require 'wavefront/cli/ts'
41
+ cli = Wavefront::Cli::Ts.new(options, arguments)
42
+ cli.run
43
+ end
44
+ end
45
+
46
+ command 'alerts' do
47
+ description "Query alerts"
48
+ on 'E', 'endpoint=', 'Connect to alternative cluster endpoint', default: Wavefront::Client::DEFAULT_HOST.to_s
49
+ on 'f', 'format=', 'Output format (ruby, json)', default: 'ruby'
50
+ on 'h', 'help', 'Display this message'
51
+ on 'p', 'private=', 'Retrieve only alerts with named private tags, comma delimited.'
52
+ on 's', 'shared=', 'Retrieve only alerts with named shared tags, comma delimited.'
53
+ on 't', 'token=', 'Wavefront authentication token'
54
+ run do |options, arguments|
55
+ require 'wavefront/cli/alerts'
56
+ cli = Wavefront::Cli::Alerts.new(options, arguments)
57
+ cli.run
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ puts options
@@ -53,6 +53,8 @@ module Wavefront
53
53
  get_alerts('affected_by_maintenance', options)
54
54
  end
55
55
 
56
+ private
57
+
56
58
  def get_alerts(path, options={})
57
59
  options[:host] ||= DEFAULT_HOST
58
60
  options[:path] ||= DEFAULT_PATH
@@ -77,8 +79,6 @@ module Wavefront
77
79
  RestClient.get(uri.to_s)
78
80
  end
79
81
 
80
- private
81
-
82
82
  def debug(enabled)
83
83
  if enabled
84
84
  RestClient.log = 'stdout'
@@ -0,0 +1,33 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ module Wavefront
18
+ class Cli
19
+
20
+ attr_accessor :options, :arguments
21
+
22
+ def initialize(options, arguments)
23
+ @options = options
24
+ @arguments = arguments
25
+
26
+ if @options.help?
27
+ puts @options
28
+ exit 0
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2015 Wavefront Inc.
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'wavefront/alerting'
17
+ require 'wavefront/cli'
18
+ require 'json'
19
+ require 'pp'
20
+
21
+ class Wavefront::Cli::Alerts < Wavefront::Cli
22
+
23
+ attr_accessor :options, :arguments
24
+
25
+ def run
26
+ alerts = Wavefront::Alerting.new(@options[:token])
27
+ queries = alerts.public_methods(false).sort
28
+ queries.delete(:token)
29
+
30
+ if arguments[0]
31
+ query = arguments[0].to_sym
32
+ else
33
+ puts "Your query should be one of: #{ queries.each {|q| q.to_s}.join(', ') }. See --help for more information"
34
+ exit 1
35
+ end
36
+
37
+ # This isn't especially nice, but if require to
38
+ # avoiding breaking the Alerting interface :(
39
+ options = Hash.new
40
+ options[:host] = @options[:endpoint]
41
+
42
+ if @options[:shared]
43
+ options[:shared_tags] = @options[:shared].delete(' ').split(',')
44
+ end
45
+ if @options[:private]
46
+ options[:private_tags] = @options[:private].delete(' ').split(',')
47
+ end
48
+
49
+ if queries.include?(query)
50
+ result = alerts.send(query, options)
51
+ else
52
+ puts "Your query should be one of: #{ queries.each {|q| q.to_s}.join(', ') }. See --help for more information"
53
+ exit 1
54
+ end
55
+
56
+ case @options[:format].to_sym
57
+ when :ruby
58
+ pp result
59
+ when :json
60
+ puts JSON.pretty_generate(JSON.parse(result))
61
+ else
62
+ puts "Invalid output format, See --help for more detail."
63
+ exit 1
64
+ end
65
+
66
+ exit 0
67
+ end
68
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2015 Wavefront Inc.
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'wavefront/client'
17
+ require 'wavefront/cli'
18
+ require 'pp'
19
+ require 'json'
20
+
21
+ class Wavefront::Cli::Ts < Wavefront::Cli
22
+
23
+ attr_accessor :options, :arguments
24
+
25
+ def run
26
+ query = @arguments[0]
27
+ if @options.minutes?
28
+ granularity = 'm'
29
+ elsif @options.hours?
30
+ granularity = 'h'
31
+ elsif @options.seconds?
32
+ granularity = 's'
33
+ elsif @options.days?
34
+ granularity = 'd'
35
+ else
36
+ puts "You must specify a granularity of either --seconds, --minutes --hours or --days. See --help for more information."
37
+ exit 1
38
+ end
39
+
40
+ unless Wavefront::Client::FORMATS.include?(@options[:format].to_sym)
41
+ puts "The output format must be on of #{Wavefront::Client::FORMATS.join(', ')}"
42
+ exit 1
43
+ end
44
+
45
+ options = Hash.new
46
+ options[:response_format] = @options[:format].to_sym
47
+ options[:prefix_length] = @options[:prefixlength].to_i
48
+
49
+ if @options[:start]
50
+ options[:start_time] = Time.at(@options[:start].to_i)
51
+ end
52
+
53
+ if @options[:end]
54
+ options[:end_time] = Time.at(@options[:end].to_i)
55
+ end
56
+
57
+ wave = Wavefront::Client.new(@options[:token], @options[:endpoint], @options[:debug])
58
+ case options[:response_format]
59
+ when :raw
60
+ puts wave.query(query, granularity, options)
61
+ when :graphite
62
+ puts wave.query(query, granularity, options).graphite.to_json
63
+ else
64
+ pp wave.query(query, granularity, options)
65
+ end
66
+
67
+ exit 0
68
+ end
69
+ end
@@ -16,6 +16,6 @@ See the License for the specific language governing permissions and
16
16
 
17
17
  module Wavefront
18
18
  class Client
19
- VERSION = "2.1.0"
19
+ VERSION = "3.0.0"
20
20
  end
21
21
  end
@@ -45,38 +45,38 @@ describe Wavefront::Alerting do
45
45
  describe '#get_alerts' do
46
46
  it 'makes API request with default options' do
47
47
  expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}")}")
48
- @wave.get_alerts('all')
48
+ @wave.all
49
49
  end
50
50
 
51
51
  it 'makes API request with specified host' do
52
52
  host = 'madeup.wavefront.com'
53
53
  expect(RestClient).to receive(:get).with("https://#{File.join(host, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}")}")
54
- @wave.get_alerts('all', { :host => host } )
54
+ @wave.all({ :host => host })
55
55
  end
56
56
 
57
57
  it 'makes API request with specified path' do
58
58
  path = '/api/new_alerts'
59
59
  expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, path, "all?t=#{TEST_TOKEN}")}")
60
- @wave.get_alerts('all', { :path => path })
60
+ @wave.all({ :path => path })
61
61
  end
62
62
 
63
63
  it 'makes API request with appended shared tags' do
64
64
  tags = [ 'first', 'second' ]
65
65
  expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}&customerTag=first&customerTag=second")}")
66
- @wave.get_alerts('all', { :shared_tags => tags })
66
+ @wave.all({ :shared_tags => tags })
67
67
  end
68
68
 
69
69
  it 'makes API request with appended private tags' do
70
70
  tags = [ 'first', 'second' ]
71
71
  expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}&userTag=first&userTag=second")}")
72
- @wave.get_alerts('all', { :private_tags => tags })
72
+ @wave.all({ :private_tags => tags })
73
73
  end
74
74
 
75
75
  it 'makes API request with both appended private tags and shared tags' do
76
76
  private_tag = 'first'
77
77
  shared_tag = 'second'
78
78
  expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}&customerTag=second&userTag=first")}")
79
- @wave.get_alerts('all', { :private_tags => private_tag, :shared_tags => shared_tag })
79
+ @wave.all({ :private_tags => private_tag, :shared_tags => shared_tag })
80
80
  end
81
81
  end
82
82
 
@@ -22,7 +22,7 @@ require 'wavefront/client/version'
22
22
  Gem::Specification.new do |spec|
23
23
  spec.name = "wavefront-client"
24
24
  spec.version = Wavefront::Client::VERSION
25
- spec.authors = ["Sam Pointer", "Louis McCormack", "Joshua McGhee", "Conor Beverland", "Salil Deshmukh"]
25
+ spec.authors = ["Sam Pointer", "Louis McCormack", "Joshua McGhee", "Conor Beverland", "Salil Deshmukh", "Rob Fisher"]
26
26
  spec.email = ["support@wavefront.com"]
27
27
  spec.description = %q{A simple abstraction for talking to wavefront in ruby}
28
28
  spec.summary = %q{A simple abstraction for talking to wavefront in ruby}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pointer
@@ -9,10 +9,11 @@ authors:
9
9
  - Joshua McGhee
10
10
  - Conor Beverland
11
11
  - Salil Deshmukh
12
+ - Rob Fisher
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2016-04-21 00:00:00.000000000 Z
16
+ date: 2016-05-16 00:00:00.000000000 Z
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
18
19
  name: bundler
@@ -100,7 +101,7 @@ description: A simple abstraction for talking to wavefront in ruby
100
101
  email:
101
102
  - support@wavefront.com
102
103
  executables:
103
- - wavefront-client
104
+ - wavefront
104
105
  extensions: []
105
106
  extra_rdoc_files: []
106
107
  files:
@@ -112,8 +113,11 @@ files:
112
113
  - NOTICE
113
114
  - README.md
114
115
  - Rakefile
115
- - bin/wavefront-client
116
+ - bin/wavefront
116
117
  - lib/wavefront/alerting.rb
118
+ - lib/wavefront/cli.rb
119
+ - lib/wavefront/cli/alerts.rb
120
+ - lib/wavefront/cli/ts.rb
117
121
  - lib/wavefront/client.rb
118
122
  - lib/wavefront/client/version.rb
119
123
  - lib/wavefront/constants.rb
data/bin/wavefront-client DELETED
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright 2015 Wavefront Inc.
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
-
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- require 'wavefront/client'
17
- require 'slop'
18
- require 'pp'
19
- require 'json'
20
-
21
- @opts = Slop.parse(strict: true) do
22
- banner 'Usage: wavefront-client QUERY (OPTIONS)'
23
- on 'd', 'days', 'Query granularity of days'
24
- on 'D', 'debug', 'Enable debug mode'
25
- on 'm', 'minutes', 'Query granularity of minutes'
26
- on 'H', 'hours', 'Query granularity of hours'
27
- on 'E', 'endpoint=', 'Connect to alternative cluster endpoint', default: Wavefront::Client::DEFAULT_HOST.to_s
28
- on 'S', 'seconds', 'Query granularity of seconds'
29
- on 's', 'start=', 'Time in UNIX epoch seconds to begin the query from'
30
- on 't', 'token=', 'Wavefront authentication token'
31
- on 'e', 'end=', 'Time in UNIX epoch seconds to query to'
32
- on 'f', 'format=', "Output format (#{Wavefront::Client::FORMATS.join(', ')})", default: Wavefront::Client::DEFAULT_FORMAT.to_s
33
- on 'p', 'prefixlength=', 'The number of path elements to treat as a prefix when doing schema manipulations', default: Wavefront::Client::DEFAULT_PREFIX_LENGTH
34
- on 'X', 'strict=','Flag to not return points outside the query window [q;s) ', default: Wavefront::Client::DEFAULT_STRICT
35
- on 'O', 'includeObsoleteMetrics=', 'Flag to include metrics that have not been reporting for more than 4 weeks,defaults to false', default: Wavefront::Client::DEFAULT_OBSOLETE_METRICS
36
-
37
- on 'h', 'help', 'Display this message'
38
- end
39
-
40
- if @opts.help?
41
- puts @opts
42
- exit 0
43
- end
44
-
45
- query = ARGV[0]
46
- if @opts.minutes?
47
- granularity = 'm'
48
- elsif @opts.hours?
49
- granularity = 'h'
50
- elsif @opts.seconds?
51
- granularity = 's'
52
- elsif @opts.days?
53
- granularity = 'd'
54
- else
55
- puts "You must specify a granularity of either --seconds, --minutes --hours or --days. See --help for more information."
56
- exit 1
57
- end
58
-
59
- unless Wavefront::Client::FORMATS.include?(@opts[:format].to_sym)
60
- puts "The output format must be on of #{Wavefront::Client::FORMATS.join(', ')}"
61
- exit 1
62
- end
63
-
64
- options = Hash.new
65
- options[:response_format] = @opts[:format].to_sym
66
- options[:prefix_length] = @opts[:prefixlength].to_i
67
-
68
- if @opts[:start]
69
- options[:start_time] = Time.at(@opts[:start].to_i)
70
- end
71
-
72
- if @opts[:end]
73
- options[:end_time] = Time.at(@opts[:end].to_i)
74
- end
75
-
76
- wave = Wavefront::Client.new(@opts[:token], @opts[:endpoint], @opts[:debug])
77
- case options[:response_format]
78
- when :raw
79
- puts wave.query(query, granularity, options)
80
- when :graphite
81
- puts wave.query(query, granularity, options).graphite.to_json
82
- else
83
- pp wave.query(query, granularity, options)
84
- end