Scenario B: Sending Alarm Messages to Slack and SMS

Set up automatic notifications to a Slack channel and an SMS phone number when alarms are triggered.

This scenario involves setting up a Slack endpoint for a channel and creating an alarm  that sends a message to both that channel and an SMS phone number. When the alarm fires, the Notifications service sends the alarm message to the destination topic, which then fans out to the topic's subscriptions. In this scenario, the topic's subscriptions include the Slack channel and SMS phone number as well as your email address.

This image shows Notifications in the context of a scenario that sends alarm messages to Slack.

Required IAM Policy

To use Oracle Cloud Infrastructure, you must be granted security access in a policy  by an administrator. This access is required whether you're using the Console or the REST API with an SDK, CLI, or other tool. If you get a message that you don't have permission or are unauthorized, verify with your administrator what type of access you have and which compartment  to work in.

If you're a member of the Administrators group, you already have the required access to execute this scenario. Otherwise, you need access to Monitoring and Notifications.

Task 1: Set up your Slack endpoint

Create an incoming webhook to your Slack app.

Example of an incoming webhook to a Slack app (equivalent to the Slack endpoint for your subscription): https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Once you set up your Slack endpoint, you can complete all other scenario steps in the Console. Alternatively, you can use the Oracle Cloud Infrastructure CLI or API, which lets you execute the individual operations yourself.

Task 2: Create the Topic

For help with troubleshooting, see Troubleshooting Notifications.

  • Note

    Another Console workflow for this scenario involves creating a new topic and the first subscription when you create the alarm, then creating additional subscriptions in that topic.
    1. Open the Create Topic panel: On the Topics list page, select Create Topic. If you need help finding the list page, see Listing Topics.
    2. For Name, type the following: Alarm Topic
    3. Select Create.
  • Use the oci ons topic create command and required parameters to create a topic:

    oci ons topic create --name <name> --compartment-id <compartment_OCID>

    Example:

    oci ons topic create --name "Alarm Topic" --compartment-id "<compartment_OCID>"

    For a complete list of parameters and values for CLI commands, see the Command Line Reference for Notifications.

  • Run the CreateTopic operation to create a topic.

    Example:

    POST /20181201/topics
    Host: notification.us-phoenix-1.oraclecloud.com
    <authorization and other headers>
    {
      "name": "Alarm Topic",
      "compartmentId": "<compartment_OCID>"
    }

Task 3: Create the Subscriptions

