Skip to content

Commit

Permalink
alert tg message pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
oxmix committed Nov 14, 2023
1 parent c2ecea6 commit 40052f8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,29 @@ func (p *NodesPool) logsAlert(node string, container string, l logsLine) {
continue
}
p.logsAlertSent.Store(hash, struct{}{})

var pretty bytes.Buffer
var format = "json"
err := json.Indent(&pretty, []byte(l.Mess), "", " ")
if err != nil {
pretty.Write([]byte(l.Mess))
format = "text"
}

go p.logsSendNotify(fmt.Sprintf(
"Node: %s\nContainer: %s\n\nTime: %s"+
"\nLink: https://"+u.Env().Endpoint+"/logs/"+node+"/"+container+"\n\nMessage:\n%s",
node, container, l.Time, l.Mess))
"```%s\n%s```[%s • *%s*](%s)",
format, pretty.Bytes(), node, container,
"https://"+u.Env().Endpoint+"/logs/"+node+"/"+container))
return
}
}
}

func (p *NodesPool) logsSendNotify(message string) {
payload, err := json.Marshal(map[string]string{
"chat_id": u.Env().NotifyTgChatId,
"text": message,
"chat_id": u.Env().NotifyTgChatId,
"text": message,
"parse_mode": "MarkdownV2",
})
if err != nil {
log.Printf("notify logs, err: %q", err.Error())
Expand Down

0 comments on commit 40052f8

Please sign in to comment.