models

package
v0.0.0-...-0bdedc6 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidRouteConfig = NewValidationError("Invalid route config")
	UnknownRouteType   = NewValidationError("unknown route type")
)
View Source
var (
	ErrMonitorNotFound          = errors.New("Monitor not found")
	ErrMonitorCollectorsInvalid = errors.New("Invalid Collector specified for Monitor")
	ErrMonitorSettingsInvalid   = errors.New("Invald variables used in Monitor Settings")
	ErrorEndpointCantBeChanged  = errors.New("A monitor's endpoint_id can not be changed.")
)

Typed errors

View Source
var (
	MonitorTypeToCheckTypeMap = []CheckType{
		HTTP_CHECK,
		HTTPS_CHECK,
		PING_CHECK,
		DNS_CHECK,
	}
	CheckTypeToMonitorTypeMap = map[CheckType]int64{
		HTTP_CHECK:  1,
		HTTPS_CHECK: 2,
		PING_CHECK:  3,
		DNS_CHECK:   4,
	}
)
View Source
var (
	ErrProbeNotFound           = NewNotFoundError("Probe not found")
	ErrProbeWithSameCodeExists = NewValidationError("A Probe with the same code already exists")
)

Typed errors

View Source
var (
	ErrEndpointNotFound = NewNotFoundError("Endpoint not found")
)

Typed errors

View Source
var ErrInvalidEmailCode = errors.New("Invalid or expired email code")
View Source
var ErrInvalidQuotaTarget = errors.New("Invalid quota target")
View Source
var MonitorTypes = []MonitorTypeDTO{
	{
		Id:   1,
		Name: "HTTP",
		Settings: []MonitorTypeSettingDTO{
			{
				Variable:     "host",
				Description:  "Hostname",
				Required:     true,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "",
			},
			{
				Variable:     "path",
				Description:  "Path",
				Required:     true,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "/",
			},
			{
				Variable:     "port",
				Description:  "Port",
				Required:     false,
				DataType:     "Number",
				Conditions:   map[string]interface{}{},
				DefaultValue: "80",
			},
			{
				Variable:    "method",
				Description: "Method",
				Required:    false,
				DataType:    "Enum",
				Conditions: map[string]interface{}{
					"values": []string{"GET", "POST", "PUT", "DELETE", "HEAD"},
				},
				DefaultValue: "GET",
			},
			{
				Variable:     "headers",
				Description:  "Headers",
				Required:     false,
				DataType:     "Text",
				Conditions:   map[string]interface{}{},
				DefaultValue: "Accept-Encoding: gzip\nUser-Agent: raintank collector\n",
			},
			{
				Variable:     "expectRegex",
				Description:  "Content Match",
				Required:     false,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "",
			},
			{
				Variable:     "timeout",
				Description:  "Timeout",
				Required:     true,
				DataType:     "Number",
				Conditions:   map[string]interface{}{},
				DefaultValue: "5",
			},
		},
	},
	{
		Id:   2,
		Name: "HTTPS",
		Settings: []MonitorTypeSettingDTO{
			{
				Variable:     "host",
				Description:  "Hostname",
				Required:     true,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "",
			},
			{
				Variable:     "path",
				Description:  "Path",
				Required:     true,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "/",
			},
			{
				Variable:     "port",
				Description:  "Port",
				Required:     false,
				DataType:     "Number",
				Conditions:   map[string]interface{}{},
				DefaultValue: "443",
			},
			{
				Variable:    "method",
				Description: "Method",
				Required:    false,
				DataType:    "Enum",
				Conditions: map[string]interface{}{
					"values": []string{"GET", "POST", "PUT", "DELETE", "HEAD"},
				},
				DefaultValue: "GET",
			},
			{
				Variable:     "headers",
				Description:  "Headers",
				Required:     false,
				DataType:     "Text",
				Conditions:   map[string]interface{}{},
				DefaultValue: "Accept-Encoding: gzip\nUser-Agent: raintank collector\n",
			},
			{
				Variable:     "expectRegex",
				Description:  "Content Match",
				Required:     false,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "",
			},
			{
				Variable:     "validateCert",
				Description:  "Validate SSL Certificate",
				Required:     false,
				DataType:     "Boolean",
				Conditions:   map[string]interface{}{},
				DefaultValue: "true",
			},
			{
				Variable:     "timeout",
				Description:  "Timeout",
				Required:     true,
				DataType:     "Number",
				Conditions:   map[string]interface{}{},
				DefaultValue: "5",
			},
		},
	},
	{
		Id:   3,
		Name: "Ping",
		Settings: []MonitorTypeSettingDTO{
			{
				Variable:     "hostname",
				Description:  "Hostname",
				Required:     true,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "",
			},
			{
				Variable:     "timeout",
				Description:  "Timeout",
				Required:     true,
				DataType:     "Number",
				Conditions:   map[string]interface{}{},
				DefaultValue: "5",
			},
		},
	},
	{
		Id:   4,
		Name: "DNS",
		Settings: []MonitorTypeSettingDTO{
			{
				Variable:     "name",
				Description:  "Record Name",
				Required:     true,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "",
			},
			{
				Variable:    "type",
				Description: "Record Type",
				Required:    true,
				DataType:    "Enum",
				Conditions: map[string]interface{}{
					"values": []string{"A", "AAAA", "CNAME", "MX", "NS", "PTR", "SOA", "SRV", "TXT"},
				},
				DefaultValue: "A",
			},
			{
				Variable:     "server",
				Description:  "Server",
				Required:     true,
				DataType:     "String",
				Conditions:   map[string]interface{}{},
				DefaultValue: "",
			},
			{
				Variable:     "port",
				Description:  "Port",
				Required:     false,
				DataType:     "Number",
				Conditions:   map[string]interface{}{},
				DefaultValue: "53",
			},
			{
				Variable:    "protocol",
				Description: "Protocol",
				Required:    false,
				DataType:    "Enum",
				Conditions: map[string]interface{}{
					"values": []string{"tcp", "udp"},
				},
				DefaultValue: "udp",
			},
			{
				Variable:     "timeout",
				Description:  "Timeout",
				Required:     true,
				DataType:     "Number",
				Conditions:   map[string]interface{}{},
				DefaultValue: "5",
			},
		},
	},
}