For help with troubleshooting, see Troubleshooting Notifications.

    1. Select the topic that you created earlier (example name was Alarm Topic): On the Topics list page, select the topic that you want to work with. If you need help finding the list page or the topic, see Listing Topics.
    2. Create the Slack subscription.
      1. Open the Create Subscription panel: In the detail page for the topic, select Create Subscription.
        The Create Subscription panel opens.
      2. For Protocol, select Slack.
      3. Fill in the remaining fields.
        Field Description
        URL

        Type (or copy and paste) the Slack endpoint that you created earlier. Include the webhook token.

        Example endpoint:

        https://hooks.slack.com/services/<webhook-token>
      4. Select Create.
      5. Confirm the new Slack subscription: Navigate to the confirmation URL that was sent to Slack.
    3. Create the SMS subscription.
      1. Open the Create Subscription panel: In the detail page for the topic, select Create Subscription.
        The Create Subscription panel opens.
      2. For Protocol, select SMS.
      3. Fill in the remaining fields.
        Field Description
        Country Select the country for the phone number. See Before You Begin.
        Phone Number Enter the phone number, using E.164 format.
      4. Select Create.
      5. Confirm the new SMS subscription: Follow the instructions received on the phone.
    4. Create the email subscription.
      1. Open the Create Subscription panel: In the detail page for the topic, select Create Subscription.
        The Create Subscription panel opens.
      2. For Protocol, select Email.
      3. Fill in the remaining fields.
        Field Description
        Email Type an email address.
      4. Select Create.
      5. Confirm the new email subscription: Open the email and navigate to the confirmation URL.
  • Note

    After creating the subscriptions, confirm them.

    Use the oci ons subscription create command and required parameters to create each subscription:

    oci ons subscription create --protocol <subscription_type> --subscription-endpoint <endpoint> --compartment-id <compartment_OCID> --topic-id <topic_OCID>

    Slack subscription example:

    oci ons subscription create --protocol "SLACK" --subscription-endpoint "<slack-endpoint>" --compartment-id "<compartment_OCID>" --topic-id "<topic_OCID>"

    SMS subscription example:

    oci ons subscription create --protocol "SMS" --subscription-endpoint "<sms-endpoint>" --compartment-id "<compartment_OCID>" --topic-id "<topic_OCID>"

    Email subscription example:

    oci ons subscription create --protocol "EMAIL" --subscription-endpoint "john.smith@example.com" --compartment-id "<compartment_OCID>" --topic-id "<topic_OCID>"

    For a complete list of parameters and values for CLI commands, see the Command Line Reference for Notifications.

  • Note

    After creating the subscriptions, confirm them.

    Run the CreateSubscription operation to create each subscription.

    Slack subscription example:

    POST /20181201/subscriptions
    Host: notification.us-phoenix-1.oraclecloud.com
    <authorization and other headers>
    {
      "topicId": "<topic_OCID>",
      "compartmentId": "<compartment_OCID>",
      "protocol": "SLACK",
      "endpoint": "<slack-endpoint>"
    }

    SMS subscription example:

    POST /20181201/subscriptions
    Host: notification.us-phoenix-1.oraclecloud.com
    <authorization and other headers>
    {
      "topicId": "<topic_OCID>",
      "compartmentId": "<compartment_OCID>",
      "protocol": "SMS",
      "endpoint": "<sms-endpoint>"
    }

    Email subscription example:

    POST /20181201/subscriptions
    Host: notification.us-phoenix-1.oraclecloud.com
    <authorization and other headers>
    {
      "topicId": "<topic_OCID>",
      "compartmentId": "<compartment_OCID>",
      "protocol": "EMAIL",
      "endpoint": "john.smith@example.com"
    }

Task 4: Create the Alarm

For help with troubleshooting, see Troubleshooting Notifications.

    1. Open the Create Alarm page.
      1. Open the navigation menu and click Observability & Management. Under Monitoring, click Alarm Definitions.
      2. Select Create Alarm.

    2. For Alarm name, type the following: Utilization Alarm
    3. Under Metric description, select the metric, interval, and statistic.

      Field Example value for this scenario
      Compartment Select the compartment  that contains the instance you want to monitor for high CPU utilization.
      Metric namespace oci_computeagent
      Metric name CpuUtilization
      Interval 1m
      Statistic Count
    4. Under Trigger rule, set up the alarm threshold.

      Field Example value for this scenario
      Operator greater than
      Value 90
      Trigger delay minutes 1
    5. Under Notifications, Destinations, select the topic that you created earlier.
      Field Example value for this scenario
      Destination Service Notifications Service
      Compartment Select the compartment  that contains the topic that you created earlier.
      Topic Select the topic that you created earlier.
    6. Select Save alarm.

  • Use the oci monitoring alarm create command and required parameters to create an alarm:

    oci monitoring alarm create --display-name <name> --compartment-id <compartment_OCID> --metric-compartment-id <compartment_OCID> --namespace <metric_namespace> --query-text <mql_expression> --severity <level> --destinations <file_or_text> --is-enabled <true_or_false>

    Example:

    oci monitoring alarm create --display-name "Utilization Alarm" --compartment-id "<compartment_OCID>" --metric-compartment-id "<compartment_OCID>" --namespace "oci_computeagent" --query-text "CpuUtilization[1m].count() > 90" --severity "CRITICAL" --destinations "<topic_OCID>" --is-enabled true

    For a complete list of parameters and values for CLI commands, see the Command Line Reference for Monitoring.

  • Run the CreateAlarm operation to create an alarm.

    Example:

    POST /20180401/alarms
    Host: telemetry.us-phoenix-1.oraclecloud.com
    <authorization and other headers>
    {
      "displayName": "Utilization Alarm",
      "compartmentId": "<compartment_OCID>",
      "metricCompartmentId": "<compartment_OCID>",
      "namespace": "oci_computeagent",
      "query": "CpuUtilization[1m].count() > 90",
      "severity": "CRITICAL",
      "destinations":
      [
        "<topic_OCID>"
      ],
      "isEnabled": true
    }