VictorOps is pretty awesome. Think an extensible, actionable Pagerduty. Somewhere where you can integrated DevOps tools to automate your escalation and response process all in one place. I have downed the Flavor Aid1 and bought in. They offer a plethora built in integrations and a simple yet versatile REST Alert API. They do not have an official ruby API client and I couldn’t find one out there in the community, so I put one together this weekend.

Introducing the victor_ops-client gem.2 This came together based off of experience writing different bots for some of the clients I work for. It offers a common naming pattern for your entity_display_names, monitoring_tool description and routing_key usage.3

Here is how to use it:

Install the gem

gem install victor_ops-client

Require it in your script

require 'victor_ops/client'

Initialize your client

# Required for Initializing Client
API_URL = 'INSERT_URL_HERE'
ROUTING_KEY = 'INSERT_ROUTING_KEY_HERE'

client = VictorOps::Client.new api_url: API_URL, routing_key: ROUTING_KEY

The API_URL is an Incoming Webhook URL provided by VictorOps. You can find it by looking at your Settings -> Integrations -> REST Endpoint. The ROUTING_KEY is URI compliant string that you would like to use to route messages within VitorOps and the Transmogrifier.

On initialization you can pass in host, name, entity_display_name and monitoring_tool as extra values that will be used in the generation of alerts. If you don’t, the tool will auto populate the values with defaults. I recommend that you pass in a name at the least. Any value that you pass in on initialization can be accessed directly through a client.settings.#{value_name} call.

Once you have established your client, you can send any of the supported alert messages to VictorOps with a simple interface and convenience methods.

# Send a CRITICAL alert
client.critical 'THE DISK IS FULL!!!'

# Send a WARNING alert
client.warn desc: 'Disk is nearing capacity', stats: `df -h`

# Send an INFO alert
client.info [ 'this', 'is', 'an', 'array' ]

# Send an ACKNOWLEDGMENT
client.ack 'bot ack'

# Send a RECOVERY
client.recovery desc: 'Disk has space', emoji: ':saiyan:'

Note that the payload you are sending can be either a STRING, ARRAY or HASH. The helper methods convert the input to the alert methods using awesome_print. I do this so that you can pack important metadata into the state_message within VictorOps easily in the code.

Rollup info from Ruby Client
Expanded details of the info from Ruby Client

If you would like to take a look at the source code feel free to take a look, fork, contribute.

I will be adding a persistence layer (most likely using daybreak) that will provide and interface to update previously posted incidents via the entity_id.

  1. Contrary to popular belief, it was Flavor Aid that was used at the Jonestown Massacre which is the morbid origin of the “Drink the Kool-Aid” saying. 

  2. RubyGems.org has provided a very helpful explanation of gem naming conventions that I suggest looking at. 

  3. Source code is on Github, MIT Liscense