Documentation
¶
Index ¶
Constants ¶
View Source
const ( NotificationCategorySpeedtest = "speedtest" NotificationCategoryPacketLoss = "packetloss" NotificationCategoryAgent = "agent" )
NotificationEventCategory constants
View Source
const ( // Speedtest events NotificationEventSpeedtestComplete = "complete" NotificationEventSpeedtestPingHigh = "ping_high" NotificationEventSpeedtestDownloadLow = "download_low" NotificationEventSpeedtestUploadLow = "upload_low" NotificationEventSpeedtestFailed = "failed" // Packet loss events NotificationEventPacketLossHigh = "threshold_exceeded" NotificationEventPacketLossDown = "monitor_down" NotificationEventPacketLossRecovered = "monitor_recovered" // Agent events NotificationEventAgentOffline = "offline" NotificationEventAgentOnline = "online" NotificationEventAgentHighBandwidth = "high_bandwidth" NotificationEventAgentLowDisk = "disk_space_low" NotificationEventAgentHighCPU = "cpu_high" NotificationEventAgentHighMemory = "memory_high" NotificationEventAgentHighTemp = "temperature_high" )
NotificationEventType constants
View Source
const ( ThresholdOperatorGT = "gt" // greater than ThresholdOperatorLT = "lt" // less than ThresholdOperatorEQ = "eq" // equal ThresholdOperatorGTE = "gte" // greater than or equal ThresholdOperatorLTE = "lte" // less than or equal )
ThresholdOperator constants
Variables ¶
View Source
var ( ErrNotFound = fmt.Errorf("record not found") ErrInvalidInput = fmt.Errorf("invalid input") )
Common errors
Functions ¶
This section is empty.
Types ¶
type NotificationChannel ¶ added in v0.4.0
type NotificationChannelInput ¶ added in v0.4.0
type NotificationEvent ¶ added in v0.4.0
type NotificationEvent struct {
ID int64 `json:"id" db:"id"`
Category string `json:"category" db:"category"`
EventType string `json:"event_type" db:"event_type"`
Name string `json:"name" db:"name"`
Description *string `json:"description" db:"description"`
DefaultEnabled bool `json:"default_enabled" db:"default_enabled"`
SupportsThreshold bool `json:"supports_threshold" db:"supports_threshold"`
ThresholdUnit *string `json:"threshold_unit" db:"threshold_unit"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
type NotificationHistory ¶ added in v0.4.0
type NotificationHistory struct {
ID int64 `json:"id" db:"id"`
ChannelID int64 `json:"channel_id" db:"channel_id"`
EventID int64 `json:"event_id" db:"event_id"`
Success bool `json:"success" db:"success"`
ErrorMessage *string `json:"error_message" db:"error_message"`
Payload *string `json:"payload" db:"payload"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
type NotificationRule ¶ added in v0.4.0
type NotificationRule struct {
ID int64 `json:"id" db:"id"`
ChannelID int64 `json:"channel_id" db:"channel_id"`
EventID int64 `json:"event_id" db:"event_id"`
Enabled bool `json:"enabled" db:"enabled"`
ThresholdValue *float64 `json:"threshold_value" db:"threshold_value"`
ThresholdOperator *string `json:"threshold_operator" db:"threshold_operator"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
// Joined fields for queries
Channel *NotificationChannel `json:"channel,omitempty" db:"-"`
Event *NotificationEvent `json:"event,omitempty" db:"-"`
}
type NotificationRuleInput ¶ added in v0.4.0
type NotificationRuleInput struct {
ChannelID int64 `json:"channel_id" validate:"required"`
EventID int64 `json:"event_id" validate:"required"`
Enabled *bool `json:"enabled"`
ThresholdValue *float64 `json:"threshold_value"`
ThresholdOperator *string `json:"threshold_operator" validate:"omitempty,oneof=gt lt eq gte lte"`
}
type NotificationService ¶ added in v0.4.0
type NotificationService interface {
// Channels
CreateChannel(input NotificationChannelInput) (*NotificationChannel, error)
GetChannel(id int64) (*NotificationChannel, error)
GetChannels() ([]NotificationChannel, error)
GetEnabledChannels() ([]NotificationChannel, error)
UpdateChannel(id int64, input NotificationChannelInput) (*NotificationChannel, error)
DeleteChannel(id int64) error
// Events
GetEvents() ([]NotificationEvent, error)
GetEventsByCategory(category string) ([]NotificationEvent, error)
GetEvent(id int64) (*NotificationEvent, error)
GetEventByType(category, eventType string) (*NotificationEvent, error)
// Rules
CreateRule(input NotificationRuleInput) (*NotificationRule, error)
GetRule(id int64) (*NotificationRule, error)
GetRules() ([]NotificationRule, error)
GetRulesByChannel(channelID int64) ([]NotificationRule, error)
GetRulesByEvent(eventID int64) ([]NotificationRule, error)
GetEnabledRulesForEvent(category, eventType string) ([]NotificationRule, error)
UpdateRule(id int64, input NotificationRuleInput) (*NotificationRule, error)
DeleteRule(id int64) error
// History
LogNotification(channelID, eventID int64, success bool, errorMessage *string, payload *string) error
GetNotificationHistory(limit int) ([]NotificationHistory, error)
// Utility
CheckThreshold(rule *NotificationRule, value float64) bool
}
NotificationService interface for database operations
type Service ¶
type Service interface {
Health() map[string]string
Close() error
InitializeTables(ctx context.Context) error
QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
// User operations
CreateUser(ctx context.Context, username, password string) (*User, error)
GetUserByUsername(ctx context.Context, username string) (*User, error)
ValidatePassword(user *User, password string) bool
UpdatePassword(ctx context.Context, username, newPassword string) error
// SpeedTest operations
SaveSpeedTest(ctx context.Context, result types.SpeedTestResult) (*types.SpeedTestResult, error)
GetSpeedTests(ctx context.Context, timeRange string, page int, limit int) (*types.PaginatedSpeedTests, error)
// Schedule operations
CreateSchedule(ctx context.Context, schedule types.Schedule) (*types.Schedule, error)
GetSchedules(ctx context.Context) ([]types.Schedule, error)
UpdateSchedule(ctx context.Context, schedule types.Schedule) error
DeleteSchedule(ctx context.Context, id int64) error
// IPerf operations
SaveIperfServer(ctx context.Context, name, host string, port int) (*types.SavedIperfServer, error)
GetIperfServers(ctx context.Context) ([]types.SavedIperfServer, error)
DeleteIperfServer(ctx context.Context, id int) error
// Packet Loss operations
GetPacketLossMonitor(monitorID int64) (*types.PacketLossMonitor, error)
GetEnabledPacketLossMonitors() ([]*types.PacketLossMonitor, error)
SavePacketLossResult(result *types.PacketLossResult) error
GetLatestPacketLossResult(monitorID int64) (*types.PacketLossResult, error)
CreatePacketLossMonitor(monitor *types.PacketLossMonitor) (*types.PacketLossMonitor, error)
UpdatePacketLossMonitor(monitor *types.PacketLossMonitor) error
DeletePacketLossMonitor(monitorID int64) error
GetPacketLossMonitors() ([]*types.PacketLossMonitor, error)
GetPacketLossResults(monitorID int64, limit int) ([]*types.PacketLossResult, error)
UpdatePacketLossMonitorState(monitorID int64, state string) error
// Monitor operations
CreateMonitorAgent(ctx context.Context, agent *types.MonitorAgent) (*types.MonitorAgent, error)
GetMonitorAgent(ctx context.Context, agentID int64) (*types.MonitorAgent, error)
GetMonitorAgents(ctx context.Context, enabledOnly bool) ([]*types.MonitorAgent, error)
UpdateMonitorAgent(ctx context.Context, agent *types.MonitorAgent) error
DeleteMonitorAgent(ctx context.Context, agentID int64) error
// Monitor agent data operations
UpsertMonitorSystemInfo(ctx context.Context, agentID int64, info *types.MonitorSystemInfo) error
GetMonitorSystemInfo(ctx context.Context, agentID int64) (*types.MonitorSystemInfo, error)
UpsertMonitorInterfaces(ctx context.Context, agentID int64, interfaces []types.MonitorInterface) error
GetMonitorInterfaces(ctx context.Context, agentID int64) ([]types.MonitorInterface, error)
UpsertMonitorPeakStats(ctx context.Context, agentID int64, stats *types.MonitorPeakStats) error
GetMonitorPeakStats(ctx context.Context, agentID int64) (*types.MonitorPeakStats, error)
SaveMonitorResourceStats(ctx context.Context, agentID int64, stats *types.MonitorResourceStats) error
GetMonitorResourceStats(ctx context.Context, agentID int64, hours int) ([]types.MonitorResourceStats, error)
SaveMonitorHistoricalSnapshot(ctx context.Context, agentID int64, snapshot *types.MonitorHistoricalSnapshot) error
GetMonitorLatestSnapshot(ctx context.Context, agentID int64, periodType string) (*types.MonitorHistoricalSnapshot, error)
CleanupMonitorData(ctx context.Context) error
// Embed NotificationService interface
NotificationService
}
Service represents the core database functionality
func New ¶
func New(cfg config.DatabaseConfig) Service
type UserService ¶
type ZerologAdapter ¶ added in v0.1.0
type ZerologAdapter struct {
// contains filtered or unexported fields
}
ZerologAdapter adapts zerolog.Logger to migrator.Logger
func (*ZerologAdapter) Printf ¶ added in v0.1.0
func (z *ZerologAdapter) Printf(format string, args ...interface{})
Source Files
¶
Click to show internal directories.
Click to hide internal directories.