feat(alert): add Opsgenie provider
CI / test (pull_request) Successful in 2m30s
CI / lint (pull_request) Successful in 1m1s
CI / vulncheck (pull_request) Successful in 51s

Support Opsgenie Alert API v2 with US/EU endpoint selection,
configurable priority (P1-P5), and GenieKey auth. TUI form
includes API key, priority picker, and EU instance toggle.
This commit is contained in:
2026-06-04 13:09:06 -04:00
parent 9e15b369d3
commit 3218af474e
3 changed files with 149 additions and 1 deletions
+32
View File
@@ -110,6 +110,24 @@ func gotifyPayload(priority string) PayloadFunc {
}
}
func opsgeniePayload(priority string) PayloadFunc {
return func(title, message string) ([]byte, error) {
return json.Marshal(map[string]any{
"message": limitMessage(title, 130),
"description": message,
"source": "uptop",
"priority": priority,
})
}
}
func limitMessage(s string, max int) string {
if len(s) <= max {
return s
}
return s[:max]
}
func GetProvider(cfg models.AlertConfig) Provider {
switch cfg.Type {
case "discord":
@@ -173,6 +191,20 @@ func GetProvider(cfg models.AlertConfig) Provider {
Payload: gotifyPayload(priority),
Headers: map[string]string{"X-Gotify-Key": cfg.Settings["token"]},
}
case "opsgenie":
priority := "P3"
if p, ok := cfg.Settings["priority"]; ok && p != "" {
priority = p
}
apiURL := "https://api.opsgenie.com/v2/alerts"
if eu, ok := cfg.Settings["eu"]; ok && eu == "true" {
apiURL = "https://api.eu.opsgenie.com/v2/alerts"
}
return &HTTPProvider{
URL: apiURL,
Payload: opsgeniePayload(priority),
Headers: map[string]string{"Authorization": "GenieKey " + cfg.Settings["api_key"]},
}
default:
return nil
}