Last active
March 3, 2017 20:19
-
-
Save PatrickTulskie/998b2d0cc6232cd1d13adf02c8ded1b6 to your computer and use it in GitHub Desktop.
VictorOps Handler for Lita
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lita.configure do |config| | |
# ... | |
config.handlers.victor_ops.api_id = "API_ID" | |
config.handlers.victor_ops.api_key = "API_KEY" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: ack __incident_number__ __victorops_username__ | |
module Lita | |
module Handlers | |
class VictorOps < Handler | |
include LitaUtility | |
include HTTParty | |
route(/ack (\d+)\s(\w*)$/i, :ack) | |
base_uri 'https://api.victorops.com/api-public/v1/' | |
config :api_id | |
config :api_key | |
def ack(response) | |
parts = response.matches.flatten | |
incident = parts[0] | |
user = parts[1] | |
deliver_ack(user: user, incident: incident, message: "acked in chat via #{robot.name}") | |
response.reply("Acking #{incident} by #{user}") | |
end | |
private | |
def default_headers | |
@default_headers ||= { | |
'X-VO-Api-Id' => config.api_id, | |
'X-VO-Api-Key' => config.api_key, | |
'Content-Type' => 'application/json' | |
} | |
end | |
def deliver_ack(user: nil, incident: nil, message: nil) | |
data = { | |
'userName' => user, | |
'incidentNames' => [incident], | |
'message' => message | |
} | |
results = self.class.patch("/incidents/ack", body: data.to_json, headers: default_headers) | |
Lita.logger.info(results.inspect) | |
results | |
end | |
end | |
Lita.register_handler(VictorOps) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment