Integrating VictorOps with Salesforce Using its REST Endpoint
This article was sponsored by VictorOps. Thank you for supporting the sponsors who make SitePoint possible!
When you have a live application with real users, problems don’t show up according to your schedule. You need a way to manage and resolve issues that come up all of a sudden, and this process needs to be as simple and painless as possible. This is where VictorOps comes in. It allows you to manage who is responsible for fixing live problems, enables communication among the team when these issues arise, and integrates with the rest of your systems to make detecting problems a piece of cake.
In this article, we’ll cover how you can use VictorOps as a REST endpoint to integrate it with other services. In particular, we’ll focus on SalesForce integration. To make this integration, you’ll need a VictorOps account.
Integration and the REST Endpoint
First of all, what do we mean when we say that VictorOps gives you a “REST endpoint”? The idea is that VictorOps allows you to access resources using a RESTful API over HTTP. What’s the point, you ask? Well, it is usually very easy to make HTTP requests, and we can use the REST endpoint to quickly set up integrations with other services. For example, a lot of companies use Nagios to monitor services within a deployment. We can integrate VictorOps with Nagios using a plugin, which simply takes alerts and pushes them over to VictorOps’s REST endpoint. The breadth of services you can integrate using the REST endpoint is incredible; as long as you have a little code that can fire off some HTTP requests to ‘alert.victorops.com’, you can make the integration happen.
Let’s take a look at how to set up one of these integrations. A lot of teams use Salesforce as a communications medium. We want people who use Salesforce (which generally includes people on the non-technical side of things) to be able to communicate with the people working with their company’s servers. So, when cases are created in Salesforce, we should get alerts through VictorOps. This allows you to have one place (VictorOps) where you can see IT problems arise throughout your infrastructure. Let’s see how to set up that integration.
Salesforce has a way to hook in little bits of code that decide what to do when specific things called “triggers” happen. These little bits of code are written in a language called “Apex” (which is more or less specific to Salesforce) that is meant to have a syntax very similar to Java. Fortunately, you don’t have to spend any of your time learning how to write Apex in order to get Salesforce integration to work since the kind folks at VictorOps have a repository that contains the required code snippets.
For security reasons, we need to tell Salesforce that our code is going to be making requests to the VictorOps REST endpoint. To do that, we’ll have to add “http://alert.victorops.com/” as a remote site by going through ‘Security Controls => Remote Site Settings => New Remote Site’ in the Salesforce dashboard. After you do that, you should see this on the ‘All Remote Sites’ page:
Before we can get the Apex code talking with VictorOps, we need to put in our API and route keys from VictorOps into the Apex code. Get yourself of a copy of the code first from this repository. Then, we need the right keys from VictorOps. From the VictorOps dashboard, we go to ‘Settings => Integrations REST Endpoint’. After enabling the integration, you’ll see a URL like this:
The part of the URL in red is your “API key”. Now, we’ll create a routing key. Your routing key allows you to route certain alerts to certain groups of people within your VictorOps organization. To set one up, again head over to ‘Settings’ in the VictorOps dashboard, click on ‘Integrations’ and down to ‘Incident Routing’. Add a rule with a routing key (e.g. “salesforce_integration”). At this point, you’ll probably be routing that routing key to ‘everyone’:
Now, in the Apex code, you should find a file named “VictorOpsTimeLine Apex Class”, with a bit of text in it that looks like this:
Edit it to add your API and routing keys.
Next up, we’ll add in the Apex code into Salesforce. Head over to ‘Setup => Apex Classes’ in Salesforce and then simply upload the files in this repository that end in ‘Class’. For example, whereas ‘VO Alert Test Class’ goes in the classes. You should end up with:
We also need to set up the triggers. To do that, head over to the Developer Console via ‘Setup => Apex Classes => Developer Console’. Click on ‘File => New => Apex Trigger’. The name should correspond to the file name of the trigger (there are two of them) and the sObject should be “Case” (since we want this trigger to fire when cases are created or resolved).
Then, just paste in the trigger code and save.
In order to finally deploy this code to a production environment (as opposed to the developer sandbox you’ve been working in so far) you’ll need to deploy a changeset from the sandbox to the production organization.
To test out the integration, you can create a new case in Salesforce and you should see it show up as an alert inside VictorOps like this:
We’ve outlined the Salesforce integration using the REST endpoint, but the procedures for integrating other platforms are remarkably similar because VictorOps can communicate with many different platforms via the REST endpoint. For example, Sensu is a nice way to monitor your system based on a set of checks, and you can use the REST endpoint in order to make its alerts show up on VictorOps so you can deal with them in a coordinated fashion.
In fact, rolling your own integration is fairly easy since VictorOps has very good documentation on how you can get alerts into the system. With an API, a simple HTTP library and a couple of hours, you can get information from nearly any service into the alerts on your VictorOps dashboard.
By providing such easy integration, VictorOps lets you deal with complex problems in a much more efficient and timely manner because you don’t have to check a million sources of information to figure out where and when the problems show up.
Further Viewing and Reading
That brings us to the end of this tutorial, but if you have any other clever ideas for VictorOps integrations, feel free to suggest them in the comments. For more on the topic, here’s a list of useful resources you can check out: