Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
peng_wang6
Product and Topic Expert
Product and Topic Expert
1,862

This is a simple example on how to integrate SAP Cloud ALM with a SLACK channel, to post the SAP Cloud ALM alerting information.
This blog referred following help documentation:

Create a new Slack Channel

  • Add a new channel as an administrator of your SLACK workspace.

    peng_wang6_0-1727745840092.png
  • Channel ID can be found in the "View Channel Details", this might be used in the mapping rule.

    peng_wang6_13-1727751795399.png

Build a new APP for the incoming webhook message.

  1. Build a new application from scratch

    peng_wang6_1-1727746197742.png
    peng_wang6_2-1727746248317.png
    peng_wang6_3-1727746295723.png
  2. Define the Scopes for the new application.
    Under the "Oauth& Permissions" tab, add the following Bot Token Scopes
    • incoming-webhook
    • channels:read
    • chat:write.customize
    • chat:write

      peng_wang6_4-1727746339144.png

       

  3. Install the application to the workspace
    peng_wang6_5-1727746603447.png
  4. Get the Bot user Oauth Token. 
    The Bot user Oauth Token will be used to create the BTP Destination in the next step.
    peng_wang6_6-1727746664430.png

     

Create a Destination under the SAP Cloud ALM subaccount

  1. Access the SAP Cloud ALM subaccount in the SAP BTP Cockpit 
  2. Under the Connectivity -> Destinations tab, to create a HTTP destination with the following details
    • Type: HTTP
    • URL: https://slack.com/api/
    • Proxy type: Internet
    • Authentication: No Authentication
    • Additional Properties:
      URL.headers.Authorization =
      Bearer <BOT User Oauth token>
      (Missing this property might lead to "not_authed" response)

      peng_wang6_10-1727747711406.png

Create a new Webhook in SAP Cloud ALM - External API Management with the BTP destination.

  1. Access to the SAP Cloud ALM tenant
  2. Goto application "External API Management" under the "Administration" tab
  3. In the Webhooks Management tab, create a new webhook with the following details
    • Destination Source: BTP Destination
    • Path: chat.postMessage
    • Destination Id: <destination created in the above step>
    • Ext. Resource Type: Chat
      peng_wang6_11-1727748226237.png

Create a new mapping rule for the Slack integration.

  1. Go to the Mappings Management tab
  2. Create a new mapping rule for the Slack integration with the following details:peng_wang6_12-1727749020070.png

    Here is a sample JSON file for the mapping rule. 
    Please exchange the parameters "username" and "channel" to your channel ID and user name.
    Refer to this documentation for more information on how to properly configure the Mappings using the Resource Changes API

 

