Add YAML config loading with validation, env overrides for secrets, and a web dashboard exposing health, stats, and recent events.
54 lines
1.2 KiB
V
54 lines
1.2 KiB
V
module sources
|
|
|
|
import x.json2 as json
|
|
|
|
pub fn transform_uptime_kuma(raw string, source UptimeKumaSource) ?Event {
|
|
doc := json.decode[json.Any](raw, json.DecoderOptions{}) or { return none }
|
|
obj := doc.as_map()
|
|
|
|
monitor := get_string(obj, 'monitor.name')
|
|
status := get_string(obj, 'heartbeat.status')
|
|
msg := get_string(obj, 'heartbeat.msg')
|
|
ping := get_string(obj, 'heartbeat.ping')
|
|
time_str := get_string(obj, 'heartbeat.time')
|
|
|
|
state_cfg := source.state_map[status] or { UptimeKumaState{} }
|
|
priority := state_cfg.priority
|
|
mut tags := state_cfg.tags.clone()
|
|
|
|
if source.tags.len > 0 && tags.len == 0 {
|
|
tags << source.tags
|
|
}
|
|
|
|
emoji := if status == 'up' { '✅' } else { '🚨' }
|
|
mut message := ''
|
|
if source.template != '' {
|
|
vars := {
|
|
'monitor': monitor
|
|
'status': status
|
|
'msg': msg
|
|
'ping': ping
|
|
'time': time_str
|
|
}
|
|
message = render_source_template(source.template, vars)
|
|
} else {
|
|
message = '${emoji} ${monitor} is ${status.to_upper()}'
|
|
if msg != '' {
|
|
message += ' — ${msg}'
|
|
}
|
|
if time_str != '' {
|
|
message += ' — ${time_str}'
|
|
}
|
|
}
|
|
|
|
return Event{
|
|
source: 'uptime_kuma'
|
|
name: source.name
|
|
topic: source.topic
|
|
priority: priority
|
|
tags: tags
|
|
message: message
|
|
raw: raw
|
|
}
|
|
}
|