sensu-cli 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Mjk0ZjhhMjdkYjBjMzE1ODQwZTdhNmU3NWEyZDU1MGU5YWRkZTdiOQ==
5
- data.tar.gz: !binary |-
6
- ODgyZTA5OThlMjlmYWFlODVkY2Y4MjRkYTBmNmMwZjM5MThkNGJjMQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- M2U4NzY3MTlkNmI4YzM0MjYxNzRhZTQwZjNiMGZlZTg1YWU1MzU1ODY1Nzk0
10
- NjY5YWMyZWU2MzNmOTVjMGJmZTMyMjQ4NzBiMGQ5NGFjN2Y0OTg4ODc3YmUy
11
- ODUzOGY1M2RiMDc5OTc4MmJiMWI2OTE3ZWZmYTY5MzQxY2IwZDc=
12
- data.tar.gz: !binary |-
13
- YmYyNTU5MzUwYzQ5N2E4OTNiODRmY2Q2NjMyY2ZmNTBmNTJjYjcwZmI4YTky
14
- Yzk2M2NhNTliNzdmZTkzMzQ5NTAyN2EwZTU5MjEyYTkwNDBjZmRmYjliYWZm
15
- NzU4NDlmNDVmYmFiNzk0ODgzYTBkOTU4YmZlY2U1YTJkZWIxMWM=
2
+ SHA1:
3
+ metadata.gz: b624e824d48454f911f02c14d4c06058683c5adb
4
+ data.tar.gz: 707b5fa3ea1c9be3fa6353e10760dccb77a90f30
5
+ SHA512:
6
+ metadata.gz: 3306b9df492dd691806e05be10990047c997e01bc9d8f4d17727fcb3a1c0be1b018a1874777803288d50ceb592fe9788127d468d4efc3ae25cd92d5b8ab8a141
7
+ data.tar.gz: aef133f48f50ed3b9fc95a56a4c6ff1d06f07aa3cde98ee1e13899f922e1ee7960285faab5dd39666dfa99469fb87d89f4b6f9055fe2809c60eae75917e1655b
data/README.md CHANGED
@@ -47,7 +47,9 @@ This format was chosen so you can do some ENV magic via your profile and setting
47
47
  `ssl` Boolean - Optional - Defaults False
48
48
  `read_timeout` Integer - Optional - Default 15 (seconds)
49
49
  `open_timeout` Integer - Optional - Default 5 (seconds)
50
- `pretty_colors` Boolean - Optional - Default True
50
+ `pretty_colors` Boolean - Optional - Default True
51
+ `proxy_address` String - Optional
52
+ `proxy_port` Integer - Optional
51
53
 
52
54
  Examples
53
55
  -----------
data/lib/sensu-cli/api.rb CHANGED
@@ -5,7 +5,8 @@ require 'rainbow/ext/string'
5
5
  module SensuCli
6
6
  class Api
7
7
  def request(opts)
8
- http = Net::HTTP.new(opts[:host], opts[:port])
8
+ http = Net::HTTP.new(opts[:host], opts[:port], opts[:proxy_address],
9
+ opts[:proxy_port])
9
10
  http.read_timeout = opts[:read_timeout]
10
11
  http.open_timeout = opts[:open_timeout]
11
12
  if opts[:ssl]
@@ -39,24 +39,26 @@ module SensuCli
39
39
  :user => Config.user || nil,
40
40
  :read_timeout => Config.read_timeout || 15,
41
41
  :open_timeout => Config.open_timeout || 5,
42
- :password => Config.password || nil
42
+ :password => Config.password || nil,
43
+ :proxy_address => Config.proxy_address || :ENV,
44
+ :proxy_port => Config.proxy_port || nil
43
45
  }
44
46
  api = Api.new
45
47
  res = api.request(opts)
46
48
  msg = api.response(res.code, res.body, @api[:command])
47
49
  msg = Filter.new(@cli[:fields][:filter]).process(msg) if @cli[:fields][:filter]
50
+ endpoint = @api[:command]
48
51
  if res.code != '200'
49
52
  SensuCli::die(0)
50
53
  elsif @cli[:fields][:format] == 'single'