{
    "_information": {
        "_version": "1",
        "_source": "SAP Cloud ALM Event Situation",
        "_destination": "Slack",
        "_name": "SAP Cloud ALM Event Situations to Slack",
        "_comment": "SLACK - Channel #calm(Workplace CALM)"
    },
    "switches": [
        {
            "name": "switchPriority",
            "cases": [
                {
                    "when": "FATAL",
                    "then": "Highest"
                },
                {
                    "when": "ERROR",
                    "then": "High"
                },
                {
                    "when": "WARNING",
                    "then": "Low"
                },
                {
                    "when": "INFO",
                    "then": "Lowest"
                }
            ],
            "default": "Lowest"
        }
    ],
    "structure": {
        "request": {
            "ok": true,
            "username": "<user name>",
            "channel": "<channel ID>",
            "blocks": [
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": "*SAP Cloud ALM Event: EVENT-SITUATION.CREATED*"
                    }
                },
                {
                    "type": "section",
                    "text": {
                        "type": "plain_text",
                        "text": "Subject: #{subject}"
                    }
                },
                {
                    "type": "section",
                    "text": {
                        "type": "plain_text",
                        "text": "Description: rating:#{rating} - priority:${SWITCH(switchPriority,rating)} - serviceType:#{serviceType} - serviceId:#{serviceId} - eventType:#{eventType} - eventName:#{eventName}"
                    }
                },
                {
                    "type": "section",
                    "text": {
                        "type": "plain_text",
                        "text": "workNotes: #{workNotes}"
                    }
                }
            ]
        },
        "response":
        {
            "chatCreated": true
        }
    },
    "eventTypeMapping": {
        "_comment": "Specificeventtypemapping",
        "operationMappings": [
            {
                "eventType": "EVENT-SITUATION.CREATED",
                "operation": "POST",
                "responseRoot": ""
            },
            {
                "eventType": "EVENT-SITUATION.CLOSED",
                "operation": "POST",
                "responseRoot": "",
                "structure": {
                    "request": {
                        "ok": true,
                        "username": "<user name>",
                        "channel": "<channel ID>",
                        "blocks": [
                            {
                                "type": "section",
                                "text": {
                                    "type": "mrkdwn",
                                    "text": "*SAP Cloud ALM Event: EVENT-SITUATION.CLOSED*"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "Subject: #{subject}"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "Description: rating:#{rating} - priority:${SWITCH(switchPriority,rating)} - serviceType:#{serviceType} - serviceId:#{serviceId} - eventType:#{eventType} - eventName:#{eventName}"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "workNotes: #{workNotes}"
                                }
                            }
                        ]
                    },
                    "response":
                    {
                        "chatCreated": true
                    }
                }

            },
            {
                "eventType": "EVENT-SITUATION.UPDATED",
                "operation": "POST",
                "responseRoot": "",
                "structure": {
                    "request": {
                        "ok": true,
                        "username": "<user name>",
                        "channel": "<channel ID>",
                        "blocks": [
                            {
                                "type": "section",
                                "text": {
                                    "type": "mrkdwn",
                                    "text": "*SAP Cloud ALM Event: EVENT-SITUATION.UPDATED*"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "Subject: #{subject}"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "Description: rating:#{rating} - priority:${SWITCH(switchPriority,rating)} - serviceType:#{serviceType} - serviceId:#{serviceId} - eventType:#{eventType} - eventName:#{eventName}"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "workNotes: #{workNotes}"
                                }
                            }
                        ]
                    },
                    "response":
                    {
                        "chatCreated": true
                    }
                }
            },
            {
                "eventType": "EVENT-SITUATION.PING",
                "operation": "POST",
                "responseRoot": "",
                "structure": {
                    "request": {
                        "ok": true,
                        "username": "<user name>",
                        "channel": "<channel ID>",
                        "blocks": [
                            {
                                "type": "section",
                                "text": {
                                    "type": "mrkdwn",
                                    "text": "*SAP Cloud ALM Event: EVENT-SITUATION.PING*"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "Subject: #{subject}"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "Description: rating:#{rating} - priority:${SWITCH(switchPriority,rating)} - serviceType:#{serviceType} - serviceId:#{serviceId} - eventType:#{eventType} - eventName:#{eventName}"
                                }
                            },
                            {
                                "type": "section",
                                "text": {
                                    "type": "plain_text",
                                    "text": "workNotes: #{workNotes}"
                                }
                            }
                        ]
                    },
                    "response":
                    {
                        "chatCreated": true
                    }
                }
            }
        ]
    }
}​

 

 

 

Create a new Subscription with the Webhook and Mapping rule created in the above steps.

  1. Go to the Mappings Management tab
  2. Create a new mapping rule for the Slack integration with the following details
    • Resource Type: Event Situation
    • Wbehook: <the webhook created in the above step>
    • Mapping: <the mapping created in the above step>
    • Type: Built-in
      peng_wang6_15-1727751968942.png

       

Testing the Slack integration under any Alert generated in the SAP Cloud ALM Monitoring application

  1. In any monitoring applications under the Operation tab
  2. Open an existing alert, and click on the Actions button
  3. Send chat notification
    peng_wang6_16-1727752065742.png
  4. Select the Subscription created and click on OK
    peng_wang6_17-1727752117616.png
  5. Check whether the message can be sent to the Slack channel. 
    peng_wang6_18-1727752163529.png

Verify the Console log in the External API Management for troubleshooting

In case there is some error happens, or the notification can't be sent successfully. It is possible to check the console log in the "Console" tab of the "External API Management" application for more details.

peng_wang6_0-1727753687892.png


2 Comments