44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
// alert-test sends one clearly marked test alert through every channel
|
|
// configured in the environment (see internal/alerts.ConfigFromEnv), so a new
|
|
// Telegram token / chat id or webhook can be verified. It never prints secrets.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"git.tornberg.me/go-otel/internal/alerts"
|
|
"git.tornberg.me/go-otel/internal/features"
|
|
)
|
|
|
|
func main() {
|
|
cfg := alerts.ConfigFromEnv()
|
|
notifiers := cfg.Notifiers()
|
|
if len(notifiers) == 0 {
|
|
fmt.Fprintln(os.Stderr, "no channel configured (TELEGRAM_KEY + TELEGRAM_CHATID, or OTEL_ALERT_WEBHOOK_URL)")
|
|
os.Exit(2)
|
|
}
|
|
now := time.Now().UTC()
|
|
a := alerts.NewAlert(features.Spike{Service: "alert-test", WindowStart: now.Add(-5 * time.Minute), WindowEnd: now, ErrorCount: 42, BaselineMean: 1, Excess: 41,
|
|
Patterns: []features.PatternDelta{{Signature: "test", Count: 42, BaselineMean: 1, Excess: 41, Novel: true, Clients: 3,
|
|
Example: features.Event{Service: "alert-test", Kind: "span", StatusCode: 500, Route: "/api/example", Message: "this is a test alert from otel-debug"}}}}, now)
|
|
a.Test = true
|
|
failed := false
|
|
for _, n := range notifiers {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
|
err := n.Send(ctx, a)
|
|
cancel()
|
|
if err != nil {
|
|
fmt.Printf("%s: FAILED: %v\n", n.Name(), err)
|
|
failed = true
|
|
continue
|
|
}
|
|
fmt.Printf("%s: sent\n", n.Name())
|
|
}
|
|
if failed {
|
|
os.Exit(1)
|
|
}
|
|
}
|