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
90
91
92
|
# File 'lib/sensu-cli/path.rb', line 90
def method_missing(method_name, *args)
puts "Path method: #{method_name} does not exist. "
end
|
Instance Method Details
#aggregates(cli) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/sensu-cli/path.rb', line 72
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
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/sensu-cli/path.rb', line 33
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 = "/check/request"
else
path = "/checks"
end
respond(path,payload)
end
|
#clients(cli) ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/sensu-cli/path.rb', line 4
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
45
46
47
48
49
50
|
# File 'lib/sensu-cli/path.rb', line 45
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
17
18
19
20
|
# File 'lib/sensu-cli/path.rb', line 17
def health(cli)
path = "/health?consumers=#{cli[:fields][:consumers]}&messages=#{cli[:fields][:messages]}"
respond(path)
end
|
#info(cli) ⇒ Object
12
13
14
15
|
# File 'lib/sensu-cli/path.rb', line 12
def info(cli)
path = "/info"
respond(path)
end
|
80
81
82
83
84
85
86
87
88
|
# File 'lib/sensu-cli/path.rb', line 80
def (cli)
if cli[:fields].has_key?(:limit) && cli[:fields].has_key?(:offset)
page = "?limit=#{cli[:fields][:limit]}&offset=#{cli[:fields][:offset]}"
elsif cli[:fields].has_key?(:limit)
page = "?limit=#{cli[:fields][:limit]}"
else
page = ""
end
end
|
#resolve(cli) ⇒ Object
52
53
54
55
56
|
# File 'lib/sensu-cli/path.rb', line 52
def resolve(cli)
payload = {:client => cli[:fields][:client], :check => cli[:fields][:check]}.to_json
path = "/event/resolve"
respond(path,payload)
end
|
#respond(path, payload = false) ⇒ Object
94
95
96
|
# File 'lib/sensu-cli/path.rb', line 94
def respond(path,payload=false)
{:path => path, :payload => payload}
end
|
#silence(cli) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/sensu-cli/path.rb', line 58
def silence(cli)
payload = {:timestamp => Time.now.to_i}
payload.merge!({:reason => cli[:fields][:reason]}) if cli[:fields][:reason]
if cli[:fields][:expires]
expires = Time.now.to_i + (cli[:fields][:expires] * 60)
payload.merge!({:expires => expires})
end
payload = payload.to_json
path = "/stashes/silence"
path << "/#{cli[:fields][:client]}" if cli[:fields][:client]
path << "/#{cli[:fields][:check]}" if cli[:fields][:check]
respond(path,payload)
end
|
#stashes(cli) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/sensu-cli/path.rb', line 22
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
|