What is the procedure for connecting an AppDynamics HTTP template to a dedicated Slack channel?
Revised May 16, 2022
Many of our customers today want to quickly alert a Slack channel when AppDynamics detects a customer-impacting performance issue with a critical application. If you are one of these joint customers with Slack, we have great news for you: Simple instructions and a template to set up this proactive alerting for your teams.
In this article...
What are the steps to creating an integration with Slack? Prepare Slack | Set up an AppDynamics alert | Create an AppDynamics policy to trigger the event or alert
How do I use my AppDynamics integration within Slack?
Resources
What are the steps to integrating with Slack?
To create this integration, we’ll use webhooks on both platforms: AppDynamics has an outgoing webhook to send notifications, and Slack has an incoming webhook to receive the notifications from AppDynamics. AppDynamics uses HTTP templates that are backed with a velocity engine so that data can be taken from variables in AppDynamics and sent into Slack. On the Slack side, this integration uses Slack blocks (layout blocks) in the template to format the message sent to Slack.
The template can be modified.
The following steps allow you to set AppDynamics up to send event notifications or alerts to a specific Slack channel. Three main areas need to be configured and set up:
A. Prepare Slack B. Set up an AppDynamics alert C. Create an AppDynamics policy to trigger the event or alert
Back to Top
A. Prepare Slack to receive AppDynamics alerts
Create a Slack App using this link. Pick a name, choose a workspace to associate your app with, and then click Create App. This app will help you post messages in Slack. You can also use any existing Slack App you have.
After creating the app, you will be redirected to the settings page for your new app (if you are using an existing app, just load its settings via your app's management dashboard).
From here select the Incoming Webhooks feature, and click the Activate Incoming Webhooks toggle to switch it on.
Now that Incoming Webhooks are enabled, the settings page should refresh and some extra options will appear. One of those options will be a button marked Add New Webhook to Workspace, and you should click it.
Go ahead and pick a channel that the app will post to, and then click to Authorize your app. You'll be sent back to your app settings, and you should now see a new entry under the Webhook URLs for Your Workspace section, with a Webhook URL that'll look something like this: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
This webhook URL generated by Slack will be used in AppDynamics as the target for the event notifications or alerting.
NOTE | Take note of it for the Request URL step in the Configure AppDynamics Alerting section below, where you will Set the Request URL parameters.
You’re now all set up in Slack. Next, go to AppDynamics to set up the outgoing webhook alert.
Back to Top
B. Prepare AppDynamics to Send Alerts to Slack
NOTE | This template uses the standard Slack “block” technology (as well as the velocity engine in AppDynamics) and can be modified.
In AppDynamics, create a new HTTP template (Alert & Respond > HTTP Request Templates > New) by first navigating to the option on the top tab, then clicking on HTTP Request Templates on the sidebar menu. In AppDynamics, create a new HTTP template on the Alert & Respond page
Configure the outbound webhook for event notifications and give it a name. Typically it’s best to name it after the application that will use it.
Set the Request URL parameters as:
Method
POST
Raw URL
The URL from Slack in Section 1 - Prepare Slack, step 6
URL Encoding
UTF-8
Scroll down the Create HTTP Template dialog to Payload and choose the following:
MIME Type
Application/JSON
Payload Encoding
UTF-8
(Payload box)
Download the attached template script and copy and paste it into the “payload box”
Use this template script for the "payload box": #set( $sm = $!{latestEvent.summaryMessage.replace('"',"*")} )
#set( $sm = $sm.replace("<b>", "*") )
#set( $sm = $sm.replace("</b>", "*") )
#set( $sm = $sm.replace("<br>", " ") )
#set( $sm = $sm.replace("null"," ") )
{
"blocks": [
{
"type": "section",
"text": {
#if( ${latestEvent.severity} == "ERROR" )
"type": "mrkdwn",
"text": ":red_circle: *New Alert from AppDynamics:* ${latestEvent.displayName}\n\n*Summary:*\n$sm"
#elseif( ${latestEvent.severity} == "WARN" )
"type": "mrkdwn",
"text": ":warning: *New Alert from AppDynamics:* ${latestEvent.displayName}\n\n*Summary:*\n$sm"
#else
"type": "mrkdwn",
"text": ":information_source: *New Alert from AppDynamics:* ${latestEvent.displayName}\n\n*Summary:*\n$sm"
#end
},
"accessory": {
"type": "image",
"image_url": "https://share-logos.s3-us-west-1.amazonaws.com/appd-s-logo.png",
"alt_text": "logo"
},
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Application:*\n${latestEvent.application.name}"
},
{
"type": "mrkdwn",
"text": "*When:*\n${latestEvent.eventTime}"
},
{
"type": "mrkdwn",
"text": "*Tier:*\n${latestEvent.tier.name}"
},
{
"type": "mrkdwn",
"text": "*Severity:*\n${latestEvent.severity}"
},
{
"type": "mrkdwn",
"text": "*Node:*\n${latestEvent.node.name}"
},
{
"type": "mrkdwn",
"text": "*Triggered by:*\n${policy.name}"
},
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Go to Alert in AppDynamics"
},
#if( ${latestEvent.severity} == "ERROR" )
"style": "danger",
#elseif( ${latestEvent.severity} == "WARN" )
"style": "primary",
#end
"value": "click_me_123",
"url": "${latestEvent.deepLink}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Start Webex Session"
},
"style": "primary",
"value": "click_me_123",
"url": "https://cisco.webex.com"
}
]
},
{
"type": "divider"
},
]
} Here's an example of what adding the script template to the Create HTTP Template, Payload section in AppDynamics looks like Example of adding the script template to the Create HTTP Template, Payload section in AppDynamics
Finally, click the Save button. Now the template is configured.
Test the template configuration. Click the Run Test button on the bottom of the page and choose some events to send over. The HTTP Action Template Test
Navigate to the Slack channel you set up. You should see a sample alert, like the “New Warning Health Rule Violation” shown below.
Test Health Rule violation warningng
To complete the integration, next, connect this template to an action and application policy.
Back to Top
C. Set Up an Action and Policy in AppDynamics to Trigger the Event or Alert
To complete the integration, tie an application to this template using an action and a policy within AppDynamics.
Set up an Action
Create a Policy
Set up an Action
First, choose an application from the pulldown menu. Then, go to the Alert & Respond tab, and choose Actions on the sidebar menu. After choosing an application, go to Alert & Respond > Actions
Next, create a new action. You’ll point this action at the template you created above. Go to the last section, choose the application, and click Create Action. In the Create Action dialog box, define the type of action to create by choosing HTTP Request. Click OK. Create Action dialog
Once you click OK, the Create HTTP Action dialog box will open. At the HTTP Request Template, enter the name of the HTTP action. Then, from the drop-down, choose which template this action will use (In this example, the HTTP template was called “Slack-Alert”). Click OK. Choose the HTTP Request Template for this Action
At the Create HTTP Action screen, click Save to confirm. Completed Create HTTP Action dialog
This completes your creation of the Action for triggering an outbound HTTP request.
Create a policy
Next, create a policy that both triggers the outbound HTTP request action, and binds the action to a particular application.
From the Actions and Alerts option, select Policy, then click Create a New Policy. Select the desired application. Create the new policy screen
Click the Create button. Name the policy, then configure which events will trigger this alert. See the example of how one might configure the policy
Next, go to the Actions tab on the top menu and select the “+”. From the list, choose an action to tie to this Policy, then click Save. Under Actions, choose an action to tie to the policy
Now, you have configured a Policy on an application to trigger an action, which then uses the template to send an event or alert (based on the rules you set in the policy) to a particular Slack channel.
Back to Top
How do I use my AppDynamics integration within Slack?
Once your application starts generating policy violations, you’ll see them in your AppD-Alerting Slack channel as shown below.
Example of the policy violation notice in Slack
The alert has two buttons. One takes you to the deep link URL in AppDynamics where the alert was generated. You can use the second button to log in and start a WebEx session if needed.
Below is an example of what you could expect to see when you click on the deep link URL.
Example of the deep link URL destination
You can click around here as you would normally do, to see things like the flowmap, calls, errors, and more.
Back to Top
Resources
Create a template for Slack in the AppDynamics documentation portal
Slack Message Attachments
How can I customize variables in Apache Velocity Templates
... View more