monitor

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PhaseScheduled means no check-in has been received yet, so the monitor is scheduled but inactive.
	PhaseScheduled Phase = "scheduled"
	// PhaseAwaiting means the monitor is awaiting the next expected check-in.
	PhaseAwaiting Phase = "awaiting"
	// PhaseOverdue means the expected check-in deadline elapsed and the alerting delay is running.
	PhaseOverdue Phase = "overdue"
	// PhaseAlerting means the alerting delay elapsed and notification was sent.
	PhaseAlerting Phase = "alerting"

	// StatusAlerting marks an alerting notification.
	StatusAlerting EventStatus = "alerting"
	// StatusResolved marks a resolved notification.
	StatusResolved EventStatus = "resolved"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	Event        Event
	ShouldNotify bool
}

CheckResult describes lifecycle events emitted by advancing the monitor clock.

type Event

type Event struct {
	IncidentID     string
	NotificationID string
	CheckInName    string
	LastCheckIn    time.Time
	ExpectedBy     time.Time
	OverdueSince   time.Time
	AlertingAt     time.Time
	Now            time.Time
	Phase          Phase
	Status         EventStatus
	Resolved       bool
	Title          string
	Text           string
}

Event describes a check-in lifecycle event used when rendering and sending notifications.

IncidentID identifies one overdue episode and is shared by the alerting and resolved notifications. NotificationID identifies one concrete notification message and is stable across delivery retries for that message.

The monitor owns factual event data only. Presentation fields such as Title and Text are intentionally left empty by the monitor and are filled by the notification renderer from the configured title/text templates.

type EventStatus

type EventStatus string

EventStatus describes the status of a notification lifecycle event.

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor tracks check-in deadlines and notification state.

func New

func New(
	checkInName string,
	expectedEvery, alertingDelay time.Duration,
	logger *slog.Logger,
) *Monitor

New creates a monitor and requires a logger because logging is part of monitor behavior.

func (*Monitor) Check

func (m *Monitor) Check(now time.Time) CheckResult

Check advances monitor state for a given time and returns lifecycle events when needed.

func (*Monitor) CheckInName

func (m *Monitor) CheckInName() string

CheckInName returns the configured check-in monitor name.

func (*Monitor) NextDeadline

func (m *Monitor) NextDeadline() (deadline time.Time, active bool)

NextDeadline returns the next lifecycle deadline for the current phase.

func (*Monitor) RecordCheckIn

func (m *Monitor) RecordCheckIn(at time.Time) RecordResult

RecordCheckIn stores a check-in time, activates or restarts the expected deadline, and returns a resolved event after alerts.

func (*Monitor) Snapshot

func (m *Monitor) Snapshot() Snapshot

Snapshot returns the current monitor state.

type Phase

type Phase string

Phase describes the current check-in monitor lifecycle phase.

type RecordResult

type RecordResult struct {
	Snapshot      Snapshot
	PreviousPhase Phase
	Event         Event
	ShouldNotify  bool
}

RecordResult describes the outcome of recording a check-in.

type Snapshot

type Snapshot struct {
	LastCheckIn  time.Time
	ExpectedBy   time.Time
	OverdueSince time.Time
	AlertingAt   time.Time
	Phase        Phase
}

Snapshot describes the current monitor state.

Jump to

Keyboard shortcuts

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