next_steps/readable_alerts/HumanReadableAlerts.YAML [96:132]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
              timestamp = parse(input_json['timestamp'], fuzzy_with_tokens=True)[0]
              timestamp1 = timestamp.strftime("%B %d %Y")
              timestamp2 = timestamp.strftime("%H:%M")
              # Write the first bit about the anomaly, what happened and when.
              response = "An anomaly in " + str(input_json['impactedMetric']['metricName']) + " was detected on " + timestamp1 + ' at ' + timestamp2 + ".\n"
              # Next grab the list of impacted time series
              num_of_time_series = len(input_json['impactedMetric']['relevantTimeSeries'])
              # Report the number of impacted time series to your user
              response += str(num_of_time_series) + " time series was impacted.\n\n"

              # Iterate over each time series, listing the dimensions and their value
              for ts in range(num_of_time_series):
                  response += "TimeSeries: " + str(num_of_time_series) + " was impacted on the following dimensions and values:\n"
                  for item in input_json['impactedMetric']['relevantTimeSeries'][ts]['dimensions']:
                      response += "\t" + item['dimensionName'] + " - " + item['dimensionValue'] + "\n"
                      
              # Report the anomaly score
              response += "\nThe Anomaly  score was: " + str(input_json['anomalyScore']) + "\n"
              
              # Generate a link to the console for the user to learn more
              runtime_region = os.environ['AWS_REGION']
              url = "https://" + runtime_region + ".console.aws.amazon.com/lookoutmetrics/home?region=" + runtime_region + "#"
              url += str(input_json['anomalyDetectorArn'])
              url += "/detectorDetails"
              response += "To learn more visit the Lookout for Metrics console at: " + url + " \n"
              return response

          def lambda_handler(event, context):
              # Call the create string function
              response = create_anomaly_string(input_json=event)
              # Send the string to SNS
              send_to_sns(message=response)
              # Report completed
              return {
                  'statusCode': 200,
                  'body': json.dumps('Message Delivered!')
              }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



next_steps/readable_alerts/readable_alerts.py [24:60]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    timestamp = parse(input_json['timestamp'], fuzzy_with_tokens=True)[0]
    timestamp1 = timestamp.strftime("%B %d %Y")
    timestamp2 = timestamp.strftime("%H:%M")
    # Write the first bit about the anomaly, what happened and when.
    response = "An anomaly in " + str(input_json['impactedMetric']['metricName']) + " was detected on " + timestamp1 + ' at ' + timestamp2 + ".\n"
    # Next grab the list of impacted time series
    num_of_time_series = len(input_json['impactedMetric']['relevantTimeSeries'])
    # Report the number of impacted time series to your user
    response += str(num_of_time_series) + " time series was impacted.\n\n"

    # Iterate over each time series, listing the dimensions and their value
    for ts in range(num_of_time_series):
        response += "TimeSeries: " + str(num_of_time_series) + " was impacted on the following dimensions and values:\n"
        for item in input_json['impactedMetric']['relevantTimeSeries'][ts]['dimensions']:
            response += "\t" + item['dimensionName'] + " - " + item['dimensionValue'] + "\n"
            
    # Report the anomaly score
    response += "\nThe Anomaly  score was: " + str(input_json['anomalyScore']) + "\n"
    
    # Generate a link to the console for the user to learn more
    runtime_region = os.environ['AWS_REGION']
    url = "https://" + runtime_region + ".console.aws.amazon.com/lookoutmetrics/home?region=" + runtime_region + "#"
    url += str(input_json['anomalyDetectorArn'])
    url += "/detectorDetails"
    response += "To learn more visit the Lookout for Metrics console at: " + url + " \n"
    return response

def lambda_handler(event, context):
    # Call the create string function
    response = create_anomaly_string(input_json=event)
    # Send the string to SNS
    send_to_sns(message=response)
    # Report completed
    return {
        'statusCode': 200,
        'body': json.dumps('Message Delivered!')
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



