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.
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.- Open the Create Topic panel: On the Topics list page, select Create Topic. If you need help finding the list page, see Listing Topics.
- For Name, type the following: Alarm Topic
- 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.
- 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.
-
Create the Slack subscription.
-
Create the SMS subscription.
-
Create the email subscription.
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.
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.
- Open the Create Alarm page.
- Open the navigation menu and click Observability & Management. Under Monitoring, click Alarm Definitions.
-
Select Create Alarm.
- For Alarm name, type the following: Utilization Alarm
-
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 -
Under Trigger rule, set up the alarm threshold.
Field Example value for this scenario Operator greater than Value 90 Trigger delay minutes 1 - 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. -
Select Save alarm.
- Open the Create Alarm page.
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 }