Knowledge Base

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I integrate AppDynamics with Slack?

What is the procedure for connecting an AppDynamics HTTP template to a dedicated Slack channel?

 

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.

 

Table of Contents


 

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 notification or alerts to a specific Slack channel. There are three main areas that need to be configured and set up: 

 

  1. Prepare Slack
  2. Set up an AppDynamics alert
  3. Create an AppDynamics policy to trigger the event or alert 

 

Prepare Slack to receive AppDynamics Alerts

  1. In Slack, create a new channel and note its name. This is the channel that will receive AppDynamics events notifications or alerts.

  2. Go to Browse Apps within Slack, and search for Incoming WebHooks. Once you find the app, click the add button to add it to your Slack instance.

    In Slack, browse Apps for the Incoming Webhooks appIn Slack, browse Apps for the Incoming Webhooks app

     

     

  3. At the prompt, choose the channel the webhook will post messages to. In this example, we chose appd-alerting, but you should choose the channel you created in step 1.

    Start configuring the Webhooks app by choosing the Slack channel you want to post toStart configuring the Webhooks app by choosing the Slack channel you want to post to

     

  4. Click the green Add Incoming WebHooks Integration button at the bottom.
     
    Click the Add Incoming Webhooks integration buttonClick the Add Incoming Webhooks integration button

     

    You’ll see the setup instructions for the webhook integration.

  5. Scroll down the setup page to the integration settings section to the webhook URL. This webhook URL generated by Slack will be used in AppDynamics as the target for the event notifications or alerting.

 

Take note of it for the Request URL step in the Configure AppDynamics Alerting section below, where you will Set the Request URL parameters.

  1. You can also add a custom name, description, and custom icon that will appear in Slack.

  2. Click the Save Settings button at the bottom of Integration Settings.
     
    Click Save Settings at the bottom of Integration SettingsClick Save Settings at the bottom of Integration Settings

 

You’re now all set up in Slack. Next, go to AppDynamics to set up the outgoing webhook alert.


 

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.

 

  1. 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 pageIn AppDynamics, create a new HTTP template on the Alert & Respond page

     

  2. 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. 

  3. Set the Request URL parameters as: 

    Method

    POST

    Raw URL

    The URL from Slack in Section 1 - Prepare Slack, step 5 

    URL Encoding

    UTF-8


    Create HTTP Request template Request URL settingsCreate HTTP Request template Request URL settings

     



  4. 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"
    		},
    	]
    }

    Example of adding the script template to the Create HTTP Template, Payload section in AppDynamics:
    Example of adding the script template to AppDynamics.Example of adding the script template to AppDynamics.
  5. Finally, click the Save button. Now the template is configured.

  6. 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 TestThe HTTP Action Template Test

     

     

     

  7. 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 warningngTest Health Rule violation warningng

 

To complete the integration, next, connect this template to an action and application policy


 

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

  1. 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 > ActionsAfter choosing an application, go to Alert & Respond > Actions

     

  2. 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 dialogCreate Action dialog

     

  3. 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 ActionChoose the HTTP Request Template for this Action

     



  4. At the Create HTTP Action screen, click Save to confirm. 

    Completed Create HTTP Action dialogCompleted 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. 

 

  1. From the Actions and Alerts option, select Policy, then click Create a New Policy. Select the desired application.

    Create the new policy screenCreate the new policy screen

     

     

  2. Click the Create button. Name the policy, then configure which events will trigger this alert.

    See the example of how one might configure the policySee the example of how one might configure the policy

     

  3. 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 policyUnder 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. 


 

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 SlackExample 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 destinationExample 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.

18 image5.png

 

 

Resources

Slack Message Attachments 

How can I customize variables in Apache Velocity Templates

Version history
Revision #:
28 of 28
Last update:
‎10-07-2020 02:12 PM
Updated by:
 


Found this article helpful? Click the Thumbs Up button.
Have an additional comment? Post it below.
Comments

thanks.

Glad you're pleased, @Ahmed.Sorour! Hoping you'll let the Community know how it goes for you!

 

Claudia Landivar

Community Manager & Editor

Knowledge Base

Great Post! 

I have setup the Slack integration with the help of this article.

 

I am noticing a few things while trying a Test Run:

1. App Server Restart notification is not getting pushed on to slack. Any reasons why?

2. If 2 event types are to be sent simultaneously, i notice only one reaching slack? Is it tool behaviour or am I missing something?

 

Regards,

Deepika Singh

 

Hi Deepika,

 

The first issue I can reproduce, so to fix it please remove 2 lines of code below.  Its at the bottom of the template. 

 

#else
"style": "green",

 

this was an oversight as style=green does not exist in the Slack Block world, so by taking those two line out it will just be the default color.  

 

The second issue I need to understand more, so when you say 2 event types, do you mean from 2 different applications or the same application?  Need to understand it more to look into it. 

 

Thanks,

 

Bill 

FYI @Deepika.Singh  and @Bill.Harper , I've removed the color code from the article above, so readers will no longer find it:

#else
"style": "green",

 

Thank you both for questions and answers that improve the Community! I'm following the other question with interest.

 

Claudia Landivar

Community Manager and Editor, Knowledge Base