ExVictorOps - Leverage VictorOps from your Elixir Apps

Today, I'd like to introduce ExVictorOps, a library that I've been writing in Elixir for connecting VictorOps into Elixir applications. At Cage Data, we love what VictorOps is doing in the devops space. We've now tied it into our chatops through Cagebot and our TechPhone project (soon to be open source).

ExVictorOps was originally written to connect TechPhone, a Twilio based application which runs most of Cage Data's office phone system, to VictorOps. We have a 24 hour emergency line for customers to call into when they have issues after hours. In days past, we had to login into our phone system each week to update the tech on call and often times it was forgotten. Now with ExVictorOps, we can have our emergency line automatically updated each week through VictorOps' rotations.

What does this code look like?

With ExVictorOps, making calls to the VictorOps API is easy. First you'll need to setup add ExVictorOps as a dependency to your project in mix.exs:

def deps do  
    { :ex_victor_ops, "~> 0.2.0" }

Then ensure that it starts with your application:

def application do  
  [applications: [:ex_victor_ops]]

Finally configure it in config/config.exs:

config :ex_victor_ops, api_id: "YOUR VICTOROPS API ID",  
                       api_key: "YOU VICTOROPS API KEY"

Now we're able to use ExVictorOps in our application. Currently the library is very young and only supports the On Call API endpoint, but I'll be adding more as I am able.

With the On Call API endpoint, you can get on call schedules by team or user. For our purposes we used the team method. Our emergency rotation is run on a team called "Support Team" and the slug for that team is support-team. To figure out the slug for your teams, go to your VictorOps settings, then Schedules and the slug is the end of the URL for each team.

For TechPhone all we needed to get was the current on call technician for our Support Team. With the ExVictorOps library that's easy:

# Get our team from VictorOps
{:ok, team} = ExVictorOps.OnCall.get_team "support-team", days_forward: 0

# Get either the current overriding technician or the current on call tech
user = ""  
cond do  
    !Enum.empty?(team.overrides) -> user = List.first(team.overrides)["overrideOnCall"]
    !Enum.empty?(team.schedule) -> user = List.first(team.schedule)["onCall"]

phone = "5555550000"  
case user do  
    "davejlong" -> phone = "5555550001"

VictorOps' API is still young and has it's limits, such as not having a user endpoint to get the technician's phone number dynamically, but what VictorOps has provided so far has been a huge step forward for Cage Data as we grow our team.

To learn how to use the rest of the ExVictorOps library take a look at some of the links below.

Dave Long

Read more posts by this author.

Subscribe to Dave Long

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!