services

package
v0.0.0-...-39e0c7e Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNotifier

func AddNotifier(n ServiceNotifier)

func All

func All() map[int64]*Service

func AllNotifiers

func AllNotifiers() map[string]ServiceNotifier

func CheckServices

func CheckServices()

checkServices will start the checking go routine for each service

func CheckinProcess

func CheckinProcess(s *Service)

CheckinProcess runs the checkin routine for each checkin attached to service

func FindNotifier

func FindNotifier(method string) *notifications.Notification

func LoadServicesYaml

func LoadServicesYaml() (*yamlFile, error)

LoadServicesYaml will attempt to load the 'services.yml' file for Service Auto Creation on startup.

func RecordFailure

func RecordFailure(s *Service, issue, reason string)

RecordFailure will create a new 'Failure' record in the database for a offline service

func RecordSuccess

func RecordSuccess(s *Service)

RecordSuccess will create a new 'hit' record in the database for a successful/online service

func Samples

func Samples() error

func SelectAllServices

func SelectAllServices(start bool) (map[int64]*Service, error)

SelectAllServices returns a slice of *core.Service to be store on []*core.Services should only be called once on startup.

func ServiceCheckQueue

func ServiceCheckQueue(s *Service, record bool)

CheckQueue is the main go routine for checking a service

func Services

func Services() map[int64]*Service

func SetDB

func SetDB(database database.Database)

func UpdateNotifiers

func UpdateNotifiers()

Types

type ByTime

type ByTime []ser

func (ByTime) Len

func (a ByTime) Len() int

func (ByTime) Less

func (a ByTime) Less(i, j int) bool

func (ByTime) Swap

func (a ByTime) Swap(i, j int)

type Service

type Service struct {
	Id                     int64                 `gorm:"primary_key;column:id" json:"id" yaml:"id"`
	Name                   string                `gorm:"column:name" json:"name" yaml:"name"`
	Domain                 string                `gorm:"column:domain" json:"domain" yaml:"domain" private:"true" scope:"user,admin"`
	ExpectedHeadersNegated bool                  `` /* 132-byte string literal not displayed */
	ExpectedHeaders        null.NullString       `gorm:"size:1000;column:expected_headers" json:"expected_headers" scope:"user,admin" yaml:"expected_headers"`
	ExpectedNegated        bool                  `gorm:"default:false;column:negate_expected" json:"negate_expected" yaml:"negate_expected" scope:"user,admin"`
	Expected               null.NullString       `gorm:"size:10000;column:expected" json:"expected" yaml:"expected" scope:"user,admin"`
	ExpectedStatus         int                   `gorm:"default:200;column:expected_status" json:"expected_status" yaml:"expected_status" scope:"user,admin"`
	Interval               int                   `gorm:"default:30;column:check_interval" json:"check_interval" yaml:"check_interval"`
	Type                   string                `gorm:"column:check_type" json:"type" scope:"user,admin" yaml:"type"`
	Method                 string                `gorm:"column:method" json:"method" scope:"user,admin" yaml:"method"`
	PostData               null.NullString       `gorm:"column:post_data" json:"post_data" scope:"user,admin" yaml:"post_data"`
	Port                   int                   `gorm:"not null;column:port" json:"port" scope:"user,admin" yaml:"port"`
	Timeout                int                   `gorm:"default:30;column:timeout" json:"timeout" scope:"user,admin" yaml:"timeout"`
	Order                  int                   `gorm:"default:0;column:order_id" json:"order_id" yaml:"order_id"`
	VerifySSL              null.NullBool         `gorm:"default:false;column:verify_ssl" json:"verify_ssl" scope:"user,admin" yaml:"verify_ssl"`
	GrpcHealthCheck        null.NullBool         `gorm:"default:false;column:grpc_health_check" json:"grpc_health_check" scope:"user,admin" yaml:"grpc_health_check"`
	Public                 null.NullBool         `gorm:"default:true;column:public" json:"public" yaml:"public"`
	GroupId                int                   `gorm:"default:0;column:group_id" json:"group_id" yaml:"group_id"`
	TLSCert                null.NullString       `gorm:"column:tls_cert" json:"tls_cert" scope:"user,admin" yaml:"tls_cert"`
	TLSCertKey             null.NullString       `gorm:"column:tls_cert_key" json:"tls_cert_key" scope:"user,admin" yaml:"tls_cert_key"`
	TLSCertRoot            null.NullString       `gorm:"column:tls_cert_root" json:"tls_cert_root" scope:"user,admin" yaml:"tls_cert_root"`
	Headers                null.NullString       `gorm:"size:1000;column:headers" json:"headers" scope:"user,admin" yaml:"headers"`
	Permalink              null.NullString       `gorm:"column:permalink" json:"permalink" yaml:"permalink"`
	Redirect               null.NullBool         `gorm:"default:false;column:redirect" json:"redirect" scope:"user,admin" yaml:"redirect"`
	CreatedAt              time.Time             `gorm:"column:created_at" json:"created_at" yaml:"-"`
	UpdatedAt              time.Time             `gorm:"column:updated_at" json:"updated_at" yaml:"-"`
	Online                 bool                  `gorm:"-" json:"online" yaml:"-"`
	Latency                int64                 `gorm:"-" json:"latency" yaml:"-"`
	PingTime               int64                 `gorm:"-" json:"ping_time" yaml:"-"`
	Online24Hours          float32               `gorm:"-" json:"online_24_hours" yaml:"-"`
	Online7Days            float32               `gorm:"-" json:"online_7_days" yaml:"-"`
	AvgResponse            int64                 `gorm:"-" json:"avg_response" yaml:"-"`
	FailuresLast24Hours    int                   `gorm:"-" json:"failures_24_hours" yaml:"-"`
	Running                chan bool             `gorm:"-" json:"-" yaml:"-"`
	Checkpoint             time.Time             `gorm:"-" json:"-" yaml:"-"`
	SleepDuration          time.Duration         `gorm:"-" json:"-" yaml:"-"`
	LastResponse           string                `gorm:"-" json:"-" yaml:"-"`
	NotifyAfter            int64                 `gorm:"column:notify_after" json:"notify_after" yaml:"notify_after" scope:"user,admin"`
	AllowNotifications     null.NullBool         `gorm:"default:true;column:allow_notifications" json:"allow_notifications" yaml:"allow_notifications" scope:"user,admin"`
	UpdateNotify           null.NullBool         `gorm:"default:true;column:notify_all_changes" json:"notify_all_changes" yaml:"notify_all_changes" scope:"user,admin"` // This Variable is a simple copy of `core.CoreApp.UpdateNotify.Bool`
	DownText               string                `gorm:"-" json:"-" yaml:"-"`                                                                                           // Contains the current generated Downtime Text 	// Is 'true' if the user has already be informed that the Services now again available // Is 'true' if the user has already be informed that the Services now again available
	LastStatusCode         int                   `gorm:"-" json:"status_code" yaml:"-"`
	LastLookupTime         int64                 `gorm:"-" json:"-" yaml:"-"`
	LastLatency            int64                 `gorm:"-" json:"-" yaml:"-"`
	LastCheck              time.Time             `gorm:"-" json:"-" yaml:"-"`
	LastOnline             time.Time             `gorm:"-" json:"last_success" yaml:"-"`
	LastOffline            time.Time             `gorm:"-" json:"last_error" yaml:"-"`
	Stats                  *Stats                `gorm:"-" json:"stats,omitempty" yaml:"-"`
	Messages               []*messages.Message   `gorm:"foreignkey:service;association_foreignkey:id" json:"messages,omitempty" yaml:"messages"`
	Incidents              []*incidents.Incident `gorm:"foreignkey:service;association_foreignkey:id" json:"incidents,omitempty" yaml:"incidents"`
	Checkins               []*checkins.Checkin   `gorm:"foreignkey:service;association_foreignkey:id" json:"checkins,omitempty" yaml:"-" scope:"user,admin"`
	Failures               []*failures.Failure   `gorm:"-" json:"failures,omitempty" yaml:"-" scope:"user,admin"`
	// contains filtered or unexported fields
}

Service is the main struct for Services

func AllInOrder

func AllInOrder() []Service

func CheckGrpc

func CheckGrpc(s *Service, record bool) (*Service, error)

CheckGrpc will check a gRPC service

func CheckHttp

func CheckHttp(s *Service, record bool) (*Service, error)

checkHttp will check a HTTP service

func CheckIcmp

func CheckIcmp(s *Service, record bool) (*Service, error)

checkIcmp will send a ICMP ping packet to the service

func CheckTcp

func CheckTcp(s *Service, record bool) (*Service, error)

checkTcp will check a TCP service

func Example

func Example(online bool) Service

func Find

func Find(id int64) (*Service, error)

func (*Service) AfterCreate

func (s *Service) AfterCreate() error

func (*Service) AfterDelete

func (s *Service) AfterDelete()

func (*Service) AfterFind

func (s *Service) AfterFind()

func (*Service) AfterUpdate

func (s *Service) AfterUpdate()

func (*Service) AllFailures

func (s *Service) AllFailures() failures.Failurer

func (*Service) AllHits

func (s *Service) AllHits() hits.Hitters

func (Service) AvgTime

func (s Service) AvgTime() int64

AvgTime will return the average amount of time for a service to response back successfully

func (*Service) BeforeCreate

func (s *Service) BeforeCreate() error

func (*Service) BeforeUpdate

func (s *Service) BeforeUpdate() error

func (*Service) CheckService

func (s *Service) CheckService(record bool)

Check will run checkHttp for HTTP services and checkTcp for TCP services if record param is set to true, it will add a record into the database.

func (*Service) Close

func (s *Service) Close()

Close will stop the go routine that is checking if service is online or not

func (*Service) Create

func (s *Service) Create() error

func (*Service) Delete

func (s *Service) Delete() error

func (*Service) DeleteCheckins

func (s *Service) DeleteCheckins() error

func (*Service) DeleteIncidents

func (s *Service) DeleteIncidents() error

func (*Service) DeleteMessages

func (s *Service) DeleteMessages() error

func (Service) Downtime

func (s Service) Downtime() utils.Duration

Downtime returns the duration of how long the service has been offline

func (Service) DowntimeText

func (s Service) DowntimeText() string

func (Service) Duration

func (s Service) Duration() time.Duration

func (*Service) FailuresColumnID

func (s *Service) FailuresColumnID() (string, int64)

func (*Service) FailuresSince

func (s *Service) FailuresSince(t time.Time) failures.Failurer

func (*Service) FirstHit

func (s *Service) FirstHit() *hits.Hit

func (Service) Hash

func (s Service) Hash() string

func (*Service) HitsColumnID

func (s *Service) HitsColumnID() (string, int64)

func (*Service) HitsSince

func (s *Service) HitsSince(t time.Time) hits.Hitters

func (*Service) IsRunning

func (s *Service) IsRunning() bool

IsRunning returns true if the service go routine is running

func (*Service) LastHit

func (s *Service) LastHit() *hits.Hit

func (*Service) LoadTLSCert

func (s *Service) LoadTLSCert() (*tls.Config, error)

func (Service) OnlineDaysPercent

func (s Service) OnlineDaysPercent(days int) float32

OnlineDaysPercent returns the service's uptime percent within last 24 hours

func (*Service) OnlineSince

func (s *Service) OnlineSince(ago time.Time) float32

OnlineSince accepts a time since parameter to return the percent of a service's uptime.

func (*Service) Start

func (s *Service) Start()

Start will create a channel for the service checking go routine

func (*Service) Update

func (s *Service) Update() error

func (*Service) UpdateStats

func (s *Service) UpdateStats() *Service

func (Service) Uptime

func (s Service) Uptime() utils.Duration

Uptime returns the duration of how long the service was online

func (Service) UptimeData

func (s Service) UptimeData(hits []*hits.Hit, fails []*failures.Failure) (*UptimeSeries, error)

Start will create a channel for the service checking go routine

func (*Service) Validate

func (s *Service) Validate() error

type ServiceNotifier

type ServiceNotifier interface {
	OnSuccess(Service) (string, error)                   // OnSuccess is triggered when a service is successful
	OnFailure(Service, failures.Failure) (string, error) // OnFailure is triggered when a service is failing
	OnTest() (string, error)                             // OnTest is triggered for testing
	OnSave() (string, error)                             // OnSave is triggered for testing
	Select() *notifications.Notification                 // OnTest is triggered for testing
	Valid(notifications.Values) error                    // Valid checks your form values
}

func ReturnNotifier

func ReturnNotifier(method string) ServiceNotifier

type ServiceOrder

type ServiceOrder []Service

ServiceOrder will reorder the services based on 'order_id' (Order)

func (ServiceOrder) Len

func (c ServiceOrder) Len() int

Sort interface for resroting the Services in order

func (ServiceOrder) Less

func (c ServiceOrder) Less(i, j int) bool

func (ServiceOrder) Swap

func (c ServiceOrder) Swap(i, j int)

type Stats

type Stats struct {
	Failures int       `gorm:"-" json:"failures"`
	Hits     int       `gorm:"-" json:"hits"`
	FirstHit time.Time `gorm:"-" json:"first_hit"`
}

type UptimeSeries

type UptimeSeries struct {
	Start    time.Time `json:"start"`
	End      time.Time `json:"end"`
	Uptime   int64     `json:"uptime"`
	Downtime int64     `json:"downtime"`
	Series   []series  `json:"series"`
}

Jump to

Keyboard shortcuts

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