HomeGuidesAPI Reference
GuidesAPI ReferenceGitHubAirheads Developer CommunityLog In

NAE can be integrated with external systems, such as security information and event management (SIEM) tools and log analytics engines. In addition, operators can use the APIs on other devices and applications on the network to request data from those systems and create a comprehensive picture of the network's state.

Creating A Slack Notification

This tutorial will teach you to easily create notifications by making a call to the Slack API endpoint.

Instructions for using the Slack API can be found here.

To prepare, we import the necessary libraries that are not already part of NAE.
For example:

from requests import POST

Adding the parameters

Step one is to add the required information to the ParameterDefinitions section of the script.
In this case, the Slack token is required for Slack channel and workspace authorization, and the Slack channel ID is required to identify the channel to which the message will be sent.

📘

Encryption

There are options in NAE to use encrypted tokens, obscuring sensitive details from any prying eyes.

For example:

'slack_token': {
        'Name': "Slack Bot OAuth Access Token",
        'Description': "Slack Bot OAuth Access Token",
        'Type': 'string',
        'Required': True,
        'Encrypted': True
},
'slack_channel': {
        'Name': "Slack Channel ID",
        'Description': "Slack Channel ID is at the end of the URL for that channel"
                        "for example https://yourTeam.../CTZ3GS5DK",
        'Type': 'string',
        'Required': True
}

Building the message

Secondly, we'll build the message. This can be as simple as creating a plain string with some meaningful text.
For example:

message = "Links are flapping! The culprit is this one: {}".format(interface_id)

Defining the API call function

Finally, we make the request to the Slack API endpoint, information about which can be found at the link above. Defining a function for each message is recommended.
For example:

def post_slack(message, channel, token, proxies):
    from requests import post
    post('https://slack.com/api/chat.postMessage',
         proxies=proxies,
         headers={'Authorization': 'Bearer {}'.format(token)},
         json={
             'text': message,
             'channel': channel
         })

And that's it!