sensu-cli 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/sensu +1 -1
- data/bin/sensu-cli +1 -1
- data/lib/sensu-cli/api.rb +60 -0
- data/lib/sensu-cli/base.rb +14 -65
- data/lib/sensu-cli/cli.rb +1 -0
- data/lib/sensu-cli/editor.rb +4 -6
- data/lib/sensu-cli/path.rb +4 -0
- data/lib/sensu-cli/pretty.rb +2 -0
- data/lib/sensu-cli/settings.rb +1 -0
- data/lib/sensu-cli/version.rb +1 -1
- data/lib/sensu-cli.rb +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTNkNGJlNWUzNzViYjgwYTYyYmVkOGQ0MzdkMzM5YjAyY2Q1ODdjMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzJlM2Q0MmRmOTg2YjA1ZGY2YmYxNzY2MjAwYzIwNDEwMTBiM2U4NQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDcyNDdhYTRhOWUwZmNlOWNiZTA2Y2I4ZTU4Y2NkZWNkNTliYmFkOTk4NTlh
|
10
|
+
M2M2YzMxNWJlZGRkN2Q1MGNlMGJhNzcyZGUwNzM5MzFlZWY2NDhhYzZkNDZh
|
11
|
+
OTE2Y2M4MDg4OWZmNjJiOGM0NTkxMDQyMmM5YTcwYzlhYTdiMGM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmIxZWZhYzc3MmI5MjI0OTcxMjY0ZjkzMGRjYzAxYTkwNmZmZTIyZjU2ODg0
|
14
|
+
YzE5YjlhZjMxNWY0MjUyNDc2YmZiNTQ3MWYyOWRlZWI3MjFjYWUxMWYwZjIz
|
15
|
+
ZGY0NDQ1MWJhOWRkNTMyYmJjYTFkZDU5ODNkMWJiNzg3MTJhZDY=
|
data/bin/sensu
CHANGED
data/bin/sensu-cli
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'json'
|
3
|
+
require 'rainbow'
|
4
|
+
|
5
|
+
module SensuCli
|
6
|
+
class Api
|
7
|
+
|
8
|
+
def request(opts)
|
9
|
+
http = Net::HTTP.new(opts[:host], opts[:port])
|
10
|
+
http.read_timeout = 15
|
11
|
+
http.open_timeout = 5
|
12
|
+
if opts[:ssl]
|
13
|
+
http.use_ssl = true
|
14
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
15
|
+
end
|
16
|
+
case opts[:method]
|
17
|
+
when 'Get'
|
18
|
+
req = Net::HTTP::Get.new(opts[:path])
|
19
|
+
when 'Delete'
|
20
|
+
req = Net::HTTP::Delete.new(opts[:path])
|
21
|
+
when 'Post'
|
22
|
+
req = Net::HTTP::Post.new(opts[:path],initheader = {'Content-Type' => 'application/json'})
|
23
|
+
req.body = opts[:payload]
|
24
|
+
end
|
25
|
+
req.basic_auth(opts[:user], opts[:password]) if opts[:user] && opts[:password]
|
26
|
+
begin
|
27
|
+
http.request(req)
|
28
|
+
rescue Timeout::Error
|
29
|
+
puts "HTTP request has timed out.".color(:red)
|
30
|
+
exit
|
31
|
+
rescue StandardError => e
|
32
|
+
puts "An HTTP error occurred. Check your settings. #{e}".color(:red)
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def response(code,body,command=nil)
|
38
|
+
case code
|
39
|
+
when '200'
|
40
|
+
JSON.parse(body)
|
41
|
+
when '201'
|
42
|
+
puts "The stash has been created." if command == "stashes" || command == "silence"
|
43
|
+
when '202'
|
44
|
+
puts "The item was submitted for processing."
|
45
|
+
when '204'
|
46
|
+
puts "Sensu is healthy" if command == 'health'
|
47
|
+
puts "The item was successfully deleted." if command == 'aggregates' || command == 'stashes'
|
48
|
+
when '400'
|
49
|
+
puts "The payload is malformed.".color(:red)
|
50
|
+
when '401'
|
51
|
+
puts "The request requires user authentication.".color(:red)
|
52
|
+
when '404'
|
53
|
+
puts "The item did not exist.".color(:cyan)
|
54
|
+
else
|
55
|
+
(command == 'health') ? (puts "Sensu is not healthy.".color(:red)) : (puts "There was an error while trying to complete your request. Response code: #{code}".color(:red))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/sensu-cli/base.rb
CHANGED
@@ -1,13 +1,3 @@
|
|
1
|
-
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
2
|
-
require 'net/https'
|
3
|
-
require 'json'
|
4
|
-
require 'sensu-cli/settings'
|
5
|
-
require 'sensu-cli/cli'
|
6
|
-
require 'sensu-cli/editor'
|
7
|
-
require 'sensu-cli/pretty'
|
8
|
-
require 'sensu-cli/path.rb'
|
9
|
-
require 'rainbow'
|
10
|
-
|
11
1
|
module SensuCli
|
12
2
|
class Base
|
13
3
|
|
@@ -15,7 +5,6 @@ module SensuCli
|
|
15
5
|
clis = Cli.new
|
16
6
|
cli = clis.global
|
17
7
|
settings
|
18
|
-
@command = cli[:command]
|
19
8
|
api_path(cli)
|
20
9
|
make_call
|
21
10
|
end
|
@@ -36,67 +25,27 @@ module SensuCli
|
|
36
25
|
|
37
26
|
def api_path(cli)
|
38
27
|
p = PathCreator.new
|
39
|
-
p.respond_to?(
|
28
|
+
p.respond_to?(cli[:command]) ? path = p.send(cli[:command], cli) : (puts "Something Bad Happened";exit)
|
40
29
|
@api = {:path => path[:path], :method => cli[:method], :command => cli[:command], :payload => (path[:payload] || false)}
|
41
30
|
end
|
42
31
|
|
43
|
-
def http_request
|
44
|
-
http = Net::HTTP.new(Config.host, Config.port)
|
45
|
-
http.read_timeout = 15
|
46
|
-
http.open_timeout = 5
|
47
|
-
if Config.ssl
|
48
|
-
http.use_ssl = true
|
49
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
50
|
-
end
|
51
|
-
case @api[:method]
|
52
|
-
when 'Get'
|
53
|
-
req = Net::HTTP::Get.new(@api[:path])
|
54
|
-
when 'Delete'
|
55
|
-
req = Net::HTTP::Delete.new(@api[:path])
|
56
|
-
when 'Post'
|
57
|
-
req = Net::HTTP::Post.new(@api[:path],initheader = {'Content-Type' => 'application/json'})
|
58
|
-
req.body = @api[:payload]
|
59
|
-
end
|
60
|
-
req.basic_auth(Config.user, Config.password) if Config.user && Config.password
|
61
|
-
begin
|
62
|
-
http.request(req)
|
63
|
-
rescue Timeout::Error
|
64
|
-
puts "HTTP request has timed out.".color(:red)
|
65
|
-
exit
|
66
|
-
rescue StandardError => e
|
67
|
-
puts "An HTTP error occurred. Check your settings. #{e}".color(:red)
|
68
|
-
exit
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
32
|
def make_call
|
73
|
-
|
74
|
-
|
33
|
+
opts = {
|
34
|
+
:path => @api[:path],
|
35
|
+
:method => @api[:method],
|
36
|
+
:payload => @api[:payload],
|
37
|
+
:host => Config.host,
|
38
|
+
:port => Config.port,
|
39
|
+
:ssl => Config.ssl || false,
|
40
|
+
:user => Config.user || nil,
|
41
|
+
:password => Config.password || nil
|
42
|
+
}
|
43
|
+
api = Api.new
|
44
|
+
res = api.request(opts)
|
45
|
+
msg = api.response(res.code, res.body, @api[:command])
|
75
46
|
res.code != '200' ? exit : Pretty.print(msg)
|
76
47
|
Pretty.count(msg)
|
77
48
|
end
|
78
49
|
|
79
|
-
def response_codes(code,body)
|
80
|
-
case code
|
81
|
-
when '200'
|
82
|
-
JSON.parse(body)
|
83
|
-
when '201'
|
84
|
-
puts "The stash has been created." if @command == "stashes" || @command == "silence"
|
85
|
-
when '202'
|
86
|
-
puts "The item was submitted for processing."
|
87
|
-
when '204'
|
88
|
-
puts "Sensu is healthy" if @command == 'health'
|
89
|
-
puts "The item was successfully deleted." if @command == 'aggregates' || @command == 'stashes'
|
90
|
-
when '400'
|
91
|
-
puts "The payload is malformed.".color(:red)
|
92
|
-
when '401'
|
93
|
-
puts "The request requires user authentication.".color(:red)
|
94
|
-
when '404'
|
95
|
-
puts "The item did not exist.".color(:cyan)
|
96
|
-
else
|
97
|
-
(@command == 'health') ? (puts "Sensu is not healthy.".color(:red)) : (puts "There was an error while trying to complete your request. Response code: #{code}".color(:red))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
50
|
end
|
102
51
|
end
|
data/lib/sensu-cli/cli.rb
CHANGED
data/lib/sensu-cli/editor.rb
CHANGED
@@ -5,12 +5,11 @@ module SensuCli
|
|
5
5
|
class Editor
|
6
6
|
|
7
7
|
def create_stash(create_path)
|
8
|
-
|
9
|
-
file
|
10
|
-
open(file)
|
8
|
+
file = temp_file({:path => create_path, :content => {:timestamp => Time.now.to_i }})
|
9
|
+
edit(file)
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
12
|
+
def edit(file)
|
14
13
|
ENV['EDITOR'] ? editor = ENV['EDITOR'] : editor = 'vi'
|
15
14
|
system("#{editor} #{file}")
|
16
15
|
begin
|
@@ -21,8 +20,7 @@ module SensuCli
|
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
def
|
25
|
-
template = {:path => @create_path, :content => {:timestamp => Time.now.to_i }}
|
23
|
+
def temp_file(template)
|
26
24
|
file = Tempfile.new('sensu')
|
27
25
|
file.write(JSON.pretty_generate(template))
|
28
26
|
file.close
|
data/lib/sensu-cli/path.rb
CHANGED
data/lib/sensu-cli/pretty.rb
CHANGED
data/lib/sensu-cli/settings.rb
CHANGED
data/lib/sensu-cli/version.rb
CHANGED
data/lib/sensu-cli.rb
CHANGED
@@ -1,2 +1,11 @@
|
|
1
|
+
require 'sensu-cli/settings'
|
2
|
+
require 'sensu-cli/cli'
|
3
|
+
require 'sensu-cli/editor'
|
4
|
+
require 'sensu-cli/pretty'
|
5
|
+
require 'sensu-cli/path.rb'
|
6
|
+
require 'sensu-cli/api.rb'
|
7
|
+
require 'sensu-cli/base.rb'
|
8
|
+
require 'sensu-cli/version.rb'
|
9
|
+
|
1
10
|
module SensuCli
|
2
11
|
end
|
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.2.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: 2013-
|
11
|
+
date: 2013-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- bin/sensu
|
64
64
|
- bin/sensu-cli
|
65
|
+
- lib/sensu-cli/api.rb
|
65
66
|
- lib/sensu-cli/base.rb
|
66
67
|
- lib/sensu-cli/cli.rb
|
67
68
|
- lib/sensu-cli/editor.rb
|