From a497049c66cbdb5030865051866e341948e1b0c4 Mon Sep 17 00:00:00 2001 From: risqy Date: Tue, 1 Aug 2023 19:22:17 +0200 Subject: [PATCH] uptime kuma webhook optional fields --- scnserver/api/handler/message.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scnserver/api/handler/message.go b/scnserver/api/handler/message.go index cb44510..ae41b09 100644 --- a/scnserver/api/handler/message.go +++ b/scnserver/api/handler/message.go @@ -335,14 +335,14 @@ func (h MessageHandler) UptimeKumaWebHook(g *gin.Context) ginresp.HTTPResponse { } type uptimeKumaWebhookBody struct { - Heartbeat struct { + Heartbeat *struct { Time string `json:"time"` Msg string `json:"msg"` Timezone string `json:"timezone"` TimezoneOffset string `json:"timezoneOffset"` LocalDateTime string `json:"localDateTime"` } `json:"heartbeat"` - Monitor struct { + Monitor *struct { Name string `json:"name"` Url *string `json:"url"` } `json:"monitor"` @@ -360,19 +360,24 @@ func (h MessageHandler) UptimeKumaWebHook(g *gin.Context) ginresp.HTTPResponse { title := fmt.Sprintf("[UptimeKuma] %v down!", b.Monitor.Name) - content := fmt.Sprintf("%v\n", b.Monitor.Name) + var content = "" content += fmt.Sprintf("%v\n", b.Msg) - if b.Monitor.Url != nil { - content += fmt.Sprintf("url: %v\n", b.Monitor.Url) + if b.Monitor != nil { + content += fmt.Sprintf("%v\n", b.Monitor.Name) + if b.Monitor.Url != nil { + content += fmt.Sprintf("url: %v\n", b.Monitor.Url) + } + } - content += "===== Heartbeat ======" - content += fmt.Sprintf("msg: %v\n", b.Heartbeat.Msg) - content += fmt.Sprintf("timestamp: %v\n", b.Heartbeat.Time) - content += fmt.Sprintf("timezone: %v\n", b.Heartbeat.Timezone) - content += fmt.Sprintf("timezone offset: %v\n", b.Heartbeat.TimezoneOffset) - content += fmt.Sprintf("local date time: %v\n", b.Heartbeat.TimezoneOffset) - + if b.Heartbeat != nil { + content += "===== Heartbeat ======" + content += fmt.Sprintf("msg: %v\n", b.Heartbeat.Msg) + content += fmt.Sprintf("timestamp: %v\n", b.Heartbeat.Time) + content += fmt.Sprintf("timezone: %v\n", b.Heartbeat.Timezone) + content += fmt.Sprintf("timezone offset: %v\n", b.Heartbeat.TimezoneOffset) + content += fmt.Sprintf("local date time: %v\n", b.Heartbeat.TimezoneOffset) + } okResp, errResp := h.sendMessageInternal(g, ctx, q.UserID, q.KeyToken, nil, &title, &content, langext.Ptr(1), nil, nil, nil) if errResp != nil {