Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
750 views
in Technique[技术] by (71.8m points)

tomcat - Get event log error message from CloudWatch to Lambda and send it to MS Teams Webhook

I am using the CloudWatch agent to catch tomcat logs, which are all errors. The agent publishes the log streams to a log group, and what I want is to get these log errors and send them to an MS Teams channel using anything like SNS, Lambda, ...

My only issue is that I could do all of the above except for that I can't get the error message, for example:

org.hibernate.exception.SQLGrammarException: could not extract ResultSet...

I am using the following python code to get this done, which I picked from AWS documentation.

#!/usr/bin/python3.7
import urllib3 
import json

http = urllib3.PoolManager() 

url = "https://outlook.office.com/webhook/xxxxxxxxx"
msg = {
    "text": event['Records'][0]['Sns']['Message']
}
encoded_msg = json.dumps(msg).encode('utf-8')
resp = http.request('POST', url, body = encoded_msg)
print({
    # "message": event['Records'][0]['Sns']['Message'], 
    "message": " ** Payload ** " ,
    "status_code": resp.status, 
    "response": resp.data
})

Can you guys help me, please? Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...