Error in metric filter pattern in cloud watch - amazon-web-services

Iam trying to create the custom cloudwatch metric from the Log Groups
I am trying to create the metric pattern for the status of the email. I just need to monitor the the response in email(success/failure)
My cloudwatch logs look like below
Email status : [EmailStatusResponse{farmId=3846, emailIds='xxx', response='success'}
So, i just need to monitor two cases
response='success'
response='failure'
Please find the below snippet for my configuration
Can anyone pls help me with the error in the filter pattern
kindly help!

Wrap this in double quotes.
Metric filter terms that include characters other than alphanumeric or underscore must be placed inside double quotes ("").
For you it would be "response='success'"

Related

GCP Alert email customization

I am trying to add more text to 'alert' email that Google send when something happens in cloud. For example I build an log based alert and when some threshhold reached then 'alert' email send. I read multiple time the document: Using Markdown and variables in documentation templates but whatever I put into 'Documentation' field come as simple text - without actual value of the field :( For example I receive an email with:
Error Text: ${log.extracted_label.rawLogIndex}
For example I have a log entry like this:
I want the value of labels\error_stack to be send in alert email - how I can do that ? Could you add an example ?
You can include the log data using the variables in the document section of the alert policy. For this log-based alert needs to be created.
To answer your question: In order to use the variable in documentation, you need to create a label for your logs. You can create a label using extractor expressions. These expressions will notify the cloud logging to extract the label's value from the logs you defined.
This document will help to understand the labels for log-based metrics along with example. You can follow this tutorial to create a log-based alerts.

AWS Cloud Watch: Metric Filter Value Extraction from Log

I have api.log logs being sent to CloudWatch and I want to create a metric filter to extract the userId of the user tried to access application.
A sample log entry looks like:
2022-12-06T19:13:59.329Z 2a-b0bc-7a79c791f19c INFO Validated that user fakeId has access to the following gated roles: create, update and delete
And the value I would like to extract is: fakeId
I read through this guide and it seems pretty straight forward because user [fakeId] seconds is unique to just this line. This guide on metric filter syntax seems to only show examples for extracting values from JSON logs and this official example list doesn't cover it.
Based on the documentation and a few other stackoverflow answers, I tried these things:
[validation="Validated", that="that", user="user", userId, ...]
[,,user="user",userId,...]
[,,user=user,userId,...]
but it didn't. Any help would be really appreciated!

Why is my AWS CloudWatch alarm not being triggered?

I'm trying to setup AWS to send notifications to a slack channel when a CloudWatch alarm goes off. I'm following along in this guide:
https://medium.com/analytics-vidhya/generate-slack-notifications-for-aws-cloudwatch-alarms-e46b68540133
I think I did everything properly but I'm not getting my slack notifications. I'm not sure where in the process it's failing but I suspect the alarm is not being triggered.
Here are the details:
CloudWatch logs shows my error is being logged:
Here is my filter metric:
Here is how I define the pattern on which I want to filter:
Here is the state of the alarm:
The alarm seems to be OK. I gave it 5 minutes after logging the error. Does this mean the alarm is not being triggered?
Thanks
UPDATE
Here are some updated screen shots to address Marcin's point about the time discrepancy (note that the CloudWatch logs are in local time and the Alarm graph is in UTC--a 6 hour difference):
I'm not exactly sure how to interpret the graph. It says OK in the top right corner but the horizontal red line at 1 seems to indicate that it's in an alarm state.
It seems to me that there must be something wrong between your pattern filter and the alarm trigger since you clearly have the message in your log stream and the alarm condition has been met.
I'm more used to seeing filter patterns in JSON, but going over the documentation at https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html there's a line that says:
Metric filter terms that include characters other than alphanumeric or underscore must be placed inside double quotes ("").
And I'm thinking that your message pattern has a dash and it's neither alphanumeric nor an underscore on it so maybe that's the part that's being interpreted differently than expected.
I believe the problem is that CloudWatch Filter's need to be quoted if they have characters other than alphanumerics and underscores.
Since your pattern has dashes in it, you will need to put your filter pattern in double quotes. Without quotes, CloudWatch may interpret dashes as minus signs used to exclude terms.
"LOGIN-SIGNUP-ERROR"
Also, as it was already discussed in the comments, you should change the statistic to SUM instead of AVERAGE assuming you want to be alerted each time this error occurs.
References:
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html

Filtering for email addresses in AWS Cloudwatch Logs?

I am looking to setup some CloudFormation stuff that is able to find any email addresses in CloudWatch logs and let us know that one slipped through the cracks. I thought this would be a simple process of using a RegEx pattern that catches all the possible variations and email address can have, and using that as a filter. Having discovered that CloudWatch filtering does not support RegEx I've become a bit stumped as to how to write a filter that can be relied upon to catch any email address.
Has anyone done something similar to this, or know where a good place to start would be?
Amazon has launched a service called CloudWatch insights and it allows to filter messages logs. In the previous link you have examples of queries.
You need to select the CloudWatch Log Group and the period of time in which search.
Example:
fields #message
| sort #timestamp desc
| filter #message like /.*47768.*/
If you're exporting the logs somewhere (Like Sumologic, Datadog etc) thats a better place to do that alerting.
If not and you're exporting them into S3 then a triggered lambda function that runs the check might do the trick. Could be expensive long term though.
The solution that we landed upon was to pass stings through a RegEx pattern that recognises email addresses before they logged into AWS. Replacing any matches with [REDACTED]. Which is simple enough to do in a lambda.

Filter AWS Cloudwatch Lambda's Log

I have a Lambda function and its logs in Cloudwatch (Log group and Log Stream). Is it possible to filter (in Cloudwatch Management Console) all logs that contain "error"? For example logs containing "Process exited before completing request".
In Log Groups there is a button "Search Events". You must click on it first.
Then it "changes" to "Filter Streams":
Now you should just type your filter and select the beginning date-time.
So this is kind of a side issue, but it was relevant for us. (I posted this to another answer on StackOverflow but thought it would be relevant to this conversation too)
We've noticed that tailing and searching logs gets really slow after a log group has a lot of Log Streams in it, like when an AWS Lambda Function has had a lot of invocations. This is because "tail" type utilities and searching need to connect to each log stream to run. Log Events get expired and deleted due to the policy you set on the Log Group itself, but the Log Streams never get cleaned up. I made a few little utility scripts to help with that:
https://github.com/four43/aws-cloudwatch-log-clean
Hopefully that save you some agony over waiting for those logs to get searched.
You can also use CloudWatch Insights (https://aws.amazon.com/about-aws/whats-new/2018/11/announcing-amazon-cloudwatch-logs-insights-fast-interactive-log-analytics/) which is an AWS extension to CloudWatch logs that gives a pretty powerful query and analytics tool. However it can be slow. Some of my queries take up to a minute. Okay, if you really need that data.
You could also use a tool I created called SenseLogs. It downloads CloudWatch data to your browser where you can do queries like you ask about. You can use either full text and search for "error" or if your log data is structured (JSON), you can use a Javascript like expression language to filter by field, eg:
error == 'critical'
Posting an update as CloudWatch has changed since 2016:
In the Log Groups there is a Search all button for a full-text search
Then just type your search: