sensu-cli 0.6.3 → 0.7.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
- NzZlY2RkYTliOTM4ZjIxZjRlNWNkNDViOTZkNTdjNzQzZTVhNDY4OQ==
5
- data.tar.gz: !binary |-
6
- MzFlZGM2ZGUxZDRhZmQ4NmY2ZGZlNWNjZTc1ZTdlYzJkNTNmMjg1Zg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YjU1MTQ1NTBkYjg5NDlmZjM4ZWQyMGJkOGEwMjEzNGMzNWUwNTU3ZTM0Y2Q5
10
- MGM3YjVkMzQzYTFjYjI1OWQ0OTdiMGI0MjJmNzhmMjVhNTE2MGQwOWMxYmZj
11
- MmUwZGFlYTUwM2FmYzMwN2UxNTk1YWUzOTY2MGYyNDQ2MTZkMDg=
12
- data.tar.gz: !binary |-
13
- YTg5MTA4NGVkNGVhMjM1MTc5NWE5OTc4YjQ0MjQ5MjBkMzMxM2Y3OTgxMTQx
14
- M2IyYmVmZDFhNjJkZTM0YmY5ZDY0ODc2NmZmYmI4NWJkYjc3ZDlmYWIxZWFk
15
- MDZmMWYwMzJmODczNjM0N2Q4NDViNTEzODZiNmJjYjRlMmVlZGI=
2
+ SHA1:
3
+ metadata.gz: 854aa85dfba14210e13adefaba1ff9baa21279af
4
+ data.tar.gz: e5afa7923f4ba3dc88ad92130478bedae923c0ca
5
+ SHA512:
6
+ metadata.gz: 1025529356b48ff380ce2729e7b36ce95cc4fdf3f00e34b34843df6eaf173b2caf2f0aae9aec26434491d90abf571a3cfa1667197eb5112963e4aeeec1f1225b
7
+ data.tar.gz: cba672217a1d45e04507c86499acc6a478721bd1cd3d9455f5b629c57ba1f5dffe43c9aa5146f30736d278b6ccbad96c3c48dccaeb9ac8d4d48e58a89416d34f
data/README.md CHANGED
@@ -36,22 +36,24 @@ Usage and Configuration
36
36
  host "127.0.0.1"
37
37
  port "4567"
38
38
  ssl false
39
+ api_endpoint "/api"
39
40
  read_timeout 20
40
41
  open_timeout 20
41
42
  ````
42
43
  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
44
 
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)
45
+ * All Configuration Settings
46
+ `host` String - Required - Host of the Sensu API
47
+ `port` String/Integer - Required - Port of the Sensu API
48
+ `ssl` Boolean - Optional - Defaults False
49
+ `api_endpoint` String - Optional - Default ''
50
+ `read_timeout` Integer - Optional - Default 15 (seconds)
51
+ `open_timeout` Integer - Optional - Default 5 (seconds)
50
52
  `pretty_colors` Boolean - Optional - Default True
51
53
  `proxy_address` String - Optional
52
54
  `proxy_port` Integer - Optional
53
- `user` String - Optional
54
- `password` String - Optional
55
+ `user` String - Optional - User for the Sensu API
56
+ `password` String - Optional - Password for the Sensu API
55
57
 
56
58
  Examples
57
59
  -----------
@@ -97,10 +99,40 @@ sensu-cli stash create PATH
97
99
  ** Resolve Commands **
98
100
  sensu-cli resolve NODE CHECK
99
101
 
102
+ ** Socket Commands **
103
+ sensu-cli socket create (OPTIONS)
104
+ sensu-cli socket raw INPUT
105
+
100
106
  --version, -v: Print version and exit
101
107
  --help, -h: Show this message
102
108
  ````
103
109
 
110
+ Filters
111
+ -------
112
+
113
+ Filters are strings in 'key,value' format.
114
+
115
+ ````
116
+ Examples:
117
+
118
+ # show all events with name matching 'foo'
119
+ sensu-cli event list -i name,foo
120
+
121
+ # show all events whose output matches 'foo'
122
+ sensu-cli event list -i output,foo
123
+ ````
124
+
125
+ Socket
126
+ -------
127
+ This command can only be used on a host that is running sensu-client. sensu-client exposes a socket for arbritary check results. For more information you can see the [sensu client documentation](https://sensuapp.org/docs/0.18/clients#client-socket-input).
128
+ ````
129
+ # send a check result to the sensu server
130
+ sensu-cli socket create -name "host33" --output "Something broke really bad" --status 1
131
+
132
+ # send raw json check result to the sensu server
133
+ sensu-cli socket raw '{"name": "host34", "output": "Something broke even worse than on host33", "status": 1}'
134
+ ````
135
+
104
136
  Contributions
105
137
  -------------
106
138
  Please provide a pull request. I'm an ops guy, not a developer, so if you're submitting code cleanup, all I ask is that you explain the improvement so I can learn.
@@ -7,6 +7,7 @@ require 'sensu-cli/api.rb'
7
7
  require 'sensu-cli/base.rb'
8
8
  require 'sensu-cli/version.rb'
9
9
  require 'sensu-cli/filter.rb'
10
+ require 'sensu-cli/client/socket.rb'
10
11
 
11
12
  module SensuCli
12
13
  def self.die(code = 0, msg = nil)
@@ -1,10 +1,22 @@
1
1
  module SensuCli
2
2
  class Base
3
+ attr_accessor :cli
3
4
  def setup
4
- @cli = Cli.new.global
5
+ self.cli = Cli.new.global
5
6
  settings
6
- api_path(@cli)
7
- make_call
7
+ if cli[:command] == 'socket'
8
+ socket
9
+ else
10
+ api_path(cli)
11
+ make_call
12
+ end
13
+ end
14
+
15
+ def socket
16
+ socket = SensuCli::Client::Socket.new
17
+ socket.format_message(cli[:fields]) if cli[:method] == 'create'
18
+ socket.message = cli[:raw] if cli[:method] == 'raw'
19
+ socket.send_udp_message
8
20
  end
9
21
 
10
22
  def settings
@@ -46,21 +58,21 @@ module SensuCli
46
58
  api = Api.new
47
59
  res = api.request(opts)
48
60
  msg = api.response(res.code, res.body, @api[:command])
49
- msg = Filter.new(@cli[:fields][:filter]).process(msg) if @cli[:fields][:filter]
61
+ msg = Filter.new(cli[:fields][:filter]).process(msg) if cli[:fields][:filter]
50
62
  endpoint = @api[:command]
51
63
  if res.code != '200'
52
64
  SensuCli::die(0)
53
- elsif @cli[:fields][:format] == 'single'
65
+ elsif cli[:fields][:format] == 'single'
54
66
  Pretty.single(msg, endpoint)
55
- elsif @cli[:fields][:format] == 'table'
56
- fields = nil || @cli[:fields][:fields]
67
+ elsif cli[:fields][:format] == 'table'
68
+ fields = nil || cli[:fields][:fields]
57
69
  Pretty.table(msg, endpoint, fields)
58
- elsif @cli[:fields][:format] == 'json'
70
+ elsif cli[:fields][:format] == 'json'
59
71
  Pretty.json(msg)
60
72
  else
61
73
  Pretty.print(msg, endpoint)
62
74
  end
63
- Pretty.count(msg) unless @cli[:fields][:format] == 'table' or @cli[:fields][:format] == 'json'
75
+ Pretty.count(msg) unless cli[:fields][:format] == 'table' or cli[:fields][:format] == 'json'
64
76
  end
65
77
  end
66
78
  end
@@ -4,7 +4,7 @@ require 'rainbow/ext/string'
4
4
 
5
5
  module SensuCli
6
6
  class Cli # rubocop:disable ClassLength
7
- SUB_COMMANDS = %w(info client check event stash aggregate silence resolve health)
7
+ SUB_COMMANDS = %w(info client check event stash aggregate silence resolve health socket)
8
8
  CLIENT_COMMANDS = %w(list show delete history)
9
9
  CHECK_COMMANDS = %w(list show request)
10
10
  EVENT_COMMANDS = %w(list show delete)
@@ -14,6 +14,7 @@ module SensuCli
14
14
  RES_COMMANDS = ''
15
15
  INFO_COMMANDS = ''
16
16
  HEALTH_COMMANDS = ''
17
+ SOCKET_COMMANDS = %w(create raw)
17
18
 
18
19
  CLIENT_BANNER = <<-EOS.gsub(/^ {10}/, '')
19
20
  ** Client Commands **
@@ -63,7 +64,11 @@ module SensuCli
63
64
  ** Resolve Commands **
64
65
  sensu-cli resolve NODE CHECK\n\r
65
66
  EOS
66
-
67
+ SOCKET_BANNER = <<-EOS.gsub(/^ {10}/, '')
68
+ ** Socket Commands **
69
+ sensu-cli socket create (OPTIONS)
70
+ sensu-cli socket raw INPUT\n\r
71
+ EOS
67
72
  def global
68
73
  global_opts = Trollop::Parser.new do
69
74
  version "sensu-cli version: #{SensuCli::VERSION}"
@@ -90,6 +95,7 @@ module SensuCli
90
95
  banner SIL_BANNER
91
96
  banner STASH_BANNER
92
97
  banner RES_BANNER
98
+ banner SOCKET_BANNER
93
99
  stop_on SUB_COMMANDS
94
100
  end
95
101
 
@@ -309,5 +315,26 @@ module SensuCli
309
315
  ARGV.empty? ? explode(opts) : check = next_argv
310
316
  deep_merge({ :command => 'resolve', :method => 'Post', :fields => { :client => command, :check => check } }, { :fields => p })
311
317
  end
318
+
319
+ def socket
320
+ opts = parser('SOCKET')
321
+ command = next_argv
322
+ explode_if_empty(opts, command)
323
+ case command
324
+ when 'create'
325
+ p = Trollop::options do
326
+ opt :name, 'The check name to report as', :short => 'n', :type => :string, :required => true
327
+ opt :output, 'The check result output', :short => 'o', :type => :string, :required => true
328
+ opt :status, 'The check result exit status to indicate severity.', :short => 's', :type => :integer
329
+ # opt :handlers, 'The check result handlers.', :type => :string
330
+ end
331
+ { :command => 'socket', :method => 'create', :fields => p }
332
+ when 'raw'
333
+ p = Trollop::options
334
+ { :command => 'socket', :method => 'raw', :raw => next_argv }
335
+ else
336
+ explode(opts)
337
+ end
338
+ end
312
339
  end
313
340
  end
@@ -0,0 +1,20 @@
1
+ require 'socket'
2
+ require 'json'
3
+
4
+ module SensuCli
5
+ module Client
6
+ class Socket
7
+ attr_accessor :message
8
+
9
+ def send_udp_message
10
+ udp = UDPSocket.new
11
+ udp.send(message, 0, '127.0.0.1', 3030)
12
+ puts 'UDP Socket Message Sent'
13
+ end
14
+
15
+ def format_message(data)
16
+ self.message = { 'name' => data[:name], 'output' => data[:output], 'status' => data[:status] }.to_json
17
+ end
18
+ end
19
+ end
20
+ end
@@ -90,7 +90,7 @@ module SensuCli
90
90
  end
91
91
 
92
92
  def respond(path, payload = false)
93
- { :path => path, :payload => payload }
93
+ { :path => "#{Config.api_endpoint}#{path}", :payload => payload }
94
94
  end
95
95
  end
96
96
  end
@@ -11,7 +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
- 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))
14
+ SensuCli::die(0, "We created the configuration file for you at #{file}. You can also place this in /etc/sensu/sensu-cli/settings.rb. Edit the settings as needed.".color(:red))
15
15
  end
16
16
  end
17
17
 
@@ -1,3 +1,3 @@
1
1
  module SensuCli
2
- VERSION = '0.6.3'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -12,9 +12,9 @@ Gem::Specification.new do |s|
12
12
  s.licenses = %w(MIT APACHE)
13
13
  s.homepage = 'http://github.com/agent462/sensu-cli'
14
14
 
15
- s.add_dependency('rainbow', '2.0.0')
15
+ s.add_dependency('rainbow', '1.99.2')
16
16
  s.add_dependency('trollop', '2.0')
17
- s.add_dependency('mixlib-config', '2.1.0')
17
+ s.add_dependency('mixlib-config', '>=2.1.0')
18
18
  s.add_dependency('hirb', '0.7.1')
19
19
  s.add_dependency('erubis', '2.7.0')
20
20
 
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.6.3
4
+ version: 0.7.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-10-09 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 1.99.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: 1.99.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: trollop
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: mixlib-config
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.1.0
55
55
  - !ruby/object:Gem::Dependency
@@ -84,28 +84,28 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: A command line utility for interacting with the Sensu api.
@@ -116,11 +116,14 @@ executables:
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
+ - README.md
119
120
  - bin/sensu
120
121
  - bin/sensu-cli
122
+ - lib/sensu-cli.rb
121
123
  - lib/sensu-cli/api.rb
122
124
  - lib/sensu-cli/base.rb
123
125
  - lib/sensu-cli/cli.rb
126
+ - lib/sensu-cli/client/socket.rb
124
127
  - lib/sensu-cli/editor.rb
125
128
  - lib/sensu-cli/filter.rb
126
129
  - lib/sensu-cli/path.rb
@@ -128,9 +131,7 @@ files:
128
131
  - lib/sensu-cli/settings.rb
129
132
  - lib/sensu-cli/templates/event.erb
130
133
  - lib/sensu-cli/version.rb
131
- - lib/sensu-cli.rb
132
134
  - sensu-cli.gemspec
133
- - README.md
134
135
  - settings.example.rb
135
136
  homepage: http://github.com/agent462/sensu-cli
136
137
  licenses:
@@ -143,17 +144,17 @@ require_paths:
143
144
  - lib
144
145
  required_ruby_version: !ruby/object:Gem::Requirement
145
146
  requirements:
146
- - - ! '>='
147
+ - - '>='
147
148
  - !ruby/object:Gem::Version
148
149
  version: '0'
149
150
  required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  requirements:
151
- - - ! '>='
152
+ - - '>='
152
153
  - !ruby/object:Gem::Version
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubyforge_project:
156
- rubygems_version: 2.0.3
157
+ rubygems_version: 2.2.2
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: A command line utility for Sensu.