Recently, I discovered that MongoDB Atlas and Mongo Ops Manager do not have the ability to send alerts directly to Microsoft Teams. Since I’ve been using rust more frequently, I decided to create a small web service that receives MongoDB alerts, and transforms them into compatible Microsoft Teams Cards, before posting them to a specified Teams incoming webhook.

You can browse the git repo here. I am definitely no rust expert, so I welcome pull requests or issues.

Overview

The executable listens on the following paths when running, for proper json posts:

/echo:
    This will return the json back to the user, good for debugging
/stdout:
    This will save the posted body to stdout within the container
/alert:
    This will receive posted alerts and transform them before sending them to the Microsoft Teams webhook
/testalert:
    This will receive posted alerts, and return the transformed card back to the client


Usage

The two primary ways to utilize mongo_alerts_2teams are either through a docker container, or through a compiled binary.

Running the docker container:

docker run -p 8000:8000 verticaleap/mongo_alert_2teams:0.1 --url "https://outlook.office.com/webhook/"

Compiling from source. First make sure you have rust installed:

cargo install --git https://github.com/findelabs/mongo_alerts_2teams.git

Once you have either a running container or binary, you can add the link to either Atlas or Mongo Ops Manager as a webhook for alerts. This link should look something like http://myserver:8000/alert.


Examples

You can use this test alert to see if you container or binary is working properly. First go ahead and start up mongo_alerts_2teams on port 8000. Then post this body to http://localhost:8000/test/alert:

curl -s http://localhost:8000/testalert -d "{
  \"alertConfigId\":\"5d2f6c93aa9b4c5735a37475\",
  \"clusterId\":\"5e1cc8d07a924c28f0847da8\",
  \"clusterName\":\"replicaset_name\",
  \"created\":\"2020-07-23T18:24:06Z\",
  \"eventTypeName\":\"PRIMARY_ELECTED\",
  \"groupId\":\"5e11d830a59b4c5bd7dd011a\",
  \"hostId\":\"8561bbbdc6d06fed0f983a344aa8366a\",
  \"hostnameAndPort\":\"localhost:27017\",
  \"id\":\"5f19a5c654964862806e9715\",
  \"links\":[
    {
      \"href\":\"http://localhost:8080/api/public/v1.0/groups/5e1ad8b08a9b4c5bd71d011a/alerts/5f1fd5c6549d486d80719715\",
  \"rel\":\"self\"
    }
  ],
  \"replicaSetName\":\"replicaset_name\",
  \"status\":\"CLOSED\",
  \"typeName\":\"REPLICA_SET\",
  \"updated\":\"2020-07-23T18:24:06Z\"
}" 

This should return a json doc like the one below, which is the MongoDB alert transformed into a card that Teams recognizes:

{
  "@context": "https://schema.org/extensions",
  "@type": "MessageCard",
  "sections": [
    {
      "activityImage": "https://company-30077.frontify.com/api/screen/download/eyJpZCI6MzQwMzI2NCwidmVyc2lvbiI6IjIwMTktMDgtMDIgMTk6Mjg6MDYifQ:frontify:DkJTntON9g0YByA8Q_M4vJX_XxO7je1rn7PJN6RJ_TI/?download&title_as_filename&track",
      "activitySubtitle": null,
      "activityTitle": "Replica set elected a new primary",
      "facts": [
        {
          "name": "Replicaset",
          "value": "\"replicaset_name\""
        },
        {
          "name": "Server",
          "value": "\"localhost:27017\""
        },
        {
          "name": "Type",
          "value": "\"REPLICA_SET\""
        }
      ]
    }
  ],
  "summary": "MongoDB Alert Card",
  "themeColor": "12924F",
  "title": "Alert Closed"
}




Has been tested on Ubuntu, MongoDB Atlas, and Ops Manager 4.2.15