128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/bender/bot.rb', line 128
def handle room, sender, message
@room_name = @@rooms.select { |r| r.xmpp_jid == room }.first.name
@room = room
@sender = sender
@message = message
severity_field = SHOW_FIELDS.key 'Severity'
severities = Hash.new { |h,k| h[k] = [] }
if message =~ /\/inc\s+(\w+)?\s*/
unless COMMANDS.include? $1.to_sym
reply_html 'Invalid usage', :red
reply_with_help
return
end
end
case message
when /^\s*\/bender\s*$/
reply_html QUOTES.sample(1).first, :red
when /^\s*\/whoami\s*$/
u = user_where name: sender
m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
reply_html m, :purple
when /^\s*\/lookup\s+(.+)\s*$/
u = user_where(name: $1) || user_where(nick: $1)
m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
reply_html m, :purple
when /^\s*(\?inc|\/inc\s+help)\s*$/
reply_with_help
when /^\s*\/inc\s*$/
refresh_incidents
is = store['incidents'].reverse.map do |i|
status = normalize_value i['fields']['status']
unless status =~ /done|complete|closed/i
'%s (%s - %s) [%s]: %s' % [
incident_link(i),
short_severity(i['fields'][severity_field]['value']),
normalize_value(i['fields']['status']),
friendly_date(i['fields']['created']),
i['fields']['summary']
]
end
end.compact.join('<br />')
if is.empty?
reply_html 'Good news everyone! No open incidents at the moment', :green
else
reply_html is
end
when /^\s*\/inc\s+summary\s*$/
refresh_incidents
statuses = Hash.new { |h,k| h[k] = 0 }
store['incidents'].reverse.each do |i|
if recent_incident? i
status = normalize_value(i['fields']['status'])
repr = '%s (%s) [%s]: %s' % [
incident_link(i),
status,
friendly_date(i['fields']['created']),
i['fields']['summary']
]
sev = i['fields'][severity_field]['value']
severities[sev] << repr
statuses[status] += 1
end
end
summary = []
summary << 'By Status:'
statuses.each do |status, size|
summary << '%s: %d incident(s)' % [ status, size ]
end
summary << ''
summary << 'By Severity:'
severities.keys.sort.each do |severity|
summary << '%s: %d incident(s)' % [
short_severity(severity),
severities[severity].size
]
end
if severities.empty?
reply_html 'No recent incidents! Woohoo!', :green
else
is = severities.keys.sort.map do |sev|
"%s:<br />%s" % [ sev, severities[sev].join("<br />") ]
end.join("<br /><br />")
reply_html(summary.join("<br />") + "<br /><br />" + is)
end
when /^\s*\/inc\s+(\d+)\s*$/
incident = select_incident $1
if incident.nil?
reply_html 'Sorry, no such incident!', :red
else
fields = SHOW_FIELDS.keys - %w[ summary ]
i = fields.map do |f|
val = incident['fields'][f]
if val
key = SHOW_FIELDS[f]
val = normalize_value val
'%s: %s' % [ key, val ]
end
end.compact
reply_html "%s - %s<br />%s" % [
incident_link(incident),
incident['fields']['summary'],
i.join("<br />")
]
end
when /^\s*\/inc\s+close\s+(\d+)\s*$/
incident = select_incident $1
if incident
reply_html *close_incident(incident)
else
reply_html 'Sorry, no such incident!', :red
end
when /^\s*\/inc\s+open\s+(severity|sev|s|p)?(\d+)\s+(.*?)\s*$/i
user = user_where name: sender
data = {
fields: {
project: { key: options.jira_project },
issuetype: { name: options.jira_type },
reporter: { name: user[:nick] },
summary: $3,
SHOW_FIELDS.key('Severity') => {
id: SEVERITIES[$2.to_i]
}
}
}
reply_html *file_incident(data)
when /^\s*\/inc\s+comment\s+(\d+)\s+(.*?)\s*$/i
incident = select_incident $1
= $2
user = user_where name: sender
if incident
reply_html *(incident, , user)
else
reply_html 'Sorry, no such incident!', :red
end
end
return true
end
|