norgbackup/norg/notifier/uptimekuma_notifier.nim

33 lines
743 B
Nim
Raw Normal View History

import ../model/state_type
import ../model/notifier_type
2024-08-27 22:16:31 +02:00
import ../model/log_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:50:58 +02:00
var message = $state
2024-08-27 19:37:48 +02:00
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
2024-08-27 22:16:31 +02:00
debug "Sending notification to " & url
2024-11-25 12:20:50 +01:00
try:
let res = sendHttpRequest(HttpGet, url)
if res.status == $Http200:
return 0
else:
return 1
except:
error(getCurrentExceptionMsg())