How to use cloud watch agent to upload only logs of Ubuntu user login failures to cloudwatch

1

In the var/log/auth.log authentication log file, login failure information usually begins with keywords such as "password failure" and "authentication failure". How to configure the proxy file /var/awslogs/etc/awslogs.conf to only collect user login failure information and send it to cloudwatch

ChatGPT gave a solution, but it didn’t work. It uploaded the entire auth.log content.

[/var/log/auth.log]
datetime_format = %b %d %H:%M:%S
file = /var/log/auth.log
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = your-log-group-name

filter_pattern = [timestamp, loglevel, source, message, host, program, pid] !~ ".*sshd.*Failed (password|publickey).*"
DD-Boom
已提問 5 個月前檢視次數 161 次
1 個回答
1
已接受的答案

Hello.

I think the file you are looking at is probably the configuration file for CloudWatch Logs Agent.
CloudWatch Logs Agent is an older agent, so you should normally use CloudWatch Agent.
If you are using CloudWatch Logs Agent, there is no "filter_pattern" setting, so I don't think you can filter.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html

If you are using CloudWatch Agent, there is a setting called "filters", so you can filter the logs you want to send.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Logssection

"collect_list": [ 
  {
    "file_path": "/opt/aws/amazon-cloudwatch-agent/logs/test.log", 
    "log_group_name": "test.log", 
    "log_stream_name": "test.log",
    "filters": [
      {
        "type": "exclude",
        "expression": "Firefox"
      },
      {
        "type": "include",
        "expression": "P(UT|OST)"
      }
    ]
  },
  .....
]
profile picture
專家
已回答 5 個月前
profile picture
專家
已審閱 21 天前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南