AlertOps and CloudTrail

AlertOps’ alert management system can be integrated with CloudTrail to receive and respond to critical (predefined status mappings) alarms/alerts through email, SMS, push notification or phone alerts. AlertOps would ensure that the alert would reach the appropriate team by using proper workflows, escalation policies and schedules. Based on your ruleset, incidents can be automatically opened and closed, depending on whether CloudTrail reports a problem or a recovery.

The above scenario and scope for integration is due to the fact that AlertOps has a very flexible and simple API/Webhook configuration feature that can be leveraged with CloudTrail's logging and notification capability.

AlertOps has to be subscribed to a particular SNS Topic in order to pull messages from the topic and manage them accordingly. This SNS topic would be attached to a CloudWatch/CloudTrail event/log metric alarm, that would execute this particular topic, when an event/log alarm occurs.

Setup a CloudTrail ‘Trail’

  • Ensure CloudTrail is enabled on your AWS account when you create the account. When activity occurs in any AWS service that supports CloudTrail, that activity is recorded in a CloudTrail event along with other AWS service events in Even History. You can view, delete and download them.

  • Go to the CloudTrail console, go to the ‘Trails’ section and click ‘Create Trail

  • Give a proper trail name. For storage location you can either create a new S3 bucket or select an already configured bucket.

  • By default, your log files are encrypted with SSE-S3 encryption. You can choose to enable or disable this. You can leave the other settings as default.

  • You can create an SNS topic here itself and configure it later. Let us leave this for now.

  • In the next step, enable CloudWatch Logs. We will be sending events to CloudWatch and then set up alarms on metrics, to send out notifications to AlertOps.

  • Under Log Group, select new, or existing and link it to a CloudWatch log group.

  • You can specify an IAM role, that CloudTrail will assume in order to send events to your CloudWatch log group.

  • Review and finish creating the trail. If everything goes well, you will have created a Trail or a configuration where in, you can send events to CloudWatch for metric alarms.

AlertOps Inbound Integration

We can define an inbound integration in AlertOps to receive the event information from the SNS Topic through an alarm from CloudWatch.

AlertOps would ensure based on these notifications received, that it would always reach out and assign to the correct person/team by utilizing its escalation policies, schedules, and workflow features. AlertOps provides Inbound Integrations to integrate with numerous monitoring, chat and ITSM tools. You can select the CloudTrain Integration Template.

At a high level, the flow looks like the diagram shown below – CloudWatch configured with a log group (which you created in the previous step), receives events from CloudTrail. CloudWatch configured with an alarm for this particular log group trail (for a metric), triggers an alarm that is connected to a SNS topic. This SNS Topic would push the message to the HTTPS endpoint provided by AlertOps. AlertOps must be subscribed to the SNS Topic in order to receive notifications. (We will create an example configuration to illustrate this in the upcoming section)

To configure an Inbound Integration in AlertOps to receive alerts from CloudTrail:

  • In the menu on left pane, select Integrations > Inbound Integrations > Add API Integration.

  • There are numerous integration options available in AlertOps, select AWS CloudTrail (or Custom)

  • Once you select the integration, you can then specify basic settings like the integration name, escalation policy, names of the recipients/groups for which the alerts must be assigned to.

  • Once you click save, the API Integration will be created, and you will be given a unique URL which acts as the access point and needs to be configured at the source (in this case the SNS Topic), to send notifications. You can find the integration you just created, and you can give advanced settings and define various configurations for the alerts to be received and processed. For example, you can define when to open and close alerts based on the response obtained from the API call, filters etc.

  • You can similarly define URL mappings as you want, owing to the flexibility provided by AlertOps’ OpenAPI/Plug-and-Play integrations. You can provide other filters and match with regex expressions as well. You can also test the generated URL.

  • CloudTrail logs trigger CloudWatch Alarms that would send notifications to AlertOps.

Configuration of CloudTrail/CloudWatch/AWS SNS for AlertOps Integration

Now that we have setup AlertOps with the AWS CloudTrail API Inbound Integration, along with a unique API URL; we can now define a Webhook connection in Amazon SNS to access this API and send out event notifications to AlertOps.

