notifier

package
v1.1.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 7 Imported by: 0

README ¶

🔔 Multi-Channel Alerting & Notification Pipeline (internal/notifier)

internal/notifier dispatches real-time outage and recovery alert notifications to external webhooks when monitor status state transitions occur in PingGopher.


📦 Key Exports & Data Structures

WebhookPayload

Standardized JSON payload structure delivered to configured webhook endpoints:

{
  "event": "incident.open",
  "monitor_id": "8438626d-3b40-4306-9678-680df5a237bb",
  "monitor_name": "Production API",
  "target_url": "https://api.example.com/health",
  "status": "DOWN",
  "cause": "HTTP 503 Service Unavailable",
  "timestamp": "2026-08-22T22:30:00Z"
}
NotificationEngine

Orchestrates alert delivery:

  • NotifyIncidentCreated: Dispatches incident.open webhook notifications upon outage detection.
  • NotifyIncidentResolved: Dispatches incident.resolved webhook notifications upon target recovery.

🧪 Testing & Verification

Automated Unit Test Suite (notifier_test.go)

We use Go's standard net/http/httptest package to launch isolated in-memory HTTP webhook receivers:

Test Method Test Focus & Verification
TestSendWebhookAlertSuccess Tests JSON payload serialization and HTTP POST dispatch to a mock webhook receiver.
TestNotificationEngineOutageAndRecovery Tests NotificationEngine dispatching incident.open on outage creation and incident.resolved on recovery.
Running Notifier Unit Tests
go test -v ./internal/notifier

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func SendDiscordAlert ¶

func SendDiscordAlert(discordWebhookURL string, payload WebhookPayload, timeout time.Duration) error

SendDiscordAlert dispatches a color-coded Discord Embed alert card with SSRF validation.

func SendSlackAlert ¶

func SendSlackAlert(slackWebhookURL string, payload WebhookPayload, timeout time.Duration) error

SendSlackAlert dispatches a rich Slack Block-Kit formatted alert payload with SSRF validation.

func SendWebhookAlert ¶

func SendWebhookAlert(webhookURL string, payload WebhookPayload, timeout time.Duration) error

SendWebhookAlert dispatches a JSON POST payload to a configured webhook URL with SSRF validation and retries.

Types ¶

type DiscordEmbed ¶

type DiscordEmbed struct {
	Title       string         `json:"title"`
	Description string         `json:"description,omitempty"`
	Color       int            `json:"color"` // Integer color code (0xE74C3C red, 0x2ECC71 green)
	Fields      []DiscordField `json:"fields,omitempty"`
	Footer      *DiscordFooter `json:"footer,omitempty"`
	Timestamp   string         `json:"timestamp,omitempty"`
}

type DiscordField ¶

type DiscordField struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

type DiscordFooter ¶

type DiscordFooter struct {
	Text string `json:"text"`
}

type DiscordWebhookPayload ¶

type DiscordWebhookPayload struct {
	Username  string         `json:"username,omitempty"`
	AvatarURL string         `json:"avatar_url,omitempty"`
	Embeds    []DiscordEmbed `json:"embeds"`
}

DiscordWebhookPayload represents a rich Discord Embed notification payload.

type NotificationEngine ¶

type NotificationEngine struct{}

NotificationEngine manages multi-channel alert dispatches for incidents.

func NewNotificationEngine ¶

func NewNotificationEngine() *NotificationEngine

NewNotificationEngine creates a new NotificationEngine.

func (*NotificationEngine) NotifyIncidentCreated ¶

func (n *NotificationEngine) NotifyIncidentCreated(monitor db.Monitor, incident db.Incident, webhookURL string)

NotifyIncidentCreated triggers real-time alerts when a new outage incident opens.

func (*NotificationEngine) NotifyIncidentResolved ¶

func (n *NotificationEngine) NotifyIncidentResolved(monitor db.Monitor, incident db.Incident, webhookURL string)

NotifyIncidentResolved triggers real-time alerts when an outage incident resolves.

type SlackBlock ¶

type SlackBlock struct {
	Type   string           `json:"type"`             // "header", "section", "divider", "context"
	Text   *SlackTextBlock  `json:"text,omitempty"`   // Header or section text
	Fields []SlackTextBlock `json:"fields,omitempty"` // Key-value grid fields
}

type SlackBlockKitPayload ¶

type SlackBlockKitPayload struct {
	Text   string       `json:"text"`
	Blocks []SlackBlock `json:"blocks,omitempty"`
}

SlackBlockKitPayload represents a rich Slack Block-Kit notification payload.

type SlackTextBlock ¶

type SlackTextBlock struct {
	Type string `json:"type"` // "plain_text" or "mrkdwn"
	Text string `json:"text"`
}

type WebhookError ¶

type WebhookError string

func (WebhookError) Error ¶

func (e WebhookError) Error() string

type WebhookPayload ¶

type WebhookPayload struct {
	Event       string `json:"event"`        // "incident.open" or "incident.resolved"
	MonitorID   string `json:"monitor_id"`   // Target monitor UUID
	MonitorName string `json:"monitor_name"` // Target monitor name
	TargetURL   string `json:"target_url"`   // Target URL
	Status      string `json:"status"`       // "DOWN" or "UP"
	Cause       string `json:"cause"`        // Outage cause description
	Timestamp   string `json:"timestamp"`    // ISO-8601 timestamp
}

WebhookPayload represents the JSON notification format dispatched to external webhooks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL