sensu-cli 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +7 -7
- data/lib/sensu-cli.rb +4 -0
- data/lib/sensu-cli/api.rb +2 -4
- data/lib/sensu-cli/base.rb +4 -5
- data/lib/sensu-cli/cli.rb +10 -2
- data/lib/sensu-cli/editor.rb +1 -2
- data/lib/sensu-cli/filter.rb +30 -17
- data/lib/sensu-cli/settings.rb +1 -2
- data/lib/sensu-cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Mjk0ZjhhMjdkYjBjMzE1ODQwZTdhNmU3NWEyZDU1MGU5YWRkZTdiOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODgyZTA5OThlMjlmYWFlODVkY2Y4MjRkYTBmNmMwZjM5MThkNGJjMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2U4NzY3MTlkNmI4YzM0MjYxNzRhZTQwZjNiMGZlZTg1YWU1MzU1ODY1Nzk0
|
10
|
+
NjY5YWMyZWU2MzNmOTVjMGJmZTMyMjQ4NzBiMGQ5NGFjN2Y0OTg4ODc3YmUy
|
11
|
+
ODUzOGY1M2RiMDc5OTc4MmJiMWI2OTE3ZWZmYTY5MzQxY2IwZDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmYyNTU5MzUwYzQ5N2E4OTNiODRmY2Q2NjMyY2ZmNTBmNTJjYjcwZmI4YTky
|
14
|
+
Yzk2M2NhNTliNzdmZTkzMzQ5NTAyN2EwZTU5MjEyYTkwNDBjZmRmYjliYWZm
|
15
|
+
NzU4NDlmNDVmYmFiNzk0ODgzYTBkOTU4YmZlY2U1YTJkZWIxMWM=
|
data/README.md
CHANGED
@@ -41,13 +41,13 @@ open_timeout 20
|
|
41
41
|
````
|
42
42
|
This format was chosen so you can do some ENV magic via your profile and setting up an alias. For details see the [wiki](https://github.com/agent462/sensu-cli/wiki)
|
43
43
|
|
44
|
-
* All Configuration Settings
|
45
|
-
`host` String - Required
|
46
|
-
`port` String/Integer - Required
|
47
|
-
`ssl` Boolean - Optional - Defaults False
|
48
|
-
`read_timeout` Integer - Optional - Default 15 (seconds)
|
49
|
-
`open_timeout` Integer - Optional - Default 5 (seconds)
|
50
|
-
`pretty_colors` Boolean - Optional - Default True
|
44
|
+
* All Configuration Settings
|
45
|
+
`host` String - Required
|
46
|
+
`port` String/Integer - Required
|
47
|
+
`ssl` Boolean - Optional - Defaults False
|
48
|
+
`read_timeout` Integer - Optional - Default 15 (seconds)
|
49
|
+
`open_timeout` Integer - Optional - Default 5 (seconds)
|
50
|
+
`pretty_colors` Boolean - Optional - Default True
|
51
51
|
|
52
52
|
Examples
|
53
53
|
-----------
|
data/lib/sensu-cli.rb
CHANGED
data/lib/sensu-cli/api.rb
CHANGED
@@ -26,11 +26,9 @@ module SensuCli
|
|
26
26
|
begin
|
27
27
|
http.request(req)
|
28
28
|
rescue Timeout::Error
|
29
|
-
|
30
|
-
exit
|
29
|
+
SensuCli::die(1, 'HTTP request has timed out.'.color(:red))
|
31
30
|
rescue StandardError => e
|
32
|
-
|
33
|
-
exit
|
31
|
+
SensuCli::die(1, "An HTTP error occurred. Check your settings. #{e}".color(:red))
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
data/lib/sensu-cli/base.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module SensuCli
|
2
2
|
class Base
|
3
3
|
def setup
|
4
|
-
|
5
|
-
@cli = clis.global
|
4
|
+
@cli = Cli.new.global
|
6
5
|
settings
|
7
6
|
api_path(@cli)
|
8
7
|
make_call
|
@@ -25,7 +24,7 @@ module SensuCli
|
|
25
24
|
|
26
25
|
def api_path(cli)
|
27
26
|
p = PathCreator.new
|
28
|
-
p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : (
|
27
|
+
p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : SensuCli::die(1, 'Something Bad Happened')
|
29
28
|
@api = { :path => path[:path], :method => cli[:method], :command => cli[:command], :payload => (path[:payload] || false) }
|
30
29
|
end
|
31
30
|
|
@@ -45,9 +44,9 @@ module SensuCli
|
|
45
44
|
api = Api.new
|
46
45
|
res = api.request(opts)
|
47
46
|
msg = api.response(res.code, res.body, @api[:command])
|
48
|
-
msg = Filter.
|
47
|
+
msg = Filter.new(@cli[:fields][:filter]).process(msg) if @cli[:fields][:filter]
|
49
48
|
if res.code != '200'
|
50
|
-
|
49
|
+
SensuCli::die(0)
|
51
50
|
elsif @cli[:fields][:format] == 'single'
|
52
51
|
Pretty.single(msg)
|
53
52
|
elsif @cli[:fields][:format] == 'table'
|
data/lib/sensu-cli/cli.rb
CHANGED
@@ -180,14 +180,18 @@ module SensuCli
|
|
180
180
|
opts = parser('CHECK')
|
181
181
|
command = next_argv
|
182
182
|
explode_if_empty(opts, command)
|
183
|
-
p = Trollop::options
|
184
183
|
item = next_argv
|
185
184
|
case command
|
186
185
|
when 'list'
|
186
|
+
p = Trollop::options do
|
187
|
+
opt :filter, 'Field and value to filter on: command,procs', :type => :string
|
188
|
+
end
|
187
189
|
{ :command => 'checks', :method => 'Get', :fields => p }
|
188
190
|
when 'show'
|
191
|
+
p = Trollop::options
|
189
192
|
deep_merge({ :command => 'checks', :method => 'Get', :fields => { :name => item } }, { :fields => p })
|
190
193
|
when 'request'
|
194
|
+
p = Trollop::options
|
191
195
|
ARGV.empty? ? explode(opts) : subscribers = next_argv.split(',')
|
192
196
|
deep_merge({ :command => 'checks', :method => 'Post', :fields => { :check => item, :subscribers => subscribers } }, { :fields => p })
|
193
197
|
else
|
@@ -202,6 +206,7 @@ module SensuCli
|
|
202
206
|
case command
|
203
207
|
when 'list'
|
204
208
|
p = Trollop::options do
|
209
|
+
opt :filter, 'Field and value to filter on: client,graphite', :type => :string
|
205
210
|
opt :format, 'Available formats; single, table, json', :short => 'f', :type => :string
|
206
211
|
end
|
207
212
|
Trollop::die :format, 'Available optional formats: single, table, json'.color(:red) if p[:format] != 'table' && p[:format] != 'single' && p[:format] != 'json' && p[:format]
|
@@ -233,6 +238,7 @@ module SensuCli
|
|
233
238
|
opt :limit, 'The number of stashes to return', :short => 'l', :type => :string
|
234
239
|
opt :offset, 'The number of stashes to offset before returning', :short => 'o', :type => :string
|
235
240
|
opt :format, 'Available formats; single, table, json', :short => 'f', :type => :string
|
241
|
+
opt :filter, 'Field and value to filter on: path,graphite', :type => :string
|
236
242
|
end
|
237
243
|
Trollop::die :offset, 'Offset depends on the limit option --limit ( -l )'.color(:red) if p[:offset] && !p[:limit]
|
238
244
|
Trollop::die :format, 'Available optional formats: single, table, json'.color(:red) if p[:format] != 'table' && p[:format] != 'single' && p[:format] != 'json' && p[:format]
|
@@ -260,7 +266,9 @@ module SensuCli
|
|
260
266
|
explode_if_empty(opts, command)
|
261
267
|
case command
|
262
268
|
when 'list'
|
263
|
-
p = Trollop::options
|
269
|
+
p = Trollop::options do
|
270
|
+
opt :filter, 'Field and value to filter on: issued,1399505890', :type => :string
|
271
|
+
end
|
264
272
|
{ :command => 'aggregates', :method => 'Get', :fields => p }
|
265
273
|
when 'show'
|
266
274
|
p = Trollop::options do
|
data/lib/sensu-cli/editor.rb
CHANGED
data/lib/sensu-cli/filter.rb
CHANGED
@@ -1,25 +1,38 @@
|
|
1
1
|
module SensuCli
|
2
2
|
class Filter
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
attr_reader :filter
|
4
|
+
|
5
|
+
def initialize(filter_data)
|
6
|
+
filter_split(filter_data)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
def filter_split(filter)
|
10
|
+
@filter = filter.sub(' ', '').split(',')
|
11
|
+
end
|
12
|
+
|
13
|
+
def match?(data)
|
14
|
+
data.to_s.include? filter[1]
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect_hash(data)
|
18
|
+
data.any? do |key, value|
|
19
|
+
if value.is_a?(Array)
|
20
|
+
match?(value) if key == filter[0]
|
21
|
+
elsif value.is_a?(Hash)
|
22
|
+
process(value)
|
20
23
|
else
|
21
|
-
|
24
|
+
match?(value) if key == filter[0]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def process(data)
|
30
|
+
if data.is_a?(Array)
|
31
|
+
data.select do |value|
|
32
|
+
process(value)
|
22
33
|
end
|
34
|
+
elsif data.is_a?(Hash)
|
35
|
+
inspect_hash(data)
|
23
36
|
end
|
24
37
|
end
|
25
38
|
end
|
data/lib/sensu-cli/settings.rb
CHANGED
@@ -11,8 +11,7 @@ module SensuCli
|
|
11
11
|
def create(directory, file)
|
12
12
|
FileUtils.mkdir_p(directory) unless File.directory?(directory)
|
13
13
|
FileUtils.cp(File.join(File.dirname(__FILE__), '../../settings.example.rb'), file)
|
14
|
-
|
15
|
-
exit
|
14
|
+
SensuCli::die(0, "We created the configuration file for you at #{file}. You can also place this in /etc/sensu/sensu-cli. Edit the settings as needed.".color(:red))
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
data/lib/sensu-cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Brandau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|