Sending Alerts to Slack and Teams

Set up webhooks to trigger alerts for your integrations.

You can subscribe to events using webhooks and get notifications to Slack or Teams. A common use case is monitoring errors from an integration with ServiceNow.

Webhooks allow you to receive information about events as they happen in near real-time in LeanIX. For more information, see Webhooks.

Sending Alerts to Slack

Follow these steps:

  1. Make a POST request to the following endpoint:
    https://{SUBDOMAIN}.leanix.net/services/webhooks/v1/subscriptions

  2. In the subscription parameter, put the value from the code snippet below and change target_url and workspace_id.

    • workspace_id: To get your workspace ID, in the administration area, select API Tokens and copy the WorkspaceId value.
    • target_url: You can get this value from the incoming Webhook created in Slack.

    Subscription payload:

    {
        "deliveryType": "PUSH",
        "tagSets": [
          [
            "integrations",
            "statistics"
          ]
        ],
        "targetMethod": "POST",
        "identifier": "Integration Statistics2",
        "callback": "var payload = delivery.payload;\nvar text = payload. type+' with Scope: '+ payload.scope+' has status: '+ payload.progress+' and error count: '+ payload.errorCount;\ndelivery.payload = {\n   text : text\n}",
    "targetUrl": "target_url",
        "workspaceId": "workspace_id"
      }
    
  3. Modify the callback as shown below to send notifications only when synchronizations fail. Replace workspace_url with your value.

    Callback:

    "callback": "var payload = delivery.payload;\ndelivery.active = false;\nvar base_url = 'workspace_url';\nif(payload.errorCount > 0){\ndelivery.active = true;\nvar text = payload. type+' with Scope: '+ payload.scope+' has status: '+ payload.progress+' and error count: '+ payload.errorCount;\ntext += '. Synclog link : '+base_url+'/admin/synclog/'+ payload.synchronizationId;\n}\ndelivery.payload = {\n   text : text\n}"
    

📘

Alerts Triggered Only for Errors

The callback in the above example will only trigger an alert when an error is generated. This can be modified if required as per specific requirements. For more information, see Advanced: Manipulate Payload using Callback.

The webhook for notifications is set up. The following image shows an example notification message.

1356

Example Notification Message in Slack

Sending Alerts to Microsoft Teams

Before you start, learn how to configure a connector for a specific channel in the Microsoft Teams documentation.

Follow these steps:

  1. Make a POST request to the following endpoint:
    https://{SUBDOMAIN}.leanix.net/services/webhooks/v1/subscriptions

  2. Copy the url from the above and you will need this for the next steps to be used as target_url.

  3. In the subscription parameter, enter the value from the following code snippet and change workspace_url, target_url and workspace_id.

    {
        "deliveryType": "PUSH",
        "tagSets": [
            [
                "integrations",
                "statistics"
            ]
        ],
        "targetMethod": "POST",
        "identifier": "Integration Statistics for Teams",
        "callback": "var payload = delivery.payload;\ndelivery.active = false;\nvar base_url = 'workspace_url';\nif(payload.errorCount > 0){\ndelivery.active = true;\nvar text = payload. type+' with Scope: '+ payload.scope+' has status: '+ payload.progress+' and error count: '+ payload.errorCount+'.';\ntext += \" Click **Sync Log** to check details!\";\n}\ndelivery.payload =   {\n    \"@context\": \"https://schema.org/extensions\",\n    \"@type\": \"MessageCard\",\n    \"themeColor\": \"0072C6\",\n    \"title\": payload. type+\" Failed\",\n    \"text\": text,\n    \"potentialAction\": [\n        {\n            \"@type\": \"OpenUri\",\n            \"name\": \"Sync Log\",\n            \"targets\": [\n                {\n                    \"os\": \"default\",\n                    \"uri\": base_url+'/admin/synclog/'+ payload.synchronizationId\n                }\n            ]\n        }\n    ]\n}",
        "targetUrl": "target_url",
        "workspaceId": "workspace_id"
    }
    

The webhook for notifications is set up. The following image shows an example notification message.

992

Example Notification Message in Microsoft Teams