This topic explains Avi Load Balancer integration with Slack to monitor alerts.

Slack is a cloud-based tool which provides IRC-like features: persistent chatrooms, private groups, direct messaging, and so on. WebHook is an event-notification function through HTTP Post messages. An application integrated with WebHooks, POSTs a message to a URL when certain criteria are matched. The Avi Load Balancer can be configured to support the WebHook feature using ControlScripts.

Configuration

The following are the two ways to integrate Slack with Avi Load Balancer to monitor alerts:

  • Using Slack Email App

  • Using WebHook ControlScript

Configuration using Slack Email App

Select the channel in the Slack Email app for which alerts must be posted. The Slack Email app provides a unique email id. Set this email id in the Alerts Action on the Avi Load Balancer user interface. For more information about configuring Alerts Action, see Configuring NSX Advanced Load Balancer to send alerts to the WebHooks URL.

For more information on sending emails to Slack, see Sending Emails to Slack.

Configuration using Avi Load Balancer ControlScript for WebHook

The use of Avi Load Balancer ControlScript for WebHook consists of the following two main steps:

  • Obtaining WebHook URL

  • Configuring Avi Load Balancer to send alerts to the configured WebHook URL

Obtaining WebHook URL

The ControlScript, usually, a Python script, is used as an action alert. Follow the steps mentioned below to obtain the WebHook URL:

  • Log in to Slack URL as an administrator.

  • Select the channel for which alerts need to be configured.

Click the Add Incoming Webhooks Integration button.



Copy the unique URL from the next window. This URL will be used in the ControlScript.

Configuring Avi Load Balancer to Send Alerts to the WebHooks URL

Navigate to Operations > Alerts > Alert Actions and select the Create option.

Provide a name of the action, select Alert Level as high, and create a new ControlScript. In the example mentioned below, a new ControlScript named Pool Down is created.

Use the WebHook URL created in the previous step as the content for ControlScript.

Following is the sample URL tested in the lab. Change the webhook_url & slack_data according to the requirement. Set the webhook_url to the one provided by Slack while creating the WebHook.

#!/usr/bin/python

 import json
 import requests

 requests.packages.urllib3.disable_warnings()
 
 webhook_url = 'https://hooks.slack.com/services/####' 
 slack_data = {'text': "Sev1 Incident: Pool is Down :computer:"}

 response = requests.post(
    webhook_url, data=json.dumps(slack_data),
    headers={'Content-Type': 'application/json'}
 )
 if response.status_code != 200:
    raise ValueError(
        'Request to slack returned an error %s, the response is:\n%s'
        % (response.status_code, response.text)
 )

Navigate to Operations > Alerts > Alert Config and click Create to set a new alert.

Complete the configuration and select Pool Down from the Alert Action drop-down menu.





Once the event is triggered, the corresponding alert will appear in the Slack channel. The log for the configured alert appears in the Alert Actions tab under Operations > Alerts.


Note:

Any error in the execution of the ControlScript will also appear in the same location.

Configuring WebHook Using REST API

For more information on configuring WebHook using the Avi Load Balancer REST API, see WebHook API.