monitor

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Routes

func Routes(h *Handler) chi.Router

Types

type Cache

type Cache interface {
	GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, bool)
	SetMonitor(ctx context.Context, m Monitor) error
	Schedule(ctx context.Context, monitorID string, runAt time.Time) error
	ClearIncident(ctx context.Context, monitorID uuid.UUID) error
	DelMonitor(ctx context.Context, id uuid.UUID) error
	DelStatus(ctx context.Context, monitorID uuid.UUID) error
	DelSchedule(ctx context.Context, monitorID string) error
}

type CreateMonitor

type CreateMonitor struct {
	UserID             uuid.UUID
	Url                string
	IntervalSec        int32
	TimeoutSec         int32
	LatencyThresholdMs *int32
	ExpectedStatus     *int32
	AlertEmail         string
}

type CreateMonitorRequest

type CreateMonitorRequest struct {
	Url                string `json:"url" validate:"required,url"`
	AlertEmail         string `json:"alert_email" validate:"email"`
	IntervalSec        int32  `json:"interval_sec" validate:"required,gte=60"`
	TimeoutSec         int32  `json:"timeout_sec" validate:"required,gte=120"`
	LatencyThresholdMs *int32 `json:"latency_threshold_ms"`
	ExpectedStatus     *int32 `json:"expected_status"`
}

type CreateMonitorResponse

type CreateMonitorResponse struct {
	MonitorID string `json:"monitor_id"`
}

type GetAllMonitorsResponse

type GetAllMonitorsResponse struct {
	UserID   string               `json:"user_id"`
	Limit    int32                `json:"limit"`
	Offset   int32                `json:"offset"`
	Monitors []GetMonitorResponse `json:"monitors"`
}

type GetMonitorResponse

type GetMonitorResponse struct {
	ID                 string `json:"id"`
	Url                string `json:"url"`
	AlertEmail         string `json:"alert_mail"`
	IntervalSec        int32  `json:"interval_sec"`
	TimeoutSec         int32  `json:"timeout_sec"`
	LatencyThresholdMs *int32 `json:"latency_threshold_ms"`
	ExpectedStatus     *int32 `json:"expected_status"`
	Enabled            bool   `json:"enabled"`
}

type Handler

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

func NewHandler

func NewHandler(service *Service, validator *validator.Validate, logger *zerolog.Logger) *Handler

func (*Handler) CreateMonitor

func (h *Handler) CreateMonitor(w http.ResponseWriter, r *http.Request)

func (*Handler) DeleteMonitor added in v0.1.2

func (h *Handler) DeleteMonitor(w http.ResponseWriter, r *http.Request)

func (*Handler) GetAllMonitors

func (h *Handler) GetAllMonitors(w http.ResponseWriter, r *http.Request)

/monitors?offset=3&limit=10

func (*Handler) GetMonitor

func (h *Handler) GetMonitor(w http.ResponseWriter, r *http.Request)

func (*Handler) UpdateMonitorStatus

func (h *Handler) UpdateMonitorStatus(w http.ResponseWriter, r *http.Request)

Patch : /monitors/{monitorID}

{
	enable: false/true
}

type Monitor

type Monitor struct {
	ID                 uuid.UUID
	UserID             uuid.UUID
	Url                string
	AlertEmail         string
	IntervalSec        int32
	TimeoutSec         int32
	LatencyThresholdMs *int32
	ExpectedStatus     *int32
	Enabled            bool
}

type MonitorRecord

type MonitorRecord struct {
	ID                 uuid.UUID
	UserID             uuid.UUID
	Url                string
	IntervalSec        time.Duration
	TimeoutSec         time.Duration
	LatencyThresholdMS time.Duration
	ExpectedStatus     int
	Enabled            bool
	Disabled           bool
}

type Repository

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

func NewRepository

func NewRepository(dbExecutor db.DBTX, logger *zerolog.Logger) *Repository

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, monitor CreateMonitor) (uuid.UUID, error)

func (*Repository) Delete added in v0.1.2

func (r *Repository) Delete(ctx context.Context, userID, monitorID uuid.UUID) error

func (*Repository) Get

func (r *Repository) Get(ctx context.Context, userID, monitorID uuid.UUID) (Monitor, error)

func (*Repository) GetAll

func (r *Repository) GetAll(ctx context.Context, userID uuid.UUID, limit int32, offset int32) ([]Monitor, error)

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, monitorID uuid.UUID) (Monitor, error)

func (*Repository) SetEnabled

func (r *Repository) SetEnabled(ctx context.Context, userID, monitorID uuid.UUID, enabled bool) error

type Service

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

func NewService

func NewService(monitorRepo *Repository, cache Cache, userSvc UserService, logger *zerolog.Logger) *Service

func (*Service) CreateMonitor

func (s *Service) CreateMonitor(ctx context.Context, data CreateMonitor) (uuid.UUID, error)

func (*Service) DeleteMonitor added in v0.1.2

func (s *Service) DeleteMonitor(ctx context.Context, userID, monitorID uuid.UUID) error

func (*Service) GetAllMonitors

func (s *Service) GetAllMonitors(ctx context.Context, userID uuid.UUID, limit int32, offset int32) ([]Monitor, error)

func (*Service) GetMonitor

func (s *Service) GetMonitor(ctx context.Context, userID uuid.UUID, monitorID uuid.UUID) (Monitor, error)

func (*Service) LoadMonitor

func (s *Service) LoadMonitor(ctx context.Context, monitorID uuid.UUID) (Monitor, error)

func (*Service) ScheduleMonitor

func (s *Service) ScheduleMonitor(ctx context.Context, mID uuid.UUID, intervalSec int32, op string)

func (*Service) UpdateMonitorStatus

func (s *Service) UpdateMonitorStatus(ctx context.Context, userID, monitorID uuid.UUID, enable bool) (bool, error)

type UpdateMonitorStatusRequest

type UpdateMonitorStatusRequest struct {
	Enable *bool `json:"enable" validate:"required"`
}

type UserService

type UserService interface {
	IncrementMonitorCount(ctx context.Context, userID uuid.UUID) error
	DecrementMonitorCount(ctx context.Context, userID uuid.UUID) error
}

Jump to

Keyboard shortcuts

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