Edgio

Health Notifications via Amazon SNS

Live Slicer health data may be made more widely available through the following workflow:
  1. A Live Slicer pushes health data to Amazon SNS whenever one of the following conditions occur:
    • An alert is generated for a key metric whenever the status of a monitored metric changes from “Healthy” to either “Warning” or “Critical.”
    • The status of a key metric resumes “Healthy” status.
  2. Amazon SNS broadcasts Live Slicer health data to one or more destination(s) (e.g., mobile device, web server, or Slack).
Get started with Amazon SNS for free through its SNS free tier. Learn more.
The Live Slicer formats health data using JSON. This data may then be filtered via custom code. This article explains how to strip out additional data generated by Amazon SNS via a custom function in Amazon Lambda.

Quick Start

Perform the following steps to set up Live Slicer health notifications:
  1. Configure health monitoring for the desired Live Slicer.
    Live Slicer health data may only be sent for metrics that are being monitored. For example, a custom monitoring configuration may be used to turn off monitoring and health notifications for one or more metrics for a particular Live Slicer.
  2. Set up an Amazon SNS topic.
    Our service pushes Live Slicer health and failover notifications to the same Amazon SNS topic.
  3. Configure the Live Slicer to push health notifications to an Amazon SNS topic.
  4. Configure Amazon SNS to broadcast health notifications to the desired destination(s). This section explains how to set up Amazon SNS and Lambda to broadcast health notifications to a Slack channel.

Set up an Amazon SNS Topic

Amazon SNS communicates with publishers and subscribers through a “topic.” For the purpose of this article, a Live Slicer will assume the role of a publisher, while a Slack channel will assume the role of the subscriber.
Our service pushes Live Slicer health and failover notifications to the same Amazon SNS topic.
Amazon SNS may be configured to broadcast data to multiple types of subscribers (e.g., web server, mobile device, email, etc.).
Perform the following steps to create a topic:
  1. Sign in to the Amazon AWS Management Console. If you don’t have an AWS account, sign up for one.
  2. Open the Amazon SNS console.
  3. Click Get started.
    Amazon SNS may require Amazon SES (i.e., Amazon Simple Email Service). Please sign up for the Amazon SES service if an error message appears within the SNS dashboard.
  4. From the upper-right corner, change your location to: US West (Oregon) us-west-2.
  5. Click Topics from the side navigation pane.
  6. Click Create topic.
  7. Click Standard.
    Our service does not support pushing notifications to a First-In-First-Out (FIFO) topic.
  8. In the Name option, assign a unique name (e.g., marketing-live-slicer) to the topic.
  9. Optional: If notifications will be sent over SMS, set the “Display name” option to the desired name.
  10. Expand the Access policy section.
  11. From the Define who can publish messages to the topic option, select Only the specified AWS accounts.
  12. Set the Only these AWS users option to our AWS account ID: 545191325524
  13. Click Create topic.
  14. Copy the topic’s ARN.

Configure Communication with Amazon SNS

Both of the following configurations must be defined before the Live Slicer will push health information to Amazon SNS:
  1. Create a notification profile that determines when SNS push notifications will be triggered.
  2. Assign the above notification profile to each desired Live Slicer.
    • Navigate to the Live Slicer Monitoring dashboard. From the main menu, navigate to Services and then click Monitoring 2.0.
    • From the Saved Views option, select a Slicer View that contains the desired Live Slicer.
    • Click on the desired Live Slicer.
    • From the right-hand pane, set the ((Active Notification Profile)) option to the notification profile created in step 1.
  3. Define the ARN topic to which Live Slicer health and failover notifications will be sent.
    • Navigate to the Notifications page: From the Live Slicer Monitoring dashboard, navigate to Settings > Notifications.
    • Click Update SNS Topic from the right-hand pane.
    • Set the Update your SNS Topic ARN option to the ARN for the topic created above.
    • Click Save Topic ARN.

Integrate Slack with Amazon SNS

Amazon SNS can broadcast notifications to various subscribers (e.g., mobile devices) using different delivery methods (e.g., HTTP, email, AWS Lambda, etc.).
The configuration performed up to this point enables the Live Slicer to send notifications to Amazon SNS. This section explains how to push those notifications from Amazon SNS to a Slack channel. Integrating Amazon SNS with Slack involves the following steps:
  1. Set up a Slack webhook.
  2. Create an Amazon Lambda function that subscribes to the Amazon SNS topic.

Set Up a Slack Webhook

Slack requires a webhook to be created before it can post messages from external sources (e.g., Amazon SNS).
Learn how to create a Slack webhook.

Subscribe to an SNS Topic via Amazon Lambda

Amazon SNS needs to be informed of the above webhook before it can send data to a Slack channel. This task can be performed using Amazon Lambda, a compute service that runs code in response to events (e.g., when data is pushed from a Live Slicer to Amazon SNS).
View Amazon Lambda’s documentation.
This section creates a Lambda function in Python that performs the following tasks:
  • Subscribes to an SNS topic.
  • Identifies the Slack webhook through which it will post messages to a Slack channel.
  • Strips out data added by Amazon SNS.
You can add custom code to this function to tailor how messages are posted to a Slack channel (e.g., filter notifications by Live Slicer).

Create a Lambda Function