51
- Pretty.single(msg)
54
+ Pretty.single(msg, endpoint)
52
55
  elsif @cli[:fields][:format] == 'table'
53
- endpoint = @api[:command]
54
56
  fields = nil || @cli[:fields][:fields]
55
57
  Pretty.table(msg, endpoint, fields)
56
58
  elsif @cli[:fields][:format] == 'json'
57
59
  Pretty.json(msg)
58
60
  else
59
- Pretty.print(msg)
61
+ Pretty.print(msg, endpoint)
60
62
  end
61
63
  Pretty.count(msg) unless @cli[:fields][:format] == 'table'
62
64
  end
data/lib/sensu-cli/cli.rb CHANGED
@@ -206,7 +206,7 @@ module SensuCli
206
206
  case command
207
207
  when 'list'
208
208
  p = Trollop::options do
209
- opt :filter, 'Field and value to filter on: client,graphite', :type => :string
209
+ opt :filter, 'Field and value to filter on: client,graphite (use "name" as field for client or event name)', :type => :string
210
210
  opt :format, 'Available formats; single, table, json', :short => 'f', :type => :string
211
211
  end
212
212
  Trollop::die :format, 'Available optional formats: single, table, json'.color(:red) if p[:format] != 'table' && p[:format] != 'single' && p[:format] != 'json' && p[:format]
@@ -1,30 +1,37 @@
1
1
  require 'rainbow/ext/string'
2
2
  require 'hirb'
3
3
  require 'json'
4
+ require 'erubis'
4
5
 
5
6
  module SensuCli
6
7
  class Pretty
7
8
  class << self
8
- def print(res)
9
- if !res.empty?
10
- if res.is_a?(Hash)
11
- res.each do |key, value|
12
- puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
13
- end
14
- elsif res.is_a?(Array)
15
- res.each do |item|
16
- puts '-------'.color(:yellow)
17
- if item.is_a?(Hash)
18
- item.each do |key, value|
19
- puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
20
- end
21
- else
22
- puts item.to_s.color(:cyan)
9
+ def print(res, endpoint = nil)
10
+ return no_values if res.empty?
11
+ case endpoint
12
+ when 'events'
13
+ template = File.read('lib/sensu-cli/templates/event.erb')
14
+ renderer = Erubis::Eruby.new(template)
15
+ res.each do |event|
16
+ puts renderer.result(event)
17
+ end
18
+ return
19
+ end
20
+ if res.is_a?(Hash)
21
+ res.each do |key, value|
22
+ puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
23
+ end
24
+ elsif res.is_a?(Array)
25
+ res.each do |item|
26
+ puts '-------'.color(:yellow)
27
+ if item.is_a?(Hash)
28
+ item.each do |key, value|
29
+ puts "#{key}: ".color(:cyan) + "#{value}".color(:green)
23
30
  end
31
+ else
32
+ puts item.to_s.color(:cyan)
24
33
  end
25
34
  end
26
- else
27
- no_values
28
35
  end
29
36
  end
30
37
 
@@ -46,39 +53,38 @@ module SensuCli
46
53
  puts 'no values for this request'.color(:cyan)
47
54
  end
48
55
 
49
- def single(res)
50
- if !res.empty?
51
- if res.is_a?(Array)
52
- keys = res.map { |item| item.keys }.flatten.uniq.sort
56
+ def single(res, endpoint = nil)
57
+ return no_values if res.empty?
58
+ case endpoint
59
+ when 'events'
60
+ res = event_data(res)
61
+ end
62
+ keys = res.map { |item| item.keys }.flatten.uniq.sort
53
63
 
54
- # Remove fields with spaces (breaks awkage)
55
- keys.select! do |key|
56
- res.none? { |item| item[key].to_s.include?(' ') }
57
- end
64
+ # Remove fields with spaces (breaks awkage)
65
+ keys.select! do |key|
66
+ res.none? { |item| item[key].to_s.include?(' ') }
67
+ end
58
68
 
