Send Alerts to Slack and Teams

Leveraging Webhooks to trigger alerts for Integrations such as ServiceNow

Overview

We often have requests from customers that they want to be notified when an integration sync fails and for error monitoring. In this document we provide details regarding sending alerts to Slack and Microsoft Teams using Webhooks. One common use case we have seen implemented is to monitor ServiceNow errors.

Webhooks allow you to receive information about events as they happen in near real-time in LeanIX. Refer to documentation for more details.

Send alerts to Slack

If you have a dedicated instance of LeanIX please set the url base to your unique domain:
https://.leanix.net

Please see Available APIs for more information regarding endpoints.

  • Add your API token at the top of the page.

  • In the Subscription parameter put the value from the code snippet below and do not forget to change target_url and workspace_id.

  • workspace_id can be fetched from Administration > Developers > API Tokens. You will see the Workspace ID on top of the page.

  • target_url can be the taken from Incoming Webhook created in Slack.

{
    "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"
  }
  • Modify the callback as per below in order to notify only when the Sync fails.
  • Change workspace_url in the below to reflect your LeanIX workspace.Eg. workspace_url: https://app.leanix.net/demoWS
"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.
More information about modifying payload using callback available here.

Message in Slack on failure.Message in Slack on failure.

Message in Slack on failure.

Send alerts to Microsoft Teams

  • Go to the POST end point below :-

https://eu-svc.leanix.net/services/webhooks/v1/docs/#!/subscriptions/createSubscription

  • US customers please utilize:

https://us-svc.leanix.net/services/webhooks/v1/docs/#!/subscriptions/createSubscription

  • Add your API token at the top of the page.

  • Check the link on how to enable Webhooks connector to a Specific Channel.

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

  • In the Subscription parameter put the value from the code snippet below and do not forget to change workspace_url, target_url and workspace_id. Eg. workspace_url :

https://app.leanix.net/demoWS

{
    "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"
}
Message in Teams on failure.Message in Teams on failure.

Message in Teams on failure.