Documentation
¶
Overview ¶
Package notify sends best-effort, security-minimized audit notifications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrManagerClosed indicates that a lifecycle operation followed Close. ErrManagerClosed = errors.New("notification manager is closed") // ErrManagerStarted indicates that Start was called more than once. ErrManagerStarted = errors.New("notification manager is already started") )
Functions ¶
This section is empty.
Types ¶
type ChannelConfig ¶
type ChannelConfig struct {
ID string
Enabled bool
Kind ChannelKind
Decisions []string
IncludeSQL bool
AllowPrivateEndpoints bool
Webhook *WebhookConfig
Syslog *SyslogConfig
}
ChannelConfig configures one independently queued notification destination.
type ChannelKind ¶
type ChannelKind string
ChannelKind identifies one supported transport.
const ( ChannelWebhook ChannelKind = "webhook" ChannelSyslog ChannelKind = "syslog" )
type ChannelStatus ¶
type ChannelStatus struct {
Sent uint64 `json:"sent"`
Failed uint64 `json:"failed"`
Dropped uint64 `json:"dropped"`
LastError string `json:"last_error,omitempty"`
LastSuccessAt time.Time `json:"last_success_at,omitempty"`
}
ChannelStatus is a process-local delivery snapshot for the future admin API.
type Config ¶
type Config struct {
Enabled bool
QueueSize int
Channels []ChannelConfig
}
Config is the complete process-local notification configuration. It is intentionally persistence-agnostic; T37-b owns storage and bootstrap wiring.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the live-only eventbus subscription and one bounded worker queue per enabled channel.
func NewManager ¶
NewManager creates an inert manager. Start or Reload applies configuration.
func (*Manager) Close ¶
Close stops subscriptions and workers. It is safe to call concurrently and more than once.
func (*Manager) Reload ¶
Reload atomically replaces the active generation. It cancels the old live-only subscription before establishing the new one, so retained eventbus history is never replayed. A very small best-effort gap is allowed.
func (*Manager) Start ¶
Start applies the initial configuration. Disabled or empty configurations intentionally do not subscribe to the event bus.
func (*Manager) Status ¶
func (manager *Manager) Status() map[string]ChannelStatus
Status returns a race-safe copy of cumulative process-local channel health.
type MetricRecorder ¶
type MetricRecorder interface {
RecordNotificationSent(channel string, at time.Time)
RecordNotificationFailed(channel, reason string)
RecordNotificationDropped(channel string)
}
MetricRecorder is implemented by internal/metrics.Metrics. Implementations must keep reason bounded and must never record destination URLs or payloads.
type NameResolver ¶
type NameResolver interface {
AgentName(ctx context.Context, id string) string
DatasourceName(ctx context.Context, id string) string
}
NameResolver supplies display names that are not present in AuditLog. It should be backed by a fast cache because it is called by channel workers.
type Option ¶
type Option func(*managerOptions)
Option customizes Manager without adding persistence concerns to Config.
func WithHTTPTimeout ¶
WithHTTPTimeout overrides the default three-second per-attempt timeout. It primarily exists to keep deterministic local tests fast.
func WithMetrics ¶
func WithMetrics(metrics MetricRecorder) Option
WithMetrics connects delivery counters to the process metrics registry.
func WithNameResolver ¶
func WithNameResolver(resolver NameResolver) Option
WithNameResolver enriches projected Agent/DataSource IDs with display names.
type Payload ¶
type Payload struct {
AuditID int64 `json:"audit_id"`
Timestamp string `json:"timestamp"`
Decision string `json:"decision"`
RiskLevel *int `json:"risk_level,omitempty"`
RuleIDs []string `json:"rule_ids"`
Datasource Identity `json:"datasource"`
Agent Identity `json:"agent"`
MCPTool *string `json:"mcp_tool,omitempty"`
StatementType *string `json:"stmt_type,omitempty"`
EstimatedRows *int64 `json:"est_rows,omitempty"`
RowsReturned *int `json:"rows_returned,omitempty"`
LatencyMS *int64 `json:"latency_ms,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
SQLNorm *string `json:"sql_norm,omitempty"`
}
Payload is the complete outbound whitelist. Adding any field here requires a security review; AuditLog must never be marshaled directly.
type SyslogConfig ¶
SyslogConfig configures RFC5424 delivery over UDP or TCP.
type WebhookConfig ¶
type WebhookConfig struct {
Template WebhookTemplate
URL string
BearerToken string
Headers map[string]string
Secret string
}
WebhookConfig configures an HTTP incoming webhook. Secret is used for the generic AgentSQL HMAC or DingTalk's signing algorithm, depending on Template.
type WebhookTemplate ¶
type WebhookTemplate string
WebhookTemplate identifies an incoming-webhook payload shape.
const ( WebhookGeneric WebhookTemplate = "generic" WebhookFeishu WebhookTemplate = "feishu" WebhookDingTalk WebhookTemplate = "dingtalk" WebhookWeCom WebhookTemplate = "wecom" WebhookSlack WebhookTemplate = "slack" )