Let’s recall what we have done so far – we have created a “trail” so that it sends events to CloudWatch log group; we have also set up an inbound integration in AlertOps and have a unique URL to which these events must send notifications to.

However, CloudWatch or CloudTrail doesn’t send event information directly to an external client, instead it sends the notification to an attached SNS Topic, which in turn would connect to an external HTTPS endpoint and push the notification (refer to the previous section for a high-level flow diagram). Let us configure an SNS topic and attach it to the CloudWatch log group metric rule.

To create an SNS Topic and a subscription:

  • Go to Services – select Amazon SNS.

  • In the left tab – select TopicsCreate Topic

  • Select Standard – Give a name to the topic. You can configure other options as you need to.

  • Once you create the topic, in the left tab – select Subscriptions – Create Subscription

  • In the Topic ARN option, select the name of the topic you just created.

  • For protocol – select HTTPS, and in the endpoint – paste the API URL which you obtained when you created the inbound integration. You can configure other options as you need to.

  • Once you create the subscription, go to Topics, select the topic you created – you must have a screen as below,

  • In the “Subscriptions” section, you will have a status that says, “Pending Confirmation. This means that AlertOps hasn’t yet subscribed to this topic to receive notifications. (The below screenshot shows “Confirmed”)

  • To subscribe to the topic, go to your AlertOps dashboard, under integrations go to ‘Inbound Log’.

  • You should have an entry in the log, from AWS, however there wont be an alert created. Select the message ID detail. In the body section, you should have a field that says, “Subscribe URL” and a link as a value. Copy and paste the link in a new tab and you must get a confirmation template. (You can save it if you want to).

  • Once you have subscribed to the topic, navigate to your AWS console. Now if you open the Subscriptions under Amazon SNS, you should see a status that says “Confirmed”. You can edit the topic and subscription configurations as and how you want it.

Configuring CloudWatch Log Group for sending out CloudTrail events:

In this configuration (for an example scenario), we will create a CloudWatch alarm that will be triggered when there are more than 3 failed sign-in attempts to the AWS console.

  • Go to CloudWatch console, in the left navigation pane, select Logs, and select the log group which you created while creating the “trial”.

  • Select the log group, and under ‘Actions’ select ‘Create Metric Filter

  • In ‘Create Filter Pattern’, enter the following:

    • { ($.eventName = ConsoleLogin) && ($.errorMessage = "Failed authentication") } 
  • You can test the pattern if you want to. For different filter pattern techniques, refer to the link in the Reference section. Click ‘Next

  • Create the filter name as “ConsoleSignInFailures”

  • Enable ‘Create New’ metric namespace and give the namespace as ‘CloudTrailMetrics’, Metric name as ‘ConsoleSigninFailureCount’ and Metric Value as ‘1’. Leave others default and click ‘Next’. Review and create the metric filter.

  • Once you create the metric filter, select it, and click “Create Alarm”. Give the settings as per the below screenshot.

  • In the next page, you can configure the SNS topic which you created in the previous section so that a notification will be sent to the AlertOps’ unique API URL when an alarm state is raised. Review and create the alarm!

  • Refer guide for AWS Cloudwatch integration - https://help.alertops.com/en/articles/1715406-aws-cloudwatch-sns , to see how to configure/setup Cloudwatch to send out notifications.

That’s it! You have created a “trail” that will send out logs to CloudWatch log group, which will trigger an alarm for a particular metric. Try logging in 3 or more times (failing which), this alarm notification will be sent and can be viewed in the ‘Inbound Log’ section in AlertOps Dashboard.

Alert Triggering Information

AlertOps will automatically create an incident when a new alert is received from AWS with an Message^NewStateValue status of “ALARM”.

If an alert with status “ALARM” matches an existing Open Alert, AlertOps will recognize the new alert as a duplicate and ignore the alert. The alert will be recorded in the Inbound Messages table as “Mapped Appended”.

AlertOps will automatically close the same incident when an alert with an Message^NewStateValue status “OK” is received.

References

AlertOps Integration Guides

General Restful API Guide

AWS CloudWatch Docs

AWS CloudTrail

AWS Metric Filter Syntax

Did this answer your question?