mirror of https://github.com/statping/statping
cache updates - api updates
parent
9ffa5674b2
commit
015a9bb869
3
Makefile
3
Makefile
|
@ -18,6 +18,9 @@ PATH:=$(PATH)
|
||||||
# build all arch's and release Statup
|
# build all arch's and release Statup
|
||||||
release: dev-deps build-all
|
release: dev-deps build-all
|
||||||
|
|
||||||
|
# build and push the images to docker hub
|
||||||
|
docker: docker-build-all docker-publish-all
|
||||||
|
|
||||||
# test all versions of Statup, golang testing and then cypress UI testing
|
# test all versions of Statup, golang testing and then cypress UI testing
|
||||||
test-all: dev-deps test
|
test-all: dev-deps test
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ type failure struct {
|
||||||
func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error) {
|
func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error) {
|
||||||
f := fail.(*failure)
|
f := fail.(*failure)
|
||||||
f.Service = s.Id
|
f.Service = s.Id
|
||||||
s.Failures = append(s.Failures, f)
|
s.Failures = append(s.Failures, f.Select())
|
||||||
row := failuresDB().Create(f)
|
row := failuresDB().Create(f)
|
||||||
if row.Error != nil {
|
if row.Error != nil {
|
||||||
utils.Log(3, row.Error)
|
utils.Log(3, row.Error)
|
||||||
|
@ -51,7 +51,7 @@ func (s *Service) AllFailures() []*failure {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, f := range fails {
|
for _, f := range fails {
|
||||||
s.Failures = append(s.Failures, f)
|
s.Failures = append(s.Failures, f.Select())
|
||||||
}
|
}
|
||||||
return fails
|
return fails
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,7 @@ func (s *Service) DeleteFailures() {
|
||||||
// LimitedFailures will return the last amount of failures from a service
|
// LimitedFailures will return the last amount of failures from a service
|
||||||
func (s *Service) LimitedFailures(amount int64) []*failure {
|
func (s *Service) LimitedFailures(amount int64) []*failure {
|
||||||
var failArr []*failure
|
var failArr []*failure
|
||||||
col := failuresDB().Where("service = ?", s.Id).Order("id asc").Limit(amount)
|
failuresDB().Where("service = ?", s.Id).Order("id asc").Limit(amount).Find(&failArr)
|
||||||
col.Find(&failArr)
|
|
||||||
return failArr
|
return failArr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,20 @@ func (s *Service) LimitedCheckins() []*Checkin {
|
||||||
return checkin
|
return checkin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SelectServices() []*Service {
|
||||||
|
var services []*Service
|
||||||
|
servicesDB().Find(&services).Order("order_id desc")
|
||||||
|
for _, service := range services {
|
||||||
|
failures := service.LimitedFailures(100)
|
||||||
|
service.Failures = nil
|
||||||
|
for _, fail := range failures {
|
||||||
|
utils.Log(1, fail)
|
||||||
|
service.Failures = append(service.Failures, fail.Select())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return services
|
||||||
|
}
|
||||||
|
|
||||||
// SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup.
|
// SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup.
|
||||||
func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
|
func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
|
||||||
var services []*Service
|
var services []*Service
|
||||||
|
@ -95,7 +109,7 @@ func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
|
||||||
failures := service.LimitedFailures(100)
|
failures := service.LimitedFailures(100)
|
||||||
service.Failures = nil
|
service.Failures = nil
|
||||||
for _, fail := range failures {
|
for _, fail := range failures {
|
||||||
service.Failures = append(service.Failures, fail)
|
service.Failures = append(service.Failures, fail.Select())
|
||||||
}
|
}
|
||||||
CoreApp.Services = append(CoreApp.Services, service)
|
CoreApp.Services = append(CoreApp.Services, service)
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,12 +214,7 @@ func apiAllServicesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
allServices := core.CoreApp.Services
|
services := core.SelectServices()
|
||||||
var services []types.ServiceInterface
|
|
||||||
for _, s := range allServices {
|
|
||||||
service := s.Select()
|
|
||||||
services = append(services, core.ReturnService(service))
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(services)
|
json.NewEncoder(w).Encode(services)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,33 +21,33 @@ import (
|
||||||
|
|
||||||
// Service is the main struct for Services
|
// Service is the main struct for Services
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
||||||
Name string `gorm:"column:name" json:"name"`
|
Name string `gorm:"column:name" json:"name"`
|
||||||
Domain string `gorm:"column:domain" json:"domain"`
|
Domain string `gorm:"column:domain" json:"domain"`
|
||||||
Expected NullString `gorm:"column:expected" json:"expected"`
|
Expected NullString `gorm:"column:expected" json:"expected"`
|
||||||
ExpectedStatus int `gorm:"default:200;column:expected_status" json:"expected_status"`
|
ExpectedStatus int `gorm:"default:200;column:expected_status" json:"expected_status"`
|
||||||
Interval int `gorm:"default:30;column:check_interval" json:"check_interval"`
|
Interval int `gorm:"default:30;column:check_interval" json:"check_interval"`
|
||||||
Type string `gorm:"column:check_type" json:"type"`
|
Type string `gorm:"column:check_type" json:"type"`
|
||||||
Method string `gorm:"column:method" json:"method"`
|
Method string `gorm:"column:method" json:"method"`
|
||||||
PostData NullString `gorm:"column:post_data" json:"post_data"`
|
PostData NullString `gorm:"column:post_data" json:"post_data"`
|
||||||
Port int `gorm:"not null;column:port" json:"port"`
|
Port int `gorm:"not null;column:port" json:"port"`
|
||||||
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
|
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
|
||||||
Order int `gorm:"default:0;column:order_id" json:"order_id"`
|
Order int `gorm:"default:0;column:order_id" json:"order_id"`
|
||||||
AllowNotifications NullBool `gorm:"default:false;column:allow_notifications" json:"allow_notifications"`
|
AllowNotifications NullBool `gorm:"default:false;column:allow_notifications" json:"allow_notifications"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||||
Online bool `gorm:"-" json:"online"`
|
Online bool `gorm:"-" json:"online"`
|
||||||
Latency float64 `gorm:"-" json:"latency"`
|
Latency float64 `gorm:"-" json:"latency"`
|
||||||
PingTime float64 `gorm:"-" json:"ping_time"`
|
PingTime float64 `gorm:"-" json:"ping_time"`
|
||||||
Online24Hours float32 `gorm:"-" json:"online_24_hours"`
|
Online24Hours float32 `gorm:"-" json:"online_24_hours"`
|
||||||
AvgResponse string `gorm:"-" json:"avg_response"`
|
AvgResponse string `gorm:"-" json:"avg_response"`
|
||||||
Running chan bool `gorm:"-" json:"-"`
|
Running chan bool `gorm:"-" json:"-"`
|
||||||
Checkpoint time.Time `gorm:"-" json:"-"`
|
Checkpoint time.Time `gorm:"-" json:"-"`
|
||||||
SleepDuration time.Duration `gorm:"-" json:"-"`
|
SleepDuration time.Duration `gorm:"-" json:"-"`
|
||||||
LastResponse string `gorm:"-" json:"-"`
|
LastResponse string `gorm:"-" json:"-"`
|
||||||
LastStatusCode int `gorm:"-" json:"status_code"`
|
LastStatusCode int `gorm:"-" json:"status_code"`
|
||||||
LastOnline time.Time `gorm:"-" json:"last_online"`
|
LastOnline time.Time `gorm:"-" json:"last_online"`
|
||||||
Failures []FailureInterface `gorm:"-" json:"failures,omitempty"`
|
Failures []*Failure `gorm:"-" json:"failures,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceInterface interface {
|
type ServiceInterface interface {
|
||||||
|
|
Loading…
Reference in New Issue