notifier

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 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 SendWebhookAlert ¶

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

SendWebhookAlert dispatches a JSON POST payload to a configured webhook URL.

Types ¶

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 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