59
- # Find max value lengths
60
- value_lengths = {}
61
- keys.each do |key|
62
- max_value_length = res.map { |item| item[key].to_s.length }.max
63
- value_lengths[key] = [max_value_length, key.length].max
64
- end
69
+ # Find max value lengths
70
+ value_lengths = {}
71
+ keys.each do |key|
72
+ max_value_length = res.map { |item| item[key].to_s.length }.max
73
+ value_lengths[key] = [max_value_length, key.length].max
74
+ end
65
75
 
66
- # Print header
67
- lengths = keys.map { |key| "%-#{value_lengths[key]}s" }.join(' ')
68
- puts format(lengths, *keys)
76
+ # Print header
77
+ lengths = keys.map { |key| "%-#{value_lengths[key]}s" }.join(' ')
78
+ puts format(lengths, *keys)
69
79
 
70
- # Print value rows
71
- res.each do |item|
72
- if item.is_a?(Hash)
73
- values = keys.map { |key| item[key] }
74
- puts format(lengths, *values)
75
- else
76
- puts item.to_s.color(:cyan)
77
- end
78
- end
80
+ # Print value rows
81
+ res.each do |item|
82
+ if item.is_a?(Hash)
83
+ values = keys.map { |key| item[key] }
84
+ puts format(lengths, *values)
85
+ else
86
+ puts item.to_s.color(:cyan)
79
87
  end
80
- else
81
- no_values
82
88
  end
83
89
  end
84
90
 
@@ -86,25 +92,45 @@ module SensuCli
86
92
  fields.split(',')
87
93
  end
88
94
 
89
- def table(res, endpoint, fields = nil)
90
- if !res.empty?
91
- if res.is_a?(Array)
92
- terminal_size = Hirb::Util.detect_terminal_size
93
- if endpoint == 'events'
94
- keys = %w(check client status flapping occurrences handlers issued output)
95
- else
96
- if fields
97
- keys = parse_fields(fields)
98
- else
99
- keys = res.map { |item| item.keys }.flatten.uniq
100
- end
101
- end
102
- puts Hirb::Helpers::AutoTable.render(res, :max_width => terminal_size[0], :fields => keys)
103
- end
95
+ def event_data(res)
96
+ events = []
97
+ res.each do |event|
98
+ events << {
99
+ 'client' => event['client']['name'],
100
+ 'address' => event['client']['address'],
101
+ 'check' => event['check']['name'],
102
+ 'interval' => event['check']['interval'],
103
+ 'occurrences' => event['occurrences'],
104
+ 'status' => event['check']['status'],
105
+ 'handlers' => event['check']['handlers'],
106
+ 'issued' => event['check']['issued'],
107
+ 'executed' => event['check']['executed'],
108
+ 'output' => event['check']['output'].rstrip
109
+ }
110
+ end
111
+ events
112
+ end
113
+
114
+ def table(res, endpoint = nil, fields = nil)
115
+ return no_values if res.empty?
116
+ case endpoint
117
+ when 'events'
118
+ keys = %w(check client address interval occurrences status handlers issued executed output)
119
+ render_table(event_data(res), keys)
104
120
  else
105
- no_values
121
+ if fields
122
+ keys = parse_fields(fields)
123
+ else
124
+ keys = res.map { |item| item.keys }.flatten.uniq
125
+ end
126
+ render_table(res, keys)
106
127
  end
107
128
  end
129
+
130
+ def render_table(data, keys)
131
+ terminal_size = Hirb::Util.detect_terminal_size
132
+ puts Hirb::Helpers::AutoTable.render(data, :max_width => terminal_size[0], :fields => keys)
133
+ end
108
134
  end
109
135
  end
110
136
  end
