Documentation
¶
Index ¶
- func ShouldSendEmail(n *Notification, sendOnWarning bool) bool
- func ShouldSendWebhook(n *Notification, minSeverity Severity) bool
- type CertExpiryData
- type CertificateChecker
- func (c *CertificateChecker) CheckAll()
- func (c *CertificateChecker) CheckNow()
- func (c *CertificateChecker) Start()
- func (c *CertificateChecker) Stop()
- func (c *CertificateChecker) WithCheckInterval(interval time.Duration) *CertificateChecker
- func (c *CertificateChecker) WithThresholds(warning, critical int) *CertificateChecker
- type CombinedNotifier
- type DomainChecker
- type DomainExpiryData
- type DomainStore
- type EmailConfig
- type EmailNotifier
- type EmailSender
- type Notification
- type NotificationCreator
- type Service
- func (s *Service) Acknowledge(id int64) error
- func (s *Service) AcknowledgeAll() (int64, error)
- func (s *Service) Create(notificationType Type, severity Severity, title, message, data string) (*Notification, error)
- func (s *Service) Delete(id int64) error
- func (s *Service) DeleteOlderThan(d time.Duration) (int64, error)
- func (s *Service) ExistsUnacknowledged(notificationType Type, data string) (bool, error)
- func (s *Service) GetByID(id int64) (*Notification, error)
- func (s *Service) List(limit int, includeAcknowledged bool) ([]Notification, error)
- func (s *Service) ListBySeverity(severity Severity, limit int, includeAcknowledged bool) ([]Notification, error)
- func (s *Service) ListByType(notificationType Type, limit int, includeAcknowledged bool) ([]Notification, error)
- func (s *Service) UnreadCount() (int, error)
- func (s *Service) UnreadCountBySeverity(severity Severity) (int, error)
- type Severity
- type Type
- type WebhookConfig
- type WebhookNotifier
- type WebhookPayload
- type WebhookResult
- type WebhookSender
- type WebhookSenderOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShouldSendEmail ¶
func ShouldSendEmail(n *Notification, sendOnWarning bool) bool
ShouldSendEmail determines if an email should be sent for a notification based on severity. By default, emails are sent for critical and error notifications.
func ShouldSendWebhook ¶
func ShouldSendWebhook(n *Notification, minSeverity Severity) bool
ShouldSendWebhook determines if a webhook should be sent for a notification based on severity. By default, webhooks are sent for all notifications.
Types ¶
type CertExpiryData ¶
type CertExpiryData struct {
Domain string `json:"domain"`
Threshold string `json:"threshold"` // "30", "7", "expired"
ExpiresAt string `json:"expires_at,omitempty"`
}
CertExpiryData is stored in the notification data field to identify unique cert/threshold combinations.
type CertificateChecker ¶
type CertificateChecker struct {
// contains filtered or unexported fields
}
CertificateChecker checks certificate expiry and creates notifications.
func NewCertificateChecker ¶
func NewCertificateChecker(notificationCreator NotificationCreator, caddyAdminAPI string) *CertificateChecker
NewCertificateChecker creates a new certificate checker.
func (*CertificateChecker) CheckAll ¶
func (c *CertificateChecker) CheckAll()
CheckAll checks all certificates and creates notifications as needed.
func (*CertificateChecker) CheckNow ¶
func (c *CertificateChecker) CheckNow()
CheckNow runs an immediate certificate check (useful for testing or manual triggers).
func (*CertificateChecker) Start ¶
func (c *CertificateChecker) Start()
Start begins the background certificate checking job.
func (*CertificateChecker) Stop ¶
func (c *CertificateChecker) Stop()
Stop stops the background certificate checking job.
func (*CertificateChecker) WithCheckInterval ¶
func (c *CertificateChecker) WithCheckInterval(interval time.Duration) *CertificateChecker
WithCheckInterval sets a custom check interval (useful for testing).
func (*CertificateChecker) WithThresholds ¶
func (c *CertificateChecker) WithThresholds(warning, critical int) *CertificateChecker
WithThresholds sets custom warning and critical thresholds in days.
type CombinedNotifier ¶
type CombinedNotifier struct {
*Service
// contains filtered or unexported fields
}
CombinedNotifier wraps both email and webhook notification capabilities.
func NewCombinedNotifier ¶
func NewCombinedNotifier(service *Service, emailSender *EmailSender, webhookSender *WebhookSender, sendOnWarning bool, webhookMinSeverity Severity) *CombinedNotifier
NewCombinedNotifier creates a notifier that can send both email and webhook notifications.
func (*CombinedNotifier) Create ¶
func (n *CombinedNotifier) Create(notificationType Type, severity Severity, title, message, data string) (*Notification, error)
Create creates a notification and sends email/webhook notifications as configured.
type DomainChecker ¶
type DomainChecker struct {
// contains filtered or unexported fields
}
DomainChecker checks domain expiry and creates notifications.
func NewDomainChecker ¶
func NewDomainChecker(notificationCreator NotificationCreator, domainStore DomainStore) *DomainChecker
NewDomainChecker creates a new domain checker.
func (*DomainChecker) CheckAll ¶
func (c *DomainChecker) CheckAll()
CheckAll checks all domains and creates notifications as needed.
func (*DomainChecker) CheckNow ¶
func (c *DomainChecker) CheckNow()
CheckNow runs an immediate domain check (useful for testing or manual triggers).
func (*DomainChecker) Start ¶
func (c *DomainChecker) Start()
Start begins the background domain checking job.
func (*DomainChecker) Stop ¶
func (c *DomainChecker) Stop()
Stop stops the background domain checking job.
func (*DomainChecker) WithCheckInterval ¶
func (c *DomainChecker) WithCheckInterval(interval time.Duration) *DomainChecker
WithCheckInterval sets a custom check interval (useful for testing).
func (*DomainChecker) WithThresholds ¶
func (c *DomainChecker) WithThresholds(warning, critical int) *DomainChecker
WithThresholds sets custom warning and critical thresholds in days.
type DomainExpiryData ¶
type DomainExpiryData struct {
DomainID int64 `json:"domain_id"`
DomainName string `json:"domain_name"`
Threshold string `json:"threshold"` // "60", "14", "expired"
ExpiresAt string `json:"expires_at,omitempty"`
}
DomainExpiryData is stored in the notification data field to identify unique domain/threshold combinations.
type DomainStore ¶
DomainStore is an interface for accessing domain data.
type EmailConfig ¶
type EmailConfig struct {
// Enabled determines if email notifications are active.
Enabled bool
// SMTPHost is the SMTP server hostname.
SMTPHost string
// SMTPPort is the SMTP server port (typically 25, 465, or 587).
SMTPPort int
// SMTPUser is the username for SMTP authentication (optional).
SMTPUser string
// SMTPPassword is the password for SMTP authentication (optional).
SMTPPassword string
// FromAddress is the sender email address.
FromAddress string
// FromName is the sender display name.
FromName string
// ToAddresses is the list of recipient email addresses.
ToAddresses []string
// UseTLS enables TLS/SSL connection (port 465).
UseTLS bool
// UseSTARTTLS enables STARTTLS upgrade (port 587).
UseSTARTTLS bool
// InsecureSkipVerify skips TLS certificate verification (for testing only).
InsecureSkipVerify bool
}
EmailConfig holds SMTP configuration for sending email notifications.
type EmailNotifier ¶
type EmailNotifier struct {
*Service
// contains filtered or unexported fields
}
EmailNotifier wraps the notification service to send emails when notifications are created.
func NewEmailNotifier ¶
func NewEmailNotifier(service *Service, emailSender *EmailSender, sendOnWarning bool) *EmailNotifier
NewEmailNotifier creates a notifier that sends emails for important notifications.
func (*EmailNotifier) Create ¶
func (n *EmailNotifier) Create(notificationType Type, severity Severity, title, message, data string) (*Notification, error)
Create creates a notification and optionally sends an email for critical notifications.
type EmailSender ¶
type EmailSender struct {
// contains filtered or unexported fields
}
EmailSender handles sending email notifications.
func NewEmailSender ¶
func NewEmailSender(config EmailConfig) *EmailSender
NewEmailSender creates a new EmailSender with the given configuration.
func (*EmailSender) IsEnabled ¶
func (e *EmailSender) IsEnabled() bool
IsEnabled returns true if email notifications are enabled and configured.
func (*EmailSender) SendNotification ¶
func (e *EmailSender) SendNotification(n *Notification) error
SendNotification sends an email notification.
type Notification ¶
type Notification struct {
ID int64
Type Type
Severity Severity
Title string
Message string
Data string // JSON string for additional data
CreatedAt time.Time
AcknowledgedAt *time.Time
}
Notification represents a notification in the system.
func (*Notification) IsAcknowledged ¶
func (n *Notification) IsAcknowledged() bool
IsAcknowledged returns true if the notification has been acknowledged.
type NotificationCreator ¶
type NotificationCreator interface {
Create(notificationType Type, severity Severity, title, message, data string) (*Notification, error)
ExistsUnacknowledged(notificationType Type, data string) (bool, error)
}
NotificationCreator is an interface for creating notifications. This allows us to use either the basic Service or the EmailNotifier.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides methods for managing notifications.
func NewService ¶
NewService creates a new notification service.
func (*Service) Acknowledge ¶
Acknowledge marks a notification as acknowledged.
func (*Service) AcknowledgeAll ¶
AcknowledgeAll marks all unacknowledged notifications as acknowledged.
func (*Service) Create ¶
func (s *Service) Create(notificationType Type, severity Severity, title, message, data string) (*Notification, error)
Create creates a new notification.
func (*Service) DeleteOlderThan ¶
DeleteOlderThan deletes acknowledged notifications older than the given duration.
func (*Service) ExistsUnacknowledged ¶
ExistsUnacknowledged checks if there's an unacknowledged notification with the given type and data. This is useful to avoid creating duplicate notifications (e.g., for the same certificate expiry).
func (*Service) GetByID ¶
func (s *Service) GetByID(id int64) (*Notification, error)
GetByID retrieves a notification by its ID.
func (*Service) List ¶
func (s *Service) List(limit int, includeAcknowledged bool) ([]Notification, error)
List retrieves notifications with optional filters.
func (*Service) ListBySeverity ¶
func (s *Service) ListBySeverity(severity Severity, limit int, includeAcknowledged bool) ([]Notification, error)
ListBySeverity retrieves notifications of a specific severity.
func (*Service) ListByType ¶
func (s *Service) ListByType(notificationType Type, limit int, includeAcknowledged bool) ([]Notification, error)
ListByType retrieves notifications of a specific type.
func (*Service) UnreadCount ¶
UnreadCount returns the count of unacknowledged notifications.
type WebhookConfig ¶
type WebhookConfig struct {
// URL is the webhook endpoint URL.
URL string
// Headers are optional headers to include with each request.
Headers map[string]string
// Enabled determines if this webhook is active.
Enabled bool
}
WebhookConfig holds configuration for a webhook endpoint.
type WebhookNotifier ¶
type WebhookNotifier struct {
*Service
// contains filtered or unexported fields
}
WebhookNotifier wraps the notification service to send webhooks when notifications are created.
func NewWebhookNotifier ¶
func NewWebhookNotifier(service *Service, webhookSender *WebhookSender, minSeverity Severity) *WebhookNotifier
NewWebhookNotifier creates a notifier that sends webhooks for notifications.
func (*WebhookNotifier) Create ¶
func (n *WebhookNotifier) Create(notificationType Type, severity Severity, title, message, data string) (*Notification, error)
Create creates a notification and optionally sends webhooks.
type WebhookPayload ¶
type WebhookPayload struct {
ID int64 `json:"id"`
Type string `json:"type"`
Severity string `json:"severity"`
Title string `json:"title"`
Message string `json:"message"`
Data string `json:"data,omitempty"`
CreatedAt time.Time `json:"created_at"`
Timestamp int64 `json:"timestamp"`
}
WebhookPayload is the JSON payload sent to webhook endpoints.
type WebhookResult ¶
WebhookResult contains the result of a webhook delivery attempt.
type WebhookSender ¶
type WebhookSender struct {
// contains filtered or unexported fields
}
WebhookSender handles sending notifications to webhook endpoints.
func NewWebhookSender ¶
func NewWebhookSender(configs []WebhookConfig, opts ...WebhookSenderOption) *WebhookSender
NewWebhookSender creates a new WebhookSender with the given configurations.
func (*WebhookSender) EnabledCount ¶
func (w *WebhookSender) EnabledCount() int
EnabledCount returns the number of enabled webhook endpoints.
func (*WebhookSender) IsEnabled ¶
func (w *WebhookSender) IsEnabled() bool
IsEnabled returns true if at least one webhook is configured and enabled.
func (*WebhookSender) SendNotification ¶
func (w *WebhookSender) SendNotification(n *Notification) []WebhookResult
SendNotification sends a notification to all enabled webhook endpoints. Returns a slice of results for each webhook endpoint.
func (*WebhookSender) SendNotificationAsync ¶
func (w *WebhookSender) SendNotificationAsync(n *Notification)
SendNotificationAsync sends a notification asynchronously and logs any errors.
type WebhookSenderOption ¶
type WebhookSenderOption func(*WebhookSender)
WebhookSenderOption is a functional option for configuring WebhookSender.
func WithBaseDelay ¶
func WithBaseDelay(d time.Duration) WebhookSenderOption
WithBaseDelay sets the base delay for exponential backoff.
func WithHTTPClient ¶
func WithHTTPClient(c *http.Client) WebhookSenderOption
WithHTTPClient sets a custom HTTP client.
func WithMaxDelay ¶
func WithMaxDelay(d time.Duration) WebhookSenderOption
WithMaxDelay sets the maximum delay between retries.
func WithMaxRetries ¶
func WithMaxRetries(n int) WebhookSenderOption
WithMaxRetries sets the maximum number of retry attempts.