Functions

This section is empty.

Types

type AddEndpointCommand

type AddEndpointCommand struct {
	OrgId    int64                `json:"-"`
	Name     string               `json:"name" binding:"Required"`
	Tags     []string             `json:"tags"`
	Monitors []*AddMonitorCommand `json:"monitors"`
	Result   *EndpointDTO         `json:"-"`
}

type AddMonitorCommand

type AddMonitorCommand struct {
	OrgId          int64                `json:"-"`
	EndpointId     int64                `json:"endpoint_id" binding:"Required"`
	MonitorTypeId  int64                `json:"monitor_type_id" binding:"Required"`
	CollectorIds   []int64              `json:"collector_ids"`
	CollectorTags  []string             `json:"collector_tags"`
	Settings       []MonitorSettingDTO  `json:"settings"`
	HealthSettings *CheckHealthSettings `json:"health_settings"`
	Frequency      int64                `json:"frequency" binding:"Required;Range(10,600)"`
	Enabled        bool                 `json:"enabled"`
	Offset         int64                `json:"-"`
	Result         *MonitorDTO          `json:"-"`
}

type AlertSchedulerValue

type AlertSchedulerValue struct {
	Id    string
	Value string
}

type AlertingJob

type AlertingJob struct {
	*CheckForAlertDTO
	GeneratedAt time.Time
	LastPointTs time.Time
	NewState    CheckEvalResult
	TimeExec    time.Time
}

Job is a job for an alert execution note that LastPointTs is a time denoting the timestamp of the last point to run against this way the check runs always on the right data, irrespective of execution delays that said, for convenience, we track the generatedAt timestamp

func (*AlertingJob) String

func (job *AlertingJob) String() string

type AppError

type AppError interface {
	Code() int
	Message() string
}

type BillingUsage

type BillingUsage struct {
	OrgId           int64
	ChecksPerMinute float64
}

type Check

type Check struct {
	Id             int64                  `json:"id"`
	OrgId          int64                  `json:"orgId"`
	EndpointId     int64                  `json:"endpointId"`
	Route          *CheckRoute            `xorm:"JSON" json:"route"`
	Type           CheckType              `json:"type" binding:"Required,In(http,https,dns,ping)"`
	Frequency      int64                  `json:"frequency" binding:"Required,Range(10,300)"`
	Offset         int64                  `json:"offset"`
	Enabled        bool                   `json:"enabled"`
	State          CheckEvalResult        `json:"state"`
	StateChange    time.Time              `json:"stateChange"`
	StateCheck     time.Time              `json:"stateCheck"`
	Settings       map[string]interface{} `json:"settings" binding:"Required"`
	HealthSettings *CheckHealthSettings   `xorm:"JSON" json:"healthSettings"`
	Created        time.Time              `json:"created"`
	Updated        time.Time              `json:"updated"`
}

func (Check) Validate

func (c Check) Validate(quotas []OrgQuotaDTO) error

type CheckDNSUsage

type CheckDNSUsage struct {
	Total  int64
	PerOrg map[string]int64
}

type CheckEvalResult

type CheckEvalResult int
const (
	EvalResultOK CheckEvalResult = iota
	EvalResultWarn
	EvalResultCrit
	EvalResultUnknown = -1
)

func (CheckEvalResult) String

func (c CheckEvalResult) String() string

type CheckForAlertDTO

type CheckForAlertDTO struct {
	Id             int64
	OrgId          int64
	EndpointId     int64
	Slug           string
	Name           string
	Type           string
	Offset         int64
	Frequency      int64
	Enabled        bool
	State          CheckEvalResult
	StateChange    time.Time
	StateCheck     time.Time
	Settings       map[string]interface{} `xorm:"JSON"`
	HealthSettings *CheckHealthSettings   `xorm:"JSON"`
	Created        time.Time
	Updated        time.Time
}

type CheckHTTPSUsage

type CheckHTTPSUsage struct {
	Total  int64
	PerOrg map[string]int64
}

type CheckHTTPUsage

type CheckHTTPUsage struct {
	Total  int64
	PerOrg map[string]int64
}

type CheckHealthSettings

type CheckHealthSettings struct {
	NumProbes     int                      `json:"num_collectors" binding:"Required"`
	Steps         int                      `json:"steps" binding:"Required"`
	Notifications CheckNotificationSetting `json:"notifications"`
}

type CheckNotificationSetting

type CheckNotificationSetting struct {
	Enabled   bool   `json:"enabled"`
	Addresses string `json:"addresses"`
}

type CheckPINGUsage

type CheckPINGUsage struct {
	Total  int64
	PerOrg map[string]int64
}

type CheckRoute

type CheckRoute struct {
	Type   RouteType              `json:"type" binding:"Required"`
	Config map[string]interface{} `json:"config"`
}

func (*CheckRoute) UnmarshalJSON

func (t *CheckRoute) UnmarshalJSON(body []byte) error

func (*CheckRoute) Validate

func (r *CheckRoute) Validate() error

type CheckState

type CheckState struct {
	Id      int64
	State   CheckEvalResult
	Updated time.Time // this protects against jobs running out of order.
	Checked time.Time
}

type CheckType

type CheckType string
const (
	HTTP_CHECK  CheckType = "http"
	HTTPS_CHECK CheckType = "https"
	DNS_CHECK   CheckType = "dns"
	PING_CHECK  CheckType = "ping"
)

type CheckUsage

type CheckUsage struct {
	Total int64
	HTTP  CheckHTTPUsage
	HTTPS CheckHTTPSUsage
	PING  CheckPINGUsage
	DNS   CheckDNSUsage
}

type CheckWithSlug

type CheckWithSlug struct {
	Check `xorm:"extends"`
	Slug  string `json:"endpointSlug"`
}

type DeleteMonitorCommand

type DeleteMonitorCommand struct {
	Id    int64 `json:"id" binding:"Required"`
	OrgId int64 `json:"-"`
}

type DiscoverEndpointCmd

type DiscoverEndpointCmd struct {
	Name string `form:"name"`
}

---------------------- COMMANDS

type Endpoint

type Endpoint struct {
	Id      int64
	OrgId   int64
	Name    string
	Slug    string
	Created time.Time
	Updated time.Time
}

func (*Endpoint) UpdateSlug

func (endpoint *Endpoint) UpdateSlug()

type EndpointDTO

type EndpointDTO struct {
	Id      int64     `json:"id"`
	OrgId   int64     `json:"orgId"`
	Name    string    `json:"name" binding:"Required"`
	Slug    string    `json:"slug"`
	Checks  []Check   `json:"checks"`
	Tags    []string  `json:"tags"`
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
}

type EndpointTag

type EndpointTag struct {
	Id         int64
	OrgId      int64
	EndpointId int64
	Tag        string
	Created    time.Time
}

type EndpointUsage

type EndpointUsage struct {
	Total  int64
	PerOrg map[string]int64
}

type GetEndpointsQuery

type GetEndpointsQuery struct {
	OrgId   int64  `form:"-"`
	Name    string `form:"name"`
	Tag     string `form:"tag"`
	OrderBy string `form:"orderBy" binding:"In(name,slug,created,updated,)"`
}

--------------------- QUERIES

type GetMonitorsQuery

type GetMonitorsQuery struct {
	EndpointId int64 `form:"endpoint_id"`
}

type GetProbesQuery

type GetProbesQuery struct {
	OrgId   int64  `form:"-"`
	Public  string `form:"public"`
	Enabled string `form:"enabled"`
	Online  string `form:"online"`
	Name    string `form:"name"`
	Slug    string `form:"slug"`
	Tag     string `form:"tag"`
	OrderBy string `form:"orderBy" binding:"In(name,slug,created,updated,)"`
}

type GlobalQuotaDTO

type GlobalQuotaDTO struct {
	Target string `json:"target"`
	Limit  int64  `json:"limit"`
	Used   int64  `json:"used"`
}

type Monitor

type Monitor struct {
	Id             int64
	OrgId          int64
	EndpointId     int64
	MonitorTypeId  int64
	Offset         int64
	Frequency      int64
	Enabled        bool
	State          CheckEvalResult
	StateChange    time.Time
	StateCheck     time.Time
	Settings       []MonitorSettingDTO
	HealthSettings *CheckHealthSettings
	Created        time.Time
	Updated        time.Time
}

type MonitorDTO

type MonitorDTO struct {
	Id              int64                `json:"id"`
	OrgId           int64                `json:"org_id"`
	EndpointId      int64                `json:"endpoint_id" `
	EndpointSlug    string               `json:"endpoint_slug"`
	MonitorTypeId   int64                `json:"monitor_type_id"`
	MonitorTypeName string               `json:"monitor_type_name"`
	CollectorIds    []int64              `json:"collector_ids"`
	CollectorTags   []string             `json:"collector_tags"`
	Collectors      []int64              `json:"collectors"`
	State           CheckEvalResult      `json:"state"`
	StateChange     time.Time            `json:"state_change"`
	StateCheck      time.Time            `json:"state_check"`
	Settings        []MonitorSettingDTO  `json:"settings"`
	HealthSettings  *CheckHealthSettings `json:"health_settings"`
	Frequency       int64                `json:"frequency"`
	Enabled         bool                 `json:"enabled"`
	Offset          int64                `json:"offset"`
	Updated         time.Time            `json:"updated"`
}

func MonitorDTOFromCheck