@@ -0,0 +1,20 @@
1
+ <%= "-------".color(:yellow) %>
2
+ <%= "id:".color(:blue).bright %> <%= id.to_s.color(:green) %>
3
+ <%= "client name:".color(:blue).bright %> <%= client['name'].to_s.color(:green) %>
4
+ <%= "address:".color(:cyan) %> <%= client['address'].to_s.color(:green) %>
5
+ <%= "subscriptions:".color(:cyan) %> <%= client['subscriptions'].to_s.color(:green) %>
6
+ <%= "version:".color(:cyan) %> <%= client['version'].to_s.color(:green) %>
7
+ <%= "timestamp:".color(:cyan) %> <%= client['timestamp'].to_s.color(:green) %>
8
+ <%= "check name:".color(:blue).bright %> <%= check['name'].to_s.color(:green) %>
9
+ <%= "command:".color(:cyan) %> <%= check['command'].to_s.color(:green) %>
10
+ <%= "handlers:".color(:cyan) %> <%= check['handlers'].to_s.color(:green) %>
11
+ <%= "interval:".color(:cyan) %> <%= check['interval'].to_s.color(:green) %>
12
+ <%= "subscribers:".color(:cyan) %> <%= check['subscribers'].to_s.color(:green) %>
13
+ <%= "issued:".color(:cyan) %> <%= check['issued'].to_s.color(:green) %>
14
+ <%= "executed:".color(:cyan) %> <%= check['executed'].to_s.color(:green) %>
15
+ <%= "duration:".color(:cyan) %> <%= check['duration'].to_s.color(:green) %>
16
+ <%= "output:".color(:cyan) %> <%= check['output'].rstrip.to_s.color(:green) %>
17
+ <%= "status:".color(:cyan) %> <%= check['status'].to_s.color(:green) %>
18
+ <%= "history:".color(:cyan) %> <%= check['history'].to_s.color(:green) %>
19
+ <%= "occurrences:".color(:blue).bright %> <%= occurrences.to_s.color(:green) %>
20
+ <%= "action:".color(:blue).bright %> <%= action.to_s.color(:green) %>
@@ -1,3 +1,3 @@
1
1
  module SensuCli
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/sensu-cli.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency('trollop', '2.0')
17
17
  s.add_dependency('mixlib-config', '2.1.0')
18
18
  s.add_dependency('hirb', '0.7.1')
19
+ s.add_dependency('erubis', '2.7.0')
19
20
 
20
21
  s.add_development_dependency('rspec')
21
22
  s.add_development_dependency('rubocop')
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.5.0
4
+ version: 0.6.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 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -66,32 +66,46 @@ dependencies:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.7.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: erubis
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.7.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.7.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ! '>='
87
+ - - '>='
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ! '>='
94
+ - - '>='
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ! '>='
101
+ - - '>='
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ! '>='
108
+ - - '>='
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  description: A command line utility for interacting with the Sensu api.
@@ -102,8 +116,10 @@ executables:
102
116
  extensions: []
103
117
  extra_rdoc_files: []
104
118
  files:
119
+ - README.md
105
120
  - bin/sensu
106
121
  - bin/sensu-cli
122
+ - lib/sensu-cli.rb
107
123
  - lib/sensu-cli/api.rb
108
124
  - lib/sensu-cli/base.rb
109
125
  - lib/sensu-cli/cli.rb
@@ -112,10 +128,9 @@ files:
112
128
  - lib/sensu-cli/path.rb
113
129
  - lib/sensu-cli/pretty.rb
114
130
  - lib/sensu-cli/settings.rb
131
+ - lib/sensu-cli/templates/event.erb
115
132
  - lib/sensu-cli/version.rb
116
- - lib/sensu-cli.rb
117
133
  - sensu-cli.gemspec
118
- - README.md
119
134
  - settings.example.rb
120
135
  homepage: http://github.com/agent462/sensu-cli
121
136
  licenses:
@@ -128,17 +143,17 @@ require_paths:
128
143
  - lib
129
144
  required_ruby_version: !ruby/object:Gem::Requirement
130
145
  requirements:
131
- - - ! '>='
146
+ - - '>='
132
147
  - !ruby/object:Gem::Version
133
148
  version: '0'
134
149
  required_rubygems_version: !ruby/object:Gem::Requirement
135
150
  requirements:
136
- - - ! '>='
151
+ - - '>='
137
152
  - !ruby/object:Gem::Version
138
153
  version: '0'
139
154
  requirements: []
140
155
  rubyforge_project:
141
- rubygems_version: 2.0.3
156
+ rubygems_version: 2.2.2
142
157
  signing_key:
143
158
  specification_version: 4
144
159
  summary: A command line utility for Sensu.