recover logstash alert field

main
ycz008 2024-02-28 16:04:16 +08:00
parent 0ed3af5f1b
commit 142f3a822b
2 changed files with 5 additions and 5 deletions

View File

@ -1,17 +1,17 @@
#!/bin/bash #!/bin/bash
# @timestamp serviceName env level message # @timestamp serviceName env level message
if (($#!=6));then if (($#!=5));then
echo "./log-alert.sh %{@timestamp} %{serviceName} %{env} %{level} %{message} %{stack_trace}" echo "./log-alert.sh %{@timestamp} %{serviceName} %{env} %{level} %{message}"
exit 1 exit 1
fi fi
if [[ -z $1 || -z $2 || -z $3 || -z $4 || -z $5 || -z $6 ]];then if [[ -z $1 || -z $2 || -z $3 || -z $4 || -z $5 ]];then
echo "one of '%{@timestamp} %{serviceName} %{env} %{level} %{message}' is empty" echo "one of '%{@timestamp} %{serviceName} %{env} %{level} %{message}' is empty"
exit 1 exit 1
fi fi
msg="timestamp: $1\nserviceName: $2\nenv: $3\nlevel: $4\nmessage: $5\nstack_trace: $6\n" msg="timestamp: $1\nserviceName: $2\nenv: $3\nlevel: $4\nmessage: $5\n"
#echo -ne $msg #echo -ne $msg
curl -X POST -H "Content-Type: application/json" -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"$msg\"}}" https://open.feishu.cn/open-apis/bot/v2/hook/29dd52e5-70d5-44b0-a443-22ea85382646 curl -X POST -H "Content-Type: application/json" -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"$msg\"}}" https://open.feishu.cn/open-apis/bot/v2/hook/29dd52e5-70d5-44b0-a443-22ea85382646

View File

@ -58,7 +58,7 @@ data:
# codec => "json_lines" # codec => "json_lines"
# } # }
exec { exec {
command => "/usr/local/bin/log-alert.sh '%{@timestamp}' '%{serviceName}' '%{env}' '%{level}' '%{message}' '%{stack_trace}'" command => "/usr/local/bin/log-alert.sh '%{@timestamp}' '%{serviceName}' '%{env}' '%{level}' '%{message}'"
} }
} }
logstash.yml: |- logstash.yml: |-