Class: SensuCli::PathCreator
- Inherits:
-
Object
- Object
- SensuCli::PathCreator
show all
- Defined in:
- lib/sensu-cli/path.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args) ⇒ Object
88
89
90
|
# File 'lib/sensu-cli/path.rb', line 88
def method_missing(method_name, *_args)
puts "Path method: #{method_name} does not exist. "
end
|
Instance Method Details
#aggregates(cli) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/sensu-cli/path.rb', line 70
def aggregates(cli)
path = '/aggregates'
path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
path << "/#{cli[:fields][:id]}" if cli[:fields][:id]
path << (cli)
respond(path)
end
|
#checks(cli) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/sensu-cli/path.rb', line 32
def checks(cli)
if cli[:fields][:name]
path = "/check/#{cli[:fields][:name]}"
elsif cli[:fields][:subscribers]
payload = { :check => cli[:fields][:check], :subscribers => cli[:fields][:subscribers] }.to_json
path = '/request'
else
path = '/checks'
end
respond(path, payload)
end
|
#clients(cli) ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/sensu-cli/path.rb', line 3
def clients(cli)
path = '/clients'
path << "/#{cli[:fields][:name]}" if cli[:fields][:name]
path << '/history' if cli[:fields][:history]
path << (cli)
respond(path)
end
|
#events(cli) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/sensu-cli/path.rb', line 44
def events(cli)
path = '/events'
path << "/#{cli[:fields][:client]}" if cli[:fields][:client]
path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
respond(path)
end
|
#health(cli) ⇒ Object
16
17
18
19
|
# File 'lib/sensu-cli/path.rb', line 16
def health(cli)
path = "/health?consumers=#{cli[:fields][:consumers]}&messages=#{cli[:fields][:messages]}"
respond(path)
end
|
#info ⇒ Object
11
12
13
14
|
# File 'lib/sensu-cli/path.rb', line 11
def info(*)
path = '/info'
respond(path)
end
|
78
79
80
81
82
83
84
85
86
|
# File 'lib/sensu-cli/path.rb', line 78
def (cli)
if cli[:fields].key?(:limit) && cli[:fields].key?(:offset)
"?limit=#{cli[:fields][:limit]}&offset=#{cli[:fields][:offset]}"
elsif cli[:fields].key?(:limit)
"?limit=#{cli[:fields][:limit]}"
else
''
end
end
|
#resolve(cli) ⇒ Object
51
52
53
54
55
|
# File 'lib/sensu-cli/path.rb', line 51
def resolve(cli)
payload = { :client => cli[:fields][:client], :check => cli[:fields][:check] }.to_json
path = '/resolve'
respond(path, payload)
end
|
#respond(path, payload = false) ⇒ Object
92
93
94
|
# File 'lib/sensu-cli/path.rb', line 92
def respond(path, payload = false)
{ :path => path, :payload => payload }
end
|
#silence(cli) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/sensu-cli/path.rb', line 57
def silence(cli)
content = { :timestamp => Time.now.to_i }
content.merge!(:owner => cli[:fields][:owner]) if cli[:fields][:owner]
content.merge!(:reason => cli[:fields][:reason]) if cli[:fields][:reason]
payload = { :content => content }
payload.merge!(:expire => cli[:fields][:expire].to_i) if cli[:fields][:expire]
silence_path = 'silence'
silence_path << "/#{cli[:fields][:client]}" if cli[:fields][:client]
silence_path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
payload = payload.merge!(:path => silence_path).to_json
respond('/stashes', payload)
end
|
#stashes(cli) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/sensu-cli/path.rb', line 21
def stashes(cli)
if cli[:fields][:create]
e = Editor.new
payload = e.create_stash(cli[:fields][:create_path]).to_json
end
path = '/stashes'
path << "/#{cli[:fields][:path]}" if cli[:fields][:path]
path << (cli)
respond(path, payload)
end
|