Add config validation and dashboard
Add YAML config loading with validation, env overrides for secrets, and a web dashboard exposing health, stats, and recent events.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
module sources
|
||||
|
||||
import x.json2 as json
|
||||
|
||||
pub fn transform_docker_event(raw string, source DockerSource, host string) ?Event {
|
||||
doc := json.decode[json.Any](raw, json.DecoderOptions{}) or { return none }
|
||||
obj := doc.as_map()
|
||||
|
||||
event_type := get_string(obj, 'status')
|
||||
actor := obj['Actor'] or { json.Any(map[string]json.Any{}) }.as_map()
|
||||
attrs := actor['Attributes'] or { json.Any(map[string]json.Any{}) }.as_map()
|
||||
|
||||
container_name := get_string(attrs, 'name')
|
||||
image := get_string(attrs, 'image')
|
||||
exit_code := get_string(attrs, 'exitCode')
|
||||
|
||||
priority := source.priority_map[event_type] or { 0 }
|
||||
|
||||
mut tags := source.tags.clone()
|
||||
if event_type == 'oom' && 'skull' !in tags {
|
||||
tags << 'skull'
|
||||
}
|
||||
|
||||
if source.template != '' {
|
||||
vars := {
|
||||
'container_name': container_name
|
||||
'status': event_type
|
||||
'image': image
|
||||
'exit_code': exit_code
|
||||
'host': host
|
||||
}
|
||||
return Event{
|
||||
source: 'docker'
|
||||
name: source.name
|
||||
topic: source.topic
|
||||
priority: priority
|
||||
tags: tags
|
||||
message: render_source_template(source.template, vars)
|
||||
raw: raw
|
||||
}
|
||||
}
|
||||
|
||||
emoji := match event_type {
|
||||
'die' { '💀' }
|
||||
'oom' { '☠️' }
|
||||
'health_status' { '💓' }
|
||||
else { '🐳' }
|
||||
}
|
||||
|
||||
mut message := '${emoji} ${container_name} → ${event_type}'
|
||||
if image != '' {
|
||||
message += '\nImage: ${image}'
|
||||
}
|
||||
if exit_code != '' {
|
||||
message += '\nExit code: ${exit_code}'
|
||||
}
|
||||
message += '\nHost: ${host}'
|
||||
|
||||
return Event{
|
||||
source: 'docker'
|
||||
name: source.name
|
||||
topic: source.topic
|
||||
priority: priority
|
||||
tags: tags
|
||||
message: message
|
||||
raw: raw
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user