sensu-cli 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjkwOGFmNTA0OWM4MzZhNThkNjE1NDkwYTZjMGNmNzY2YmYyOWQ3NA==
4
+ ZWUwZDFkN2IxNjBjNzJkMmRhMDM0NTYxMjcyMGExODg0M2U0Zjc3Mg==
5
5
  data.tar.gz: !binary |-
6
- MjRkNzBkMTQ0ZWRhNGVkNTRlN2Y5YWVhNjVlODViZmJmNzllMGFmNQ==
6
+ ZGMyNDBjMjkwYmJlYzVhZmE5OWM2NmRjN2JmMThmM2YxZTZkMWI1Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZWE3ZGZiODZhNzdhNTdhZmM3NjU4Zjk1YzRkNGQzNDZmNjQwMjcxNzE2OWZk
10
- ZWE2ZWQzZmNkYTY0OTA5MjU5ODhlMTI4ZThmNDNkYmY2N2JiZWYyZGI1ZDk0
11
- MWNhMzMyNTg3NGMzMzBjNWFjMjVkMGExYTMyZjMzOTg4NDc2NWI=
9
+ YmE4OThmNTNlNTU4Yjk0ODRmMDQ0NWI2M2IxMTYxYzBlZDM5MjVhYWYyYjVi
10
+ Y2ZlNTk5YmFjOTQxNTc4MWQzYzYwOWE0NjQ3YjM2Y2ZjZTI3YzUyNTIwZGJm
11
+ NjQ0OGUzMjNmOWI1MjA3NWI2MzNlMmRkZWQ1MmM0ZTkzZGFkNzQ=
12
12
  data.tar.gz: !binary |-
13
- NTQ3ZjMzMWEyZDliNDk0NGU2NzhiZWU0YjI4NjEzZGEyN2M1MTJjYTg3YTU1
14
- ZDk1ODQ4M2ExZWE3ODg1ZjcwOGMwZTE3ZGJkMTVkOWIxMDJiNmQ5YmI3ODZj
15
- Y2Y0YTUzMzBlOTZhMmI0ZTdkMGYzMmQyMTBhNzdkOTM2NjliN2Y=
13
+ MzAwZDI5NjFhNjczMDVhYzQyY2U5NDQ4ZWNjOTFkMjE4ZDNkOTBkZjk2ZGM4
14
+ ZWFjNTlmZmY2Nzk5YmNhOGYyYzNlM2Y2YTA1ZmVlYzA1ZDQ0ZjNhMjU3ZmI5
15
+ ZDZlZGJlM2RlMjRlZTcwZWQ4MjI5MWQ5ZTBlNWQ5MjlmNzg3NzY=
data/README.md CHANGED
@@ -10,7 +10,7 @@ sensu-cli
10
10
  # ------------------
11
11
  # /\
12
12
  # '--'
13
- # SENSU
13
+ # SENSU-CLI
14
14
  #
15
15
  ```
16
16
  A sensu-cli for interacting with the sensu api.
@@ -51,7 +51,7 @@ password "some_secret_password"
51
51
 
52
52
  Expire Silenced Hosts/Checks
53
53
  ----------------------------
54
- I added an expires option to `sensu silence` to be used like `sensu silence HOST -e 30` where `-e` denotes the number of minutes from now a host/checks silence should expire. This won't work by itself. We add a key to the silence stash with a time in the future. If you run [check-stashes](https://github.com/agent462/sensu-check-stashes) on your sensu-server it will check for expired stashes and delete them.
54
+ I added an expires option to `sensu-cli silence` to be used like `sensu-cli silence HOST -e 30` where `-e` denotes the number of minutes from now a host/checks silence should expire. This won't work by itself. We add a key to the silence stash with a time in the future. If you run [check-stashes](https://github.com/agent462/sensu-check-stashes) on your sensu-server it will check for expired stashes and delete them.
55
55
 
56
56
  There is also a reason option `-r` available. Be nice and use it so your colleagues know what you're doing.
57
57
 
@@ -61,42 +61,43 @@ Examples
61
61
  Available subcommands: (for details, sensu SUB-COMMAND --help)
62
62
 
63
63
  ** Aggregate Commands **
64
- sensu aggregate list (OPTIONS)
65
- sensu aggregate show CHECK (OPTIONS)
66
- sensu aggregate delete CHECK
64
+ sensu-cli aggregate list (OPTIONS)
65
+ sensu-cli aggregate show CHECK (OPTIONS)
66
+ sensu-cli aggregate delete CHECK
67
67
 
68
68
  ** Check Commands **
69
- sensu check list
70
- sensu check show CHECK
71
- sensu check request CHECK SUB1,SUB2
69
+ sensu-cli check list
70
+ sensu-cli check show CHECK
71
+ sensu-cli check request CHECK SUB1,SUB2
72
72
 
73
73
  ** Client Commands **
74
- sensu client list (OPTIONS)
75
- sensu client show NODE
76
- sensu client delete NODE
77
- sensu client history NODE
74
+ sensu-cli client list (OPTIONS)
75
+ sensu-cli client show NODE
76
+ sensu-cli client delete NODE
77
+ sensu-cli client history NODE
78
78
 
79
79
  ** Event Commands **
80
- sensu event list
81
- sensu event show NODE (OPTIONS)
82
- sensu event delete NODE CHECK
80
+ sensu-cli event list
81
+ sensu-cli event show NODE (OPTIONS)
82
+ sensu-cli event delete NODE CHECK
83
83
 
84
84
  ** Health Commands **
85
- sensu health (OPTIONS)
85
+ sensu-cli health (OPTIONS)
86
86
 
87
87
  ** Info Commands **
88
- sensu info
88
+ sensu-cli info
89
89
 
90
90
  ** Silence Commands **
91
- sensu silence NODE (OPTIONS)
91
+ sensu-cli silence NODE (OPTIONS)
92
92
 
93
93
  ** Stash Commands **
94
- sensu stash list (OPTIONS)
95
- sensu stash show STASHPATH
96
- sensu stash delete STASHPATH
94
+ sensu-cli stash list (OPTIONS)
95
+ sensu-cli stash show STASHPATH
96
+ sensu-cli stash delete STASHPATH
97
+ sensu-cli stash create PATH
97
98
 
98
99
  ** Resolve Commands **
99
- sensu resolve NODE CHECK
100
+ sensu-cli resolve NODE CHECK
100
101
 
101
102
  --version, -v: Print version and exit
102
103
  --help, -h: Show this message
data/bin/sensu-cli ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ unless $:.include?(File.dirname(__FILE__) + '/../lib/')
3
+ $: << File.dirname(__FILE__) + '/../lib'
4
+ end
5
+
6
+ require 'sensu-cli/sensu'
7
+ sensu = SensuCli::Core.new
8
+ sensu.setup
data/lib/sensu-cli/cli.rb CHANGED
@@ -7,7 +7,7 @@ module SensuCli
7
7
  CLIENT_COMMANDS = %w(list show delete history)
8
8
  CHECK_COMMANDS = %w(list show request)
9
9
  EVENT_COMMANDS = %w(list show delete)
10
- STASH_COMMANDS = %w(list show delete)
10
+ STASH_COMMANDS = %w(list show delete create)
11
11
  AGG_COMMANDS = %w(list show delete)
12
12
  SIL_COMMANDS = ""
13
13
  RES_COMMANDS = ""
@@ -16,52 +16,52 @@ module SensuCli
16
16
 
17
17
  CLIENT_BANNER = <<-EOS.gsub(/^ {10}/, '')
18
18
  ** Client Commands **
19
- sensu client list (OPTIONS)
20
- sensu client show NODE
21
- sensu client delete NODE
22
- sensu client history NODE\n\r
19
+ sensu-cli client list (OPTIONS)
20
+ sensu-cli client show NODE
21
+ sensu-cli client delete NODE
22
+ sensu-cli client history NODE\n\r
23
23
  EOS
24
24
  INFO_BANNER = <<-EOS.gsub(/^ {10}/, '')
25
25
  ** Info Commands **
26
- sensu info\n\r
26
+ sensu-cli info\n\r
27
27
  EOS
28
28
  HEALTH_BANNER = <<-EOS.gsub(/^ {10}/, '')
29
29
  ** Health Commands **
30
- sensu health (OPTIONS)\n\r
30
+ sensu-cli health (OPTIONS)\n\r
31
31
  EOS
32
32
  CHECK_BANNER = <<-EOS.gsub(/^ {10}/, '')
33
33
  ** Check Commands **
34
- sensu check list
35
- sensu check show CHECK
36
- sensu check request CHECK SUB1,SUB2\n\r
34
+ sensu-cli check list
35
+ sensu-cli check show CHECK
36
+ sensu-cli check request CHECK SUB1,SUB2\n\r
37
37
  EOS
38
38
  EVENT_BANNER = <<-EOS.gsub(/^ {10}/, '')
39
39
  ** Event Commands **
40
- sensu event list
41
- sensu event show NODE (OPTIONS)
42
- sensu event delete NODE CHECK\n\r
40
+ sensu-cli event list
41
+ sensu-cli event show NODE (OPTIONS)
42
+ sensu-cli event delete NODE CHECK\n\r
43
43
  EOS
44
44
  STASH_BANNER = <<-EOS.gsub(/^ {10}/, '')
45
45
  ** Stash Commands **
46
- sensu stash list (OPTIONS)
47
- sensu stash show STASHPATH
48
- sensu stash delete STASHPATH\n\r
46
+ sensu-cli stash list (OPTIONS)
47
+ sensu-cli stash show STASHPATH
48
+ sensu-cli stash delete STASHPATH
49
+ sensu-cli stash create PATH\n\r
49
50
  EOS
50
- #sensu stash create
51
51
  #apost '/stashes'
52
52
  AGG_BANNER = <<-EOS.gsub(/^ {10}/, '')
53
53
  ** Aggregate Commands **
54
- sensu aggregate list (OPTIONS)
55
- sensu aggregate show CHECK (OPTIONS)
56
- sensu aggregate delete CHECK\n\r
54
+ sensu-cli aggregate list (OPTIONS)
55
+ sensu-cli aggregate show CHECK (OPTIONS)
56
+ sensu-cli aggregate delete CHECK\n\r
57
57
  EOS
58
58
  SIL_BANNER = <<-EOS.gsub(/^ {10}/, '')
59
59
  ** Silence Commands **
60
- sensu silence NODE (OPTIONS)\n\r
60
+ sensu-cli silence NODE (OPTIONS)\n\r
61
61
  EOS
62
62
  RES_BANNER = <<-EOS.gsub(/^ {10}/, '')
63
63
  ** Resolve Commands **
64
- sensu resolve NODE CHECK\n\r
64
+ sensu-cli resolve NODE CHECK\n\r
65
65
  EOS
66
66
 
67
67
  def global
@@ -77,10 +77,10 @@ module SensuCli
77
77
  # ------------------
78
78
  # /\
79
79
  # '--'
80
- # SENSU
80
+ # SENSU-CLI
81
81
  #
82
82
  EOS
83
- banner "\n\rAvailable subcommands: (for details, sensu SUB-COMMAND --help)\n\r"
83
+ banner "\n\rAvailable subcommands: (for details, sensu-cli SUB-COMMAND --help)\n\r"
84
84
  banner AGG_BANNER
85
85
  banner CHECK_BANNER
86
86
  banner CLIENT_BANNER
@@ -235,6 +235,10 @@ module SensuCli
235
235
  p = Trollop::options
236
236
  item = next_argv
237
237
  deep_merge({:command => 'stashes', :method => 'Delete', :fields => {:path => item}},{:fields => p})
238
+ when 'create'
239
+ p = Trollop::options
240
+ item = next_argv
241
+ deep_merge({:command => 'stashes', :method => 'Post', :fields => {:create => true, :create_path => item}},{:fields => p})
238
242
  else
239
243
  explode(opts)
240
244
  end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+ require 'tempfile'
3
+
4
+ module SensuCli
5
+ class Editor
6
+
7
+ def create_stash(create_path)
8
+ @create_path = create_path
9
+ file = create_file
10
+ open(file)
11
+ end
12
+
13
+ def open(file)
14
+ ENV['EDITOR'] ? editor = ENV['EDITOR'] : editor = 'vi'
15
+ system("#{editor} #{file}")
16
+ begin
17
+ JSON.parse(File.read(file))
18
+ rescue JSON::ParserError
19
+ puts "The stash you created has Invalid JSON."
20
+ exit
21
+ end
22
+ end
23
+
24
+ def create_file
25
+ template = {:path => @create_path, :content => {:timestamp => Time.now.to_i }}
26
+ file = Tempfile.new('sensu')
27
+ file.write(JSON.pretty_generate(template))
28
+ file.close
29
+ file.path
30
+ end
31
+
32
+ end
33
+ end
@@ -3,6 +3,7 @@ require 'net/https'
3
3
  require 'json'
4
4
  require 'sensu-cli/settings'
5
5
  require 'sensu-cli/cli'
6
+ require 'sensu-cli/editor'
6
7
  require 'rainbow'
7
8
 
8
9
  module SensuCli
@@ -12,6 +13,7 @@ module SensuCli
12
13
  clis = Cli.new
13
14
  cli = clis.global
14
15
  settings
16
+ @command = cli[:command]
15
17
  api_path(cli)
16
18
  make_call
17
19
  end
@@ -31,44 +33,77 @@ module SensuCli
31
33
  end
32
34
 
33
35
  def api_path(cli)
34
- @command = cli[:command]
35
- case @command
36
- when 'clients'
37
- path = "/clients" << (cli[:fields][:name] ? "/#{cli[:fields][:name]}" : "") << (cli[:fields][:history] ? "/history" : "")
38
- when 'info'
39
- path = "/info"
40
- when 'health'
41
- path = "/health?consumers=#{cli[:fields][:consumers]}&messages=#{cli[:fields][:messages]}"
42
- when 'stashes'
43
- path = "/stashes" << (cli[:fields][:path] ? "/#{cli[:fields][:path]}" : "")
44
- when 'checks'
45
- if cli[:fields][:name]
46
- path = "/check/#{cli[:fields][:name]}"
47
- elsif cli[:fields][:subscribers]
48
- path = "/check/request"
49
- payload = {:check => cli[:fields][:check],:subscribers => cli[:fields][:subscribers]}.to_json
50
- else
51
- path = "/checks"
52
- end
53
- when 'events'
54
- path = "/events" << (cli[:fields][:client] ? "/#{cli[:fields][:client]}" : "") << (cli[:fields][:check] ? "/#{cli[:fields][:check]}" : "")
55
- when 'resolve'
56
- payload = {:client => cli[:fields][:client], :check => cli[:fields][:check]}.to_json
57
- path = "/event/resolve"
58
- when 'silence'
59
- payload = {:timestamp => Time.now.to_i}
60
- payload.merge!({:reason => cli[:fields][:reason]}) if cli[:fields][:reason]
61
- if cli[:fields][:expires]
62
- expires = Time.now.to_i + (cli[:fields][:expires] * 60)
63
- payload.merge!({:expires => expires})
64
- end
65
- payload = payload.to_json
66
- path = "/stashes/silence" << (cli[:fields][:client] ? "/#{cli[:fields][:client]}" : "") << (cli[:fields][:check] ? "/#{cli[:fields][:check]}" : "")
67
- when 'aggregates'
68
- path = "/aggregates" << (cli[:fields][:check] ? "/#{cli[:fields][:check]}" : "") << (cli[:fields][:id] ? "/#{cli[:fields][:id]}" : "")
36
+ self.respond_to?(@command) ? path = send(@command, cli) : (puts "Something Bad Happened";exit)
37
+ @api = {:path => path, :method => cli[:method], :command => cli[:command], :payload => (@payload || false)}
38
+ end
39
+
40
+ def clients(cli)
41
+ path = "/clients"
42
+ path << "/#{cli[:fields][:name]}" if cli[:fields][:name]
43
+ path << "/history" if cli[:fields][:history]
44
+ path << pagination(cli)
45
+ end
46
+
47
+ def info(cli)
48
+ path = "/info"
49
+ end
50
+
51
+ def health(cli)
52
+ path = "/health?consumers=#{cli[:fields][:consumers]}&messages=#{cli[:fields][:messages]}"
53
+ end
54
+
55
+ def stashes(cli)
56
+ if cli[:fields][:create]
57
+ e = Editor.new
58
+ @payload = e.create_stash(cli[:fields][:create_path]).to_json
69
59
  end
70
- path << pagination(cli) if ["stashes","clients","aggregates"].include?(@command)
71
- @api = {:path => path, :method => cli[:method], :command => cli[:command], :payload => (payload || false)}
60
+ path = "/stashes"
61
+ path << "/#{cli[:fields][:path]}" if cli[:fields][:path]
62
+ path << pagination(cli)
63
+ end
64
+
65
+ def checks(cli)
66
+ if cli[:fields][:name]
67
+ path = "/check/#{cli[:fields][:name]}"
68
+ elsif cli[:fields][:subscribers]
69
+ @payload = {:check => cli[:fields][:check],:subscribers => cli[:fields][:subscribers]}.to_json
70
+ path = "/check/request"
71
+ else
72
+ path = "/checks"
73
+ end
74
+ end
75
+
76
+ def events(cli)
77
+ path = "/events"
78
+ path << "/#{cli[:fields][:client]}" if cli[:fields][:client]
79
+ path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
80
+ path
81
+ end
82
+
83
+ def resolve(cli)
84
+ @payload = {:client => cli[:fields][:client], :check => cli[:fields][:check]}.to_json
85
+ path = "/event/resolve"
86
+ end
87
+
88
+ def silence(cli)
89
+ payload = {:timestamp => Time.now.to_i}
90
+ payload.merge!({:reason => cli[:fields][:reason]}) if cli[:fields][:reason]
91
+ if cli[:fields][:expires]
92
+ expires = Time.now.to_i + (cli[:fields][:expires] * 60)
93
+ payload.merge!({:expires => expires})
94
+ end
95
+ @payload = payload.to_json
96
+ path = "/stashes/silence"
97
+ path << "/#{cli[:fields][:client]}" if cli[:fields][:client]
98
+ path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
99
+ path
100
+ end
101
+
102
+ def aggregates(cli)
103
+ path = "/aggregates"
104
+ path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
105
+ path << "/#{cli[:fields][:id]}" if cli[:fields][:id]
106
+ path << pagination(cli)
72
107
  end
73
108
 
74
109
  def pagination(cli)
@@ -1,3 +1,3 @@
1
1
  module SensuCli
2
- VERSION = '0.0.10'
2
+ VERSION = '0.1.0'
3
3
  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.0.10
4
+ version: 0.1.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-05-13 00:00:00.000000000 Z
11
+ date: 2013-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -56,11 +56,14 @@ description: A command line utility for interacting with the Sensu api.
56
56
  email: agent462@gmail.com
57
57
  executables:
58
58
  - sensu
59
+ - sensu-cli
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
62
63
  - bin/sensu
64
+ - bin/sensu-cli
63
65
  - lib/sensu-cli/cli.rb
66
+ - lib/sensu-cli/editor.rb
64
67
  - lib/sensu-cli/sensu.rb
65
68
  - lib/sensu-cli/settings.rb
66
69
  - lib/sensu-cli/version.rb