To introduce the new Octopus Subscriptions feature, we thought it'd be useful to show a simple example of notifying a Slack channel whenever something critical happens within Octopus.
To do this, we'll need the following:
- an Octopus 3.5.* instance that supports subscriptions
- a Zapier account to catch the webhooks from Octopus and notify our Slack channel
- a Slack account and channel for receiving the notifications
We'll work backwards through these steps to show how to build a basic subscription notification.
We love Slack here at Octopus and it's the perfect candidate to notify us when important things happen (since we hardly ever check our emails anymore :) ).
For this example, we've setup a channel called "critical-stuff" where we want to receive our critical notifications.
We're going to use Zapier to host a webhook for us. Zapier will include a trigger (the webhook) and then run an action (notifying Slack). The idea being, Octopus will call this webhook whenever critical events have happened and Slack will be notified.
NOTE: We're using a trial account of Zapier to illustrate our example here. You may choose to write your own webhook and integrate the Slack API yourself, but Zapier makes this super easy to get up and running quickly and saves us time.
To create your trigger:
- Login to Zapier and create a new Zap.
- Select "Webhooks" from the list of built-in apps and proceed to create a "Catch Hook" that waits for a new POST.
- On the last step of the webhook setup, Zapier will give you a webhook URL. Remember this value for later! We'll use this value in our Octopus subscription. It will look something like this:
To test the connectivity and payload of this webhook, you will now need to jump into Octopus and setup your first subscription. But make sure you keep your Zapier screen open so we can confirm the test works and continue to add our Slack action later.
Once your have Octopus 3.5 installed, you can access subscriptions from the Configuration > Audit > Subscriptions menu. We can now proceed to create a subscription that calls the Zapier webhooks as soon as events become available.
To get started, we'll create a subscription called "Notify me of all things!", being sure to paste in your Zapier webhook URL:
Once we save this record, Octopus will log an event that a subscription has been created. The subscription scheduler within Octopus will then process this event and trigger the Zapier webhook.
If you jump back over to your Zapier screen now (wait up to 30 seconds for Octopus to do its processing), your Zapier test should have successfully received a payload from Octopus:
Back to Zapier to integrate our Slack action
Now that Octopus has successfully talked to Zapier via our webhook, we can integrate the Slack action.
You can now continue to setup your action:
- Add an action from the side menu in Zapier.
- Select "Slack" from the list of popular apps (or use the search function to find Slack).
- Select "Send Channel Message" from the list of actions.
- Connect your Slack account to Zapier (follow the prompts).
- Once you arrive on the Edit Step screen, you may select the Slack channel you want to receive notifications on. In this example, we've selected the "critical-stuff" channel we created earlier.
Now comes the cool part: The message we'll be sending to Slack :)
Zapier knows the payload that Octopus will send in its webhook (because we sent a test earlier), so we can insert a field for the message and select from the payload objects that Octopus delivers for each event. For example:
In our case, we want to know the "Payload Event Message".
We can now continue to save that Zapier action and proceed to a test, and BOOM, just like that, we are now notified in Slack when activity occurs in Octopus:
Remembering to save our Zap and give it a name (making sure it's enabled), we can now proceed back into Octopus and modify our subscription(s) to notify us according to certain criteria only.
Back to Octopus (to finalise our subscription)
In this case, we only want to know about critical events such as deployments failing or auto-deployments being blocked. We can easily modify the subscription we made earlier to make this happen:
- Open our subscriptions in Octopus.
- Select the "Notify me of all things!" subscription that we made earlier.
- Edit the name of the subscription to "Critical events notification".
- Select only the critical events by using an Event Group filter.
Now Octopus will notify our Slack channel (via our Zapier webhook) whenever critical events occur within Octopus :)
You can learn more about subscriptions, including emailing and scoping subscription to certain teams) in our subscriptions documentation.
Octopus Deploy is used by thousands of developers across the globe, from small companies to large enterprises. Find out if it meets your deployment automation needs by taking advantage of our free 30-day trial. You can spin up an instance with just a few clicks!