问题
I have following function in ruby to send aws logs to microsoft team channel through webhook. Some text contains underscore signs like connection_web
but appears like connectionweb
in MS teams. How to get the exact output ?
require 'json'
require 'net/https'
require 'uri'
require 'base64'
require 'zlib'
require 'stringio'
def lambda_handler(event:, context:)
log_event = JSON.parse(decode_and_decompress(event["awslogs"]["data"]))
response = speak(messages_from_blob(log_event))
puts response.body
end
def speak(message)
http = Net::HTTP.new("MS-Teamwebhook.com", 443)
http.use_ssl = true
request = Net::HTTP::Post.new(ENV["HOOK_URL"])
request.body = JSON.generate({
text: message
})
http.request(request)
end
def decode_and_decompress(input)
binary_compressed = Base64.decode64(input)
gz = Zlib::GzipReader.new(StringIO.new(binary_compressed))
gz.read
end
def messages_from_blob(event_data)
event_data["logEvents"]
.map{ |e| e["message"] }
.join("\n")
end
来源:https://stackoverflow.com/questions/65923762/microsoft-teams-escaping-underscores-in-text