func MonitorDTOFromCheck(c Check, endpointSlug string) MonitorDTO

func MonitorDTOFromCheckWithSlug

func MonitorDTOFromCheckWithSlug(c CheckWithSlug) MonitorDTO

type MonitorForAlertDTO

type MonitorForAlertDTO struct {
	Id              int64
	OrgId           int64
	EndpointId      int64
	EndpointSlug    string
	EndpointName    string
	MonitorTypeId   int64
	MonitorTypeName string
	Offset          int64
	Frequency       int64
	Enabled         bool
	StateChange     time.Time
	StateCheck      time.Time
	Settings        []MonitorSettingDTO
	HealthSettings  *CheckHealthSettings
	Created         time.Time
	Updated         time.Time
}

func (*MonitorForAlertDTO) SettingsMap

func (m *MonitorForAlertDTO) SettingsMap() map[string]string

type MonitorSettingDTO

type MonitorSettingDTO struct {
	Variable string `json:"variable" binding:"Required"`
	Value    string `json:"value"`
}

type MonitorSettingsDTO

type MonitorSettingsDTO []MonitorSettingDTO

func (MonitorSettingsDTO) ToV2Setting

func (s MonitorSettingsDTO) ToV2Setting(t CheckType) map[string]interface{}

type MonitorType

type MonitorType struct {
	Id      int64
	Name    string
	Created time.Time
	Updated time.Time
}

type MonitorTypeDTO

type MonitorTypeDTO struct {
	Id       int64                   `json:"id"`
	Name     string                  `json:"name"`
	Settings []MonitorTypeSettingDTO `json:"settings"`
}

type MonitorTypeSetting

type MonitorTypeSetting struct {
	Id            int64
	MonitorTypeId int64
	Variable      string
	Description   string
	Required      bool
	DataType      string
	DefaultValue  string
	Conditions    map[string]interface{}
}

type MonitorTypeSettingDTO

type MonitorTypeSettingDTO struct {
	Variable     string                 `json:"variable"`
	Description  string                 `json:"description"`
	Required     bool                   `json:"required"`
	DataType     string                 `json:"data_type"`
	Conditions   map[string]interface{} `json:"conditions"`
	DefaultValue string                 `json:"default_value"`
}

type NotFoundError

type NotFoundError struct {
	Msg string
}

func NewNotFoundError

func NewNotFoundError(msg string) NotFoundError

func (NotFoundError) Code

func (e NotFoundError) Code() int

func (NotFoundError) Error

func (e NotFoundError) Error() string

func (NotFoundError) Message

func (e NotFoundError) Message() string

type OrgQuotaDTO

type OrgQuotaDTO struct {
	OrgId  int64  `json:"org_id"`
	Target string `json:"target"`
	Limit  int64  `json:"limit"`
	Used   int64  `json:"used"`
}

type Probe

type Probe struct {
	Id            int64
	OrgId         int64
	Slug          string
	Name          string
	Public        bool
	Latitude      float64
	Longitude     float64
	Created       time.Time
	Updated       time.Time
	Online        bool
	OnlineChange  time.Time
	Enabled       bool
	EnabledChange time.Time
}

func (*Probe) UpdateSlug

func (collector *Probe) UpdateSlug()

type ProbeDTO

type ProbeDTO struct {
	Id            int64     `json:"id" binding:"required"`
	OrgId         int64     `json:"org_id"`
	Slug          string    `json:"slug"`
	Name          string    `json:"name" binding:"required"`
	Tags          []string  `json:"tags"`
	Public        bool      `json:"public"`
	Latitude      float64   `json:"latitude"`
	Longitude     float64   `json:"longitude"`
	Online        bool      `json:"online"`
	OnlineChange  time.Time `json:"online_change"`
	Enabled       bool      `json:"enabled"`
	EnabledChange time.Time `json:"enabled_change"`
	Created       time.Time `json:"created"`
	Updated       time.Time `json:"updated"`
	RemoteIp      []string  `json:"remoteIp"`
}

---------------------- DTO

type ProbeLocationDTO

type ProbeLocationDTO struct {
	Key       string  `json:"key"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	Name      string  `json:"name"`
}

type ProbeReadyPayload

type ProbeReadyPayload struct {
	Collector    *ProbeDTO        `json:"collector"`
	MonitorTypes []MonitorTypeDTO `json:"monitor_types"`
	SocketId     string           `json:"socket_id"`
}

type ProbeSession

type ProbeSession struct {
	Id         int64
	OrgId      int64
	ProbeId    int64
	SocketId   string
	Version    string
	InstanceId string
	RemoteIp   string
	Updated    time.Time
}

type ProbeTag

type ProbeTag struct {
	Id      int64
	OrgId   int64
	ProbeId int64
	Tag     string
	Created time.Time
}

type ProbeUsage

type ProbeUsage struct {
	Total  int64
	PerOrg map[string]int64
}

type Quota

type Quota struct {
	Id      int64
	OrgId   int64
	Target  string
	Limit   int64
	Created time.Time
	Updated time.Time
}

type QuotaScope

type QuotaScope struct {
	Name         string
	Target       string
	DefaultLimit int64
}

func GetQuotaScopes

func GetQuotaScopes(target string) ([]QuotaScope, error)

type RouteByIdIndex

type RouteByIdIndex struct {
	Id      int64
	ProbeId int64
	CheckId int64
	Created time.Time
}

type RouteByTagIndex

type RouteByTagIndex struct {
	Id      int64
	OrgId   int64
	CheckId int64
	Tag     string
	Created time.Time
}

type RouteType

type RouteType string
const (
	RouteByTags RouteType = "byTags"
	RouteByIds  RouteType = "byIds"
)

type SendEmailCommand

type SendEmailCommand struct {
	To       []string
	Template string
	Data     map[string]interface{}
	Massive  bool
	Info     string
}

type SuggestedMonitor

type SuggestedMonitor struct {
	MonitorTypeId int64               `json:"monitor_type_id"`
	Settings      []MonitorSettingDTO `json:"settings"`
}

type UpdateEndpointCommand

type UpdateEndpointCommand struct {
	Id     int64    `json:"id" binding:"Required"`
	OrgId  int64    `json:"-"`
	Name   string   `json:"name" binding:"Required"`
	Tags   []string `json:"tags"`
	Result *EndpointDTO
}

type UpdateMonitorCommand

type UpdateMonitorCommand struct {
	Id             int64                `json:"id" binding:"Required"`
	EndpointId     int64                `json:"endpoint_id" binding:"Required"`
	OrgId          int64                `json:"-"`
	MonitorTypeId  int64                `json:"monitor_type_id" binding:"Required"`
	CollectorIds   []int64              `json:"collector_ids"`
	CollectorTags  []string             `json:"collector_tags"`
	Settings       []MonitorSettingDTO  `json:"settings"`
	HealthSettings *CheckHealthSettings `json:"health_settings"`
	Frequency      int64                `json:"frequency" binding:"Required;Range(10,600)"`
	Enabled        bool                 `json:"enabled"`
	Offset         int64                `json:"-"`
}

type UpdateMonitorStateCommand

type UpdateMonitorStateCommand struct {
	Id       int64
	State    CheckEvalResult
	Updated  time.Time
	Checked  time.Time
	Affected int
}

type Usage

type Usage struct {
	Endpoints EndpointUsage
	Probes    ProbeUsage
	Checks    CheckUsage
}

func NewUsage

func NewUsage() *Usage

type ValidationError

type ValidationError struct {
	Msg string
}

func NewValidationError

func NewValidationError(msg string) ValidationError

func (ValidationError) Code

func (e ValidationError) Code() int

func (ValidationError) Error

func (e ValidationError) Error() string

func (ValidationError) Message

func (e ValidationError) Message() string

Jump to

Keyboard shortcuts

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