Perform the following steps to create a Lambda function:
  1. Open the Amazon Lambda console.
  2. Click Get Started Now.
  3. Click Blank Function.
  4. Click the dashed box and then select SNS as the trigger for this function.
  5. Verify that the SNS topic created earlier in this article is selected in the SNS topic option.
  6. Mark the Enable trigger option.
  7. Click Next.
  8. Configure the Lambda function :
    • Name: Set the Name option to the name of the function (e.g., forward_to_slack).
    • Description: Set the Description option to a brief description for the purpose of the function (e.g., Send Live Slicer information to a Slack channel.).
    • Runtime: Set the Runtime option to Python 2.7.
    • Code: Set the Lambda function code option to the following code:
      python
      1import json
      2import urllib2
      3
      4def forward_to_slack(event, context):
      5 # The URL for your Slack Channel's webhook
      6 url = "https://hooks.slack.com/services/ABCDE1234/FGHIJ5678/KLMNOPQRSTUV901234567890"
      7
      8 # Format the message
      9 try:
      10 # Try to navigate to the Message that was sent via SNS and strip out the
      11 # rest of the delivery information
      12 slack_data = {"text": str(event['Records'][0]['Sns']['Message'])}
      13 except:
      14 slack_data = {"text": str(event)}
      15
      16 # Dump the json to prepare it for sending
      17 data = json.dumps(slack_data)
      18
      19 # Create the request
      20 req = urllib2.Request(url, data)
      21
      22 # Send request
      23 urllib2.urlopen(req)
      Update the webhook URL defined in the code to point to the one copied in the Setting up a Slack Webhook section.
    • Handler: Set the Handler option to lambda_function. and then append the name of the function defined in the Name option (e.g., lambda_function.forward_to_slack).
    • Role: Set the Role option to Create new role from template(s).
    • Role name: Set the Role name option to the name that will be assigned to the new role (e.g., lambda_basic_execution).
    • Click Next.
  9. Amazon Lambda will now allow you to review the function that will be created. Verify the correct SNS topic has been selected and that the Lambda function configuration.
  10. Click Create function. Amazon Lambda will now automatically post health data to a Slack channel as it is provided by a Live Slicer.

Notification Data Format

Once an alert is triggered or upon resuming “Healthy” status, a Live Slicer sends information that describes the change in JSON format. Each parameter sent in this health notification is described below.
ParameterDescription
slicer_owner_usernameIndicates the email address through which the Live Slicer authenticates to the system. This email address is defined by the username setting in the Live Slicer configuration file (i.e., uplynk.conf).
old_metric_healthIndicates the state of the metric identified by the metric_name parameter prior to this change in status. Valid values are:
- healthy: Metric did not meet or exceed its warning or critical threshold.
- warning: Metric met or exceeded its warning threshold, but remained below its critical threshold.
- critical: Metric met or exceeded its critical threshold.
- neutral: Monitoring information is unavailable because the Live Slicer was inactive.
metric_critical_thresholdIndicates the threshold that must be met before the metric identified by the metric_name parameter enters a critical state. This threshold is defined in the monitoring rule assigned to the Live Slicer. Examples:
- 8 frames: Threshold value is 8, unit is “frames”.
- None seconds: No threshold defined, unit is “seconds”.
- null: Metric cannot be assigned a critical threshold value.
current_metric_healthIndicates the current state of the metric identified by the metric_name parameter. Valid values are:
- healthy: Metric did not meet or exceed its warning or critical threshold.
- warning: Metric met or exceeded its warning threshold, but remained below its critical threshold.
- critical: Metric met or exceeded its critical threshold.
slicer_current_healthIndicates the current health of the Live Slicer defined in the slicer parameter. Valid values are:
- healthy: Live Slicer is not experiencing warning or critical levels for any monitored metric.
- warning: Live Slicer is experiencing warning levels for one or more monitored metrics.
- critical: Live Slicer is experiencing critical levels for one or more monitored metrics.
slicerIndicates the name of the Live Slicer that pushed the current health notification.
metric_warning_thresholdIndicates the threshold that must be met before the metric identified by the metric_name parameter enters a warning state. This threshold is defined in the monitoring rule assigned to the Live Slicer. Examples:
- 8 frames: Threshold value is 8, unit is “frames”.
- None seconds: No threshold defined, unit is “seconds”.
- null: Metric cannot be assigned a warning threshold value.
current_metric_valueIndicates the metric’s value at the time defined by the utc_time parameter. Examples:
- 8 frames: Metric’s value is 8, unit is “frames”.
- TS unicast :1234 1920x1080: Description of the signal for “Signal Status” when a signal is detected.
- no signal: Reported for “Signal Status” when a signal is not detected.
utc_timeIndicates the date and time (UTC) at which the change in metric health took place. Syntax: YYYY-MM-DD hh:mm:ss.ffffff
Sample value: 2017-01-16 19:40:53.605533
metric_nameIdentifies the metric that triggered the change in Live Slicer health.

Sample Health Notification Data

The following sample data indicates that the Live Slicer’s signal was restored allowing it to resume “healthy” status.
JSON
1{
2 "slicer_owner_username": "joe@mycompany.com",
3 "old_metric_health": "critical",
4 "metric_critical_threshold": null,
5 "current_metric_health": "healthy",
6 "slicer_current_health": "healthy",
7 "slicer": "MySlicer",
8 "metric_warning_threshold": null,
9 "current_metric_value": "TS unicast :1234 1920x1080",
10 "utc_time": "2017-01-16 19:35:49.105642",
11 "metric_name": "Signal Status"
12}