A Zapier automation example featuring Device42 Webhooks

tl;dr— This post features a Zapier automation example, harnessing the power of Device42’s webhooks to drive things. This time around, we demonstrate how we can use a “power toggle” event in Device42 to actually control a DigitalOcean droplet, causing it to power-toggle either on or off.

You’ve got the automation itch. The good news is, you aren’t alone! It’s going around like a plague (but in a really, really good way!). What this means is that there are countless examples, ideas, and best of all — automation tools being released all the time.

This time, we will focus on utilizing Device42’s webhooks to drive automation with Zapier, a web based SaaS … Well, AaaS (Automation As A Service? Is that a thing!?) to automate power control of a DigitalOcean droplet based on the “Power” setting in Device42’s CMDB being changed either to off, or on.

Because Zapier abstracts a lot of the complexity away from the process of setting up if-this-then-that type automation, providing an easy to understand, platform independent automation toolchain with ready-built integrations with tons of popular applications, this example should be not only easy to follow, but easy to duplicate as well. Best of all, once you’ve familiarized yourself with the automation workflow and sending webhooks from Device42 to Zapier, you can build on this example — and the sky’s the limit!

As a starting point, you’re going to need at bare minimum a working Device42 installation and a Zapier account. Simple, yet very powerful.

The overview of the process is as follows:

  1. Create a new “Zap” in Zapier to catch Device42’s webhook

  2. Add Zapier’s webhook endpoint to Device42 and configure Device42 to send a webhook the endpoint when power is toggled

  3. Back to Zapier – Add a filter

  4. Create the action that your automation will trigger and have Zapier toggle the power on your DigitalOcean droplet

Step 1 Create a new “Zap” to catch Device42’s webhook

Choose the orange “Make a Zap!” button to begin. Search for “Webhooks by Zapier Tigger” and select it, and tell it you’d like it to “Catch Hook”.

Device42 Zapier Trigger

Save your changes and ‘continue’, selecting ‘continue’ through the next screen as well. Unless you are already very familiar with the contents of the webhook payload and are doing something different, you won’t be utilizing the ‘pick off a child key’ option for this automation demonstration.

Device42 Zapier Trigger

Copy the custom URL endpoint generated by Zapier and head over to your Device42 instance for step 2.

Step 2 Create a new webhook endpoint in Device42

Next, lets create the webhook endpoint in Device42 using the custom endpoint URL we got last step. To do this, visit the Tools → Webhooks → Endpoints menu in Device42, and select Add Webhook Endpoint +.

Device42 Zapier Trigger

Set the endpoint URL to that which was provided by Zapier, as shown. You may want to choose “Ignore Certificate Errors” until you are sure everything is working, just in case – it can be edited & unchecked later, but will ensure an SSL error isn’t the cause of your automation not working.

Save everything, and move on to creation of a the webhook action.

Step 2a Create and configure the “Action” trigger in Device42 to send the webhook

The next step is to create the ‘Action‘ trigger in Device42. This step involves configuration of the criteria that will cause Device42 to actually send the webhook off to the endpoint we added in the last step. Choose a descriptive name; the name is for identification purposes only, so try and be clear and concise. Since we’re looking to fire a webhook when power state is toggled – let’s call it ‘Power Toggled’.

Next, let’s configure webhooks to be sent when changes occur within our cloud instances.  We’ll do this by filtering the Action list by “cloud” — and then selecting “Cloud Instance Information”.

Device42 Zapier Trigger

Step 3 Back to Zapier – Add a filter

Once you’ve come this far, Zapier should be waiting for you to send a “test” webhook, which it will parse [when it receives it successfully] to provide you options in convenient drop downs for the next part of this step. Go ahead and make a change to one of the fields under the “Cloud Instance Information” heading on one of your cloud devices within Device42 to kick off a webhook [hint: you can verify a webhook is going to be sent by either looking at the ‘pending’ webhooks in Device42]. If all went as planned, Zapier should catch it, and you should see the following:

Device42 Zapier Trigger

Feel free to click “view your hook” to get the details of what was sent over with the webhook; When you’re all finished, go ahead and continue setup.

Now that everything is squared away with our webhook, we need to filter it so that our actions only happen when we change the power status of an instance. If you look at the webhook payload, you’ll see “Data Status”, which is either a 1 or a 2: the former translates to ‘running’, and the latter to the ‘stopped’ selection on your Device42 CI.

Zapier doesn’t have an “equals” for numbers, so to work around this, we can use “greater than” or “less than” [a bit odd, indeed – one of our programmers shared this hint]. Let’s set the filter to make sure “Data Status” is “greater than 1” for when a 2 comes over, which would translate to ‘the machine was turned off’, and “less than 2” for when a 1 comes, meaning ‘an instance was toggled on’.

Device42 Zapier Trigger

This is the filter configured to handle the “power off” event, since a 2 will always evaluate greater than 1.

A quick test demonstrates that this workaround is, though not pretty, indeed functional:

Device42 Zapier Trigger

Now let’s set up the action.

Step 4 Create the action that your automation will trigger

In Zapier, “Action” setup is Step 3. Choose “Digital Ocean” and then choose “Power a Droplet On/Off”:

Device42 Zapier Trigger

Save & Continue, and select your DigitalOcean account if it was already detected. If not, choose “Connect a New Account”, and follow the instructions on screen – Zapier takes care of all the complexities and even handles the two-factor auth.

Next, you’re going to want to choose “Use a Custom Value” for “Droplet”, since we’re going to pull the droplet ID out of the webhook. The custom value we’ll use for Droplet ID, which we specify on the next line, is — you guessed it — Data Name, and of course, the action in this case is “Power On”.

Device42 Zapier Trigger

If you’ve been keeping up and you have gotten to this step, you should be able to save & test your automation!

Congratulations!  You’ve created your first automation with Device42’s webhooks, Zapier, and Digital Ocean! Feels good, doesn’t it? You will need to create another Zap for Power Off, following the exact same steps as above, just next time powering your droplet off when ‘Data Status’ is ‘Less than 2’. Of course, feel free to add your own customizations, too – that’s what automating is all about, after all!

Did you enjoy this Guide? Have you automated anything else using Device42’s webhooks and Zapier, or Zapier & the Device42 API? Are you possibly planning to automate something in the future? We’re curious – Please do tell us about it! This post gives but a basic peek into the power and flexibility of Device42 Webhooks, the API, and Zapier. Leave a comment below or drop us an email with any questions, feedback, or just to say hello — We would absolutely love to hear from you!