uptime kuma webhook
This commit is contained in:
parent
5af06b63a9
commit
3a2733c1b6
|
@ -318,8 +318,8 @@ func (h MessageHandler) sendMessageInternal(g *gin.Context, ctx *logic.AppContex
|
||||||
// @Description All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required
|
// @Description All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required
|
||||||
// @Tags External
|
// @Tags External
|
||||||
//
|
//
|
||||||
// @Param query_data query handler.UptimeKumaWebHook.query false " "
|
// @Param query_data query handler.UptimeKumaWebHook.query false " "
|
||||||
// @Param post_body body handler.UptimeKumaWebHook.body false " "
|
// @Param post_body body handler.UptimeKumaWebHook.uptimeKumaWebhookBody false " "
|
||||||
//
|
//
|
||||||
// @Success 200 {object} any
|
// @Success 200 {object} any
|
||||||
// @Failure 400 {object} ginresp.apiError
|
// @Failure 400 {object} ginresp.apiError
|
||||||
|
@ -333,11 +333,23 @@ func (h MessageHandler) UptimeKumaWebHook(g *gin.Context) ginresp.HTTPResponse {
|
||||||
UserID *models.UserID `form:"user_id" example:"7725"`
|
UserID *models.UserID `form:"user_id" example:"7725"`
|
||||||
KeyToken *string `form:"key" example:"P3TNH8mvv14fm"`
|
KeyToken *string `form:"key" example:"P3TNH8mvv14fm"`
|
||||||
}
|
}
|
||||||
type body struct {
|
|
||||||
Title string `json:"Title"`
|
type uptimeKumaWebhookBody struct {
|
||||||
Body string `json:"Body"`
|
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 {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Url *string `json:"url"`
|
||||||
|
} `json:"monitor"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
}
|
}
|
||||||
var b body
|
|
||||||
|
var b uptimeKumaWebhookBody
|
||||||
var q query
|
var q query
|
||||||
|
|
||||||
ctx, httpErr := h.app.StartRequest(g, nil, &q, &b, nil)
|
ctx, httpErr := h.app.StartRequest(g, nil, &q, &b, nil)
|
||||||
|
@ -346,7 +358,22 @@ func (h MessageHandler) UptimeKumaWebHook(g *gin.Context) ginresp.HTTPResponse {
|
||||||
return *httpErr
|
return *httpErr
|
||||||
}
|
}
|
||||||
|
|
||||||
okResp, errResp := h.sendMessageInternal(g, ctx, q.UserID, q.KeyToken, nil, &b.Title, &b.Body, langext.Ptr(1), nil, nil, nil)
|
title := fmt.Sprintf("[UptimeKuma] %v down!", b.Monitor.Name)
|
||||||
|
|
||||||
|
content := fmt.Sprintf("%v\n", b.Monitor.Name)
|
||||||
|
content += fmt.Sprintf("%v\n", b.Msg)
|
||||||
|
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)
|
||||||
|
|
||||||
|
okResp, errResp := h.sendMessageInternal(g, ctx, q.UserID, q.KeyToken, nil, &title, &content, langext.Ptr(1), nil, nil, nil)
|
||||||
|
|
||||||
if errResp != nil {
|
if errResp != nil {
|
||||||
return *errResp
|
return *errResp
|
||||||
|
|
|
@ -2757,7 +2757,7 @@
|
||||||
"name": "post_body",
|
"name": "post_body",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/handler.UptimeKumaWebHook.body"
|
"$ref": "#/definitions/handler.UptimeKumaWebHook.uptimeKumaWebhookBody"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -3449,13 +3449,41 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"handler.UptimeKumaWebHook.body": {
|
"handler.UptimeKumaWebHook.uptimeKumaWebhookBody": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"Body": {
|
"heartbeat": {
|
||||||
"type": "string"
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"localDateTime": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"msg": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"time": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"timezone": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"timezoneOffset": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Title": {
|
"monitor": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"msg": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -458,11 +458,29 @@ definitions:
|
||||||
user_id:
|
user_id:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
handler.UptimeKumaWebHook.body:
|
handler.UptimeKumaWebHook.uptimeKumaWebhookBody:
|
||||||
properties:
|
properties:
|
||||||
Body:
|
heartbeat:
|
||||||
type: string
|
properties:
|
||||||
Title:
|
localDateTime:
|
||||||
|
type: string
|
||||||
|
msg:
|
||||||
|
type: string
|
||||||
|
time:
|
||||||
|
type: string
|
||||||
|
timezone:
|
||||||
|
type: string
|
||||||
|
timezoneOffset:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
monitor:
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
msg:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
handler.pingResponse:
|
handler.pingResponse:
|
||||||
|
@ -2600,7 +2618,7 @@ paths:
|
||||||
in: body
|
in: body
|
||||||
name: post_body
|
name: post_body
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/handler.UptimeKumaWebHook.body'
|
$ref: '#/definitions/handler.UptimeKumaWebHook.uptimeKumaWebhookBody'
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
|
|
Loading…
Reference in New Issue