lita-sensu 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87b5befe154037c096d9e44b6d11580a41163735
4
- data.tar.gz: 727ff8794a2b6c3d0b6b056a53b1b3a6fe68c80c
3
+ metadata.gz: 428df3096d47dcdd95e9c4a2b2394ead23aaa034
4
+ data.tar.gz: c0e212aebf2ff594bbbb1c9d28eba57cbd697bc5
5
5
  SHA512:
6
- metadata.gz: b742b422fb67017aa01b6128138c120484873c57c481d45993b249d785cb0947480e435bba5fb6afb773b775d1c2a53ba29f481bd5125c220b20147a9f28a328
7
- data.tar.gz: 1720affdfd77459b26c38981a45f952b5cd0002689133ea82a139777e9bcbd3726f89ea588f357b6794ede886ec6b999500b23a35a3f9f1595eea9f996a2bee3
6
+ metadata.gz: 9848baf16cdec5f0e9a73c8a58af52c1198e5a7fad19c71b2c8d2c9ced6cffa02650c4de64ef42cc6ae20c023386fa98bb5cebe2893c4b5cf42830338800407e
7
+ data.tar.gz: 9a6388bc52fc0232c8000948a01aa582e552adc3d3f51af9e8f816fa6ee20c4da67ee70f6b03cf7d7f0a785eb3d83f22fd1fd20f3414fc955aa81e6e67848a1f
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .idea
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -22,9 +22,35 @@ module Lita
22
22
  route(/(?:sensu\s+)?silence ([^\s\/]*)(?:\/)?([^\s]*)?(?: for (\d+)(\w))?/, :silence, help: {"sensu silence <hostname>[/<check>][ for <duration><units>]" => "Silence event"})
23
23
  route(/sensu stash(es)?/, :stashes, help: {"sensu stashes" => "Displays current sensu stashes"})
24
24
 
25
+ def headers
26
+ headers = {}
27
+ if config.api_user
28
+ headers["Authorization"] = "Basic #{Base64.encode64("#{config.api_user.chomp}:#{config.api_pass.chomp}")}"
29
+ end
30
+ headers
31
+ end
32
+
33
+ def http_get(url)
34
+ http.get(url) do |req|
35
+ req.headers = headers
36
+ end
37
+ end
38
+
39
+ def http_delete(url)
40
+ http.delete(url) do |req|
41
+ req.headers = headers
42
+ end
43
+ end
44
+
45
+ def http_post(url, data)
46
+ http.post(url, data) do |req|
47
+ req.headers = headers
48
+ end
49
+ end
50
+
25
51
  def client(response)
26
52
  client = add_domain(response.matches[0][0])
27
- resp = http.get("#{config.api_url}:#{config.api_port}/clients/#{client}")
53
+ resp = http_get("#{config.api_url}:#{config.api_port}/clients/#{client}")
28
54
  if resp.status == 200
29
55
  client = MultiJson.load(resp.body, :symbolize_keys => true)
30
56
  response.reply(MultiJson.dump(client, :pretty => true))
@@ -38,7 +64,7 @@ module Lita
38
64
 
39
65
  def client_history(response)
40
66
  client = add_domain(response.matches[0][0])
41
- resp = http.get("#{config.api_url}:#{config.api_port}/clients/#{client}/history")
67
+ resp = http_get("#{config.api_url}:#{config.api_port}/clients/#{client}/history")
42
68
  if resp.status == 200
43
69
  history = MultiJson.load(resp.body, :symbolize_keys => true).sort{|a,b| a[:check]<=>b[:check]}
44
70
  response.reply(render_template('client_history', history: history))
@@ -49,7 +75,7 @@ module Lita
49
75
  end
50
76
 
51
77
  def clients(response)
52
- resp = http.get("#{config.api_url}:#{config.api_port}/clients")
78
+ resp = http_get("#{config.api_url}:#{config.api_port}/clients")
53
79
  if resp.status == 200
54
80
  clients = MultiJson.load(resp.body, :symbolize_keys => true).sort{|a,b| a[:name]<=>b[:name]}
55
81
  response.reply(render_template('clients', clients: clients))
@@ -66,7 +92,7 @@ module Lita
66
92
  client = ''
67
93
  end
68
94
 
69
- resp = http.get("#{config.api_url}:#{config.api_port}/events#{client}")
95
+ resp = http_get("#{config.api_url}:#{config.api_port}/events#{client}")
70
96
  if resp.status == 200
71
97
  events = MultiJson.load(resp.body, :symbolize_keys => true).sort{|a,b| a[:client][:name]<=>b[:client][:name]}
72
98
  response.reply(render_template('events', events: events))
@@ -77,7 +103,7 @@ module Lita
77
103
  end
78
104
 
79
105
  def info(response)
80
- resp = http.get("#{config.api_url}:#{config.api_port}/info")
106
+ resp = http_get("#{config.api_url}:#{config.api_port}/info")
81
107
  raise RequestError unless resp.status == 200
82
108
  info = MultiJson.load(resp.body, :symbolize_keys => true)
