init work of uptime

This commit is contained in:
Blake Ridgway
2026-03-22 11:30:31 -05:00
parent 854cba4c24
commit f0db70c840
18 changed files with 2252 additions and 0 deletions

40
internal/alert/discord.go Normal file
View File

@@ -0,0 +1,40 @@
package alert
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
type DiscordAlerter struct {
webhookURL string
client *http.Client
}
func NewDiscordAlerter(webhookURL string) *DiscordAlerter {
return &DiscordAlerter{
webhookURL: webhookURL,
client: &http.Client{Timeout: 10 * time.Second},
}
}
func (d *DiscordAlerter) Send(subject, body string) error {
payload, err := json.Marshal(map[string]string{"content": body})
if err != nil {
return fmt.Errorf("marshal payload: %w", err)
}
resp, err := d.client.Post(d.webhookURL, "application/json", bytes.NewReader(payload))
if err != nil {
return fmt.Errorf("post webhook: %w", err)
}
defer resp.Body.Close()
// Discord returns 204 No Content on success.
if resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("webhook returned %d", resp.StatusCode)
}
return nil
}