norgbackup/norg/notifier/uptimekuma_notifier.nim

29 lines
661 B
Nim
Raw Normal View History

import ../model/state_type
import ../model/notifier_type
2024-08-18 16:12:44 +02:00
import strformat
2024-08-18 16:12:44 +02:00
import ../utils/httprequest
type
UptimeKuma* = object of Notifier
2024-08-19 03:21:46 +02:00
proc send_notify*(uk: UptimeKuma, state: State, runtime: int = 0, msg: string = ""): int {.discardable.} =
2024-08-25 23:18:07 +02:00
var status: string = "down"
2024-08-18 16:12:44 +02:00
case state
of Success, Running:
status = "up"
else:
status = "down"
2024-08-27 19:37:48 +02:00
var message = fmt"{status}"
if msg != "":
message &= fmt":{msg}"
2024-08-19 03:21:46 +02:00
let url = fmt"{uk.base_url}?status={status}&msg={message}&ping={runtime}"
2024-08-18 16:12:44 +02:00
echo "Sending notification to " & url
let res = sendHttpRequest(HttpGet, url)
if res.status == $Http200:
return 0
else:
return 1