83
109
  response.reply(MultiJson.dump(info, :pretty => true))
@@ -85,7 +111,7 @@ module Lita
85
111
 
86
112
  def remove_client(response)
87
113
  client = add_domain(response.matches[0][0])
88
- resp = http.delete("#{config.api_url}:#{config.api_port}/clients/#{client}")
114
+ resp = http_delete("#{config.api_url}:#{config.api_port}/clients/#{client}")
89
115
  if resp.status == 202
90
116
  response.reply("#{client} removed")
91
117
  elsif resp.status == 404
@@ -101,7 +127,7 @@ module Lita
101
127
  check = response.matches[0][1]
102
128
 
103
129
  data = { :client => client, :check => check }
104
- resp = http.post("#{config.api_url}:#{config.api_port}/resolve", MultiJson.dump(data))
130
+ resp = http_post("#{config.api_url}:#{config.api_port}/resolve", MultiJson.dump(data))
105
131
  if resp.status == 202
106
132
  response.reply("#{client}/#{check} resolved")
107
133
  elsif resp.status == 400
@@ -154,7 +180,7 @@ module Lita
154
180
  :path => "silence/#{path}"
155
181
  }
156
182
 
157
- resp = http.post("#{config.api_url}:#{config.api_port}/stashes", MultiJson.dump(data))
183
+ resp = http_post("#{config.api_url}:#{config.api_port}/stashes", MultiJson.dump(data))
158
184
  if resp.status == 201
159
185
  response.reply("#{path} silenced for #{humanDuration}")
160
186
  else
@@ -164,7 +190,7 @@ module Lita
164
190
  end
165
191
 
166
192
  def stashes(response)
167
- resp = http.get("#{config.api_url}:#{config.api_port}/stashes")
193
+ resp = http_get("#{config.api_url}:#{config.api_port}/stashes")
168
194
  if resp.status == 200
169
195
  stashes = MultiJson.load(resp.body, :symbolize_keys => true).sort{|a,b| a[:name]<=>b[:name]}
170
196
  response.reply(render_template('stashes', stashes: stashes))
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-sensu"
3
- spec.version = "0.1.1"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Justin Lambert"]
5
5
  spec.email = ["jlambert@eml.cc"]
6
6
  spec.description = "Lita plugin to interact with sensu"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-sensu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Lambert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2015-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -143,13 +143,9 @@ files:
143
143
  - spec/spec_helper.rb
144
144
  - templates/.gitkeep
145
145
  - templates/client_history.erb
146
- - templates/client_history.hipchat.erb
147
146
  - templates/clients.erb
148
- - templates/clients.hipchat.erb
149
147
  - templates/events.erb
150
- - templates/events.hipchat.erb
151
148
  - templates/stashes.erb
152
- - templates/stashes.hipchat.erb
153
149
  homepage: https://github.com/jlambert121/lita-sensu
154
150
  licenses:
155
151
  - Apache-2.0
@@ -1,16 +0,0 @@
1
- <table>
2
- <tr>
3
- <th>Check</th>
4
- <th>Status</th>
5
- <th>Last Checked</th>
6
- <th>History</th>
7
- </tr>
8
- <% @history.each do |check| %>
9
- <tr>
10
- <td><%= check[:check] %></td>
11
- <td><%= check[:last_status] %></td>
12
- <td><%= Time.at(check[:last_execution]) %></td>
13
- <td><%= check[:history].join(',') %></td>
14
- </tr>
15
- <% end %>
16
- </table>
@@ -1,13 +0,0 @@
1
- <table>
2
- <tr>
3
- <th>Name</th><th>IP</th><th>Subscriptions</th><th>Version
4
- </tr>
5
- <% @clients.each do |client| %>
6
- <tr>
7
- <td><%= client[:name] %></td>
8
- <td><%= client[:address] %></td>
9
- <td><%= client[:subscriptions].sort().join(', ') %></td>
10
- <td><%= client[:version]%></td>
11
- </tr>
12
- <% end %>
13
- </table>
@@ -1,14 +0,0 @@
1
- <table>
2
- <tr>
3
- <th>Client</th>
4
- <th>Check</th>
5
- <th>Occurrences</th>
6
- <th>Output</th>
7
- </tr>
8
- <% @events.each do |event| %>
9
- <tr>
10
- <td><%= event[:client][:name] %></td>
11
- <td><%= event[:check][:name] %></td>
12
- <td><%= event[:occurrences] %></td>
13
- <td><%= event[:check][:output] %></td>
14
- <% end %>
@@ -1,12 +0,0 @@
1
- <table>
2
- <tr>
3
- <th>Path</th><th>Added On</th><th>By</th><th>Seconds to expiration</th>
4
- </tr>
5
- <% @stashes.each do |stash| %>
6
- <tr>
7
- <td><%= stash[:path] %></td>
8
- <td><%= Time.at(stash[:content][:timestamp]) %></td>
9
- <td><%= stash[:content][:by] || ''%> </td>
10
- <td><%= stash[:expire] || '' %></td>
11
- </tr>
12
- <% end %>