monitor

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeCursor added in v0.1.9

func EncodeCursor(c Cursor) (string, error)

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 {
	TeamID             uuid.UUID
	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:"omitempty,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 Cursor added in v0.1.9

type Cursor struct {
	CreatedAt time.Time
	MonitorID string
}

func DecodeCursor added in v0.1.9

func DecodeCursor(v string) (*Cursor, error)

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"`
	IsDown             bool   `json:"is_down"`
}

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)

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)

type ListMonitorsOptions added in v0.1.9

type ListMonitorsOptions struct {
	Limit  int32
	Cursor *Cursor
}

type ListMonitorsPage added in v0.1.9

type ListMonitorsPage struct {
	Monitors   []Monitor
	HasMore    bool
	NextCursor *string
	Limit      int32
}

type ListMonitorsResponse added in v0.1.9

type ListMonitorsResponse struct {
	Limit      int32                `json:"limit"`
	HasMore    bool                 `json:"has_more"`
	NextCursor *string              `json:"next_cursor,omitempty"`
	Monitors   []GetMonitorResponse `json:"monitors"`
}

type Monitor

type Monitor struct {
	ID                 uuid.UUID
	TeamID             uuid.UUID
	UserID             uuid.UUID
	Url                string
	AlertEmail         string
	IntervalSec        int32
	TimeoutSec         int32
	LatencyThresholdMs *int32
	ExpectedStatus     *int32
	Enabled            bool
	CreatedAt          time.Time
	IsDown             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) CloseOpenIncident added in v0.1.9

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

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, teamID, monitorID uuid.UUID) error

func (*Repository) Get

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

func (*Repository) GetAll

func (r *Repository) GetAll(ctx context.Context, teamID uuid.UUID, opts ListMonitorsOptions) ([]Monitor, bool, 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, teamID, 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, teamID, monitorID uuid.UUID) error

func (*Service) GetAllMonitors

func (s *Service) GetAllMonitors(ctx context.Context, teamID uuid.UUID, opts ListMonitorsOptions) (ListMonitorsPage, error)

func (*Service) GetMonitor

func (s *Service) GetMonitor(ctx context.Context, teamID 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, teamID, 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