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
|
||||
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: dev-deps test
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ type failure struct {
|
|||
func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error) {
|
||||
f := fail.(*failure)
|
||||
f.Service = s.Id
|
||||
s.Failures = append(s.Failures, f)
|
||||
s.Failures = append(s.Failures, f.Select())
|
||||
row := failuresDB().Create(f)
|
||||
if row.Error != nil {
|
||||
utils.Log(3, row.Error)
|
||||
|
@ -51,7 +51,7 @@ func (s *Service) AllFailures() []*failure {
|
|||
return nil
|
||||
}
|
||||
for _, f := range fails {
|
||||
s.Failures = append(s.Failures, f)
|
||||
s.Failures = append(s.Failures, f.Select())
|
||||
}
|
||||
return fails
|
||||
}
|
||||
|
@ -68,8 +68,7 @@ func (s *Service) DeleteFailures() {
|
|||
// LimitedFailures will return the last amount of failures from a service
|
||||
func (s *Service) LimitedFailures(amount int64) []*failure {
|
||||
var failArr []*failure
|
||||
col := failuresDB().Where("service = ?", s.Id).Order("id asc").Limit(amount)
|
||||
col.Find(&failArr)
|
||||
failuresDB().Where("service = ?", s.Id).Order("id asc").Limit(amount).Find(&failArr)
|
||||
return failArr
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,20 @@ func (s *Service) LimitedCheckins() []*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.
|
||||
func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
|
||||
var services []*Service
|
||||
|
@ -95,7 +109,7 @@ func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
|
|||
failures := service.LimitedFailures(100)
|
||||
service.Failures = nil
|
||||
for _, fail := range failures {
|
||||
service.Failures = append(service.Failures, fail)
|
||||
service.Failures = append(service.Failures, fail.Select())
|
||||
}
|
||||
CoreApp.Services = append(CoreApp.Services, service)
|
||||
}
|
||||
|
|
|
@ -214,12 +214,7 @@ func apiAllServicesHandler(w http.ResponseWriter, r *http.Request) {
|
|||
sendUnauthorizedJson(w, r)
|
||||
return
|
||||
}
|
||||
allServices := core.CoreApp.Services
|
||||
var services []types.ServiceInterface
|
||||
for _, s := range allServices {
|
||||
service := s.Select()
|
||||
services = append(services, core.ReturnService(service))
|
||||
}
|
||||
services := core.SelectServices()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(services)
|
||||
}
|
||||
|
|
|
@ -21,33 +21,33 @@ import (
|
|||
|
||||
// Service is the main struct for Services
|
||||
type Service struct {
|
||||
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Domain string `gorm:"column:domain" json:"domain"`
|
||||
Expected NullString `gorm:"column:expected" json:"expected"`
|
||||
ExpectedStatus int `gorm:"default:200;column:expected_status" json:"expected_status"`
|
||||
Interval int `gorm:"default:30;column:check_interval" json:"check_interval"`
|
||||
Type string `gorm:"column:check_type" json:"type"`
|
||||
Method string `gorm:"column:method" json:"method"`
|
||||
PostData NullString `gorm:"column:post_data" json:"post_data"`
|
||||
Port int `gorm:"not null;column:port" json:"port"`
|
||||
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
|
||||
Order int `gorm:"default:0;column:order_id" json:"order_id"`
|
||||
AllowNotifications NullBool `gorm:"default:false;column:allow_notifications" json:"allow_notifications"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
Online bool `gorm:"-" json:"online"`
|
||||
Latency float64 `gorm:"-" json:"latency"`
|
||||
PingTime float64 `gorm:"-" json:"ping_time"`
|
||||
Online24Hours float32 `gorm:"-" json:"online_24_hours"`
|
||||
AvgResponse string `gorm:"-" json:"avg_response"`
|
||||
Running chan bool `gorm:"-" json:"-"`
|
||||
Checkpoint time.Time `gorm:"-" json:"-"`
|
||||
SleepDuration time.Duration `gorm:"-" json:"-"`
|
||||
LastResponse string `gorm:"-" json:"-"`
|
||||
LastStatusCode int `gorm:"-" json:"status_code"`
|
||||
LastOnline time.Time `gorm:"-" json:"last_online"`
|
||||
Failures []FailureInterface `gorm:"-" json:"failures,omitempty"`
|
||||
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Domain string `gorm:"column:domain" json:"domain"`
|
||||
Expected NullString `gorm:"column:expected" json:"expected"`
|
||||
ExpectedStatus int `gorm:"default:200;column:expected_status" json:"expected_status"`
|
||||
Interval int `gorm:"default:30;column:check_interval" json:"check_interval"`
|
||||
Type string `gorm:"column:check_type" json:"type"`
|
||||
Method string `gorm:"column:method" json:"method"`
|
||||
PostData NullString `gorm:"column:post_data" json:"post_data"`
|
||||
Port int `gorm:"not null;column:port" json:"port"`
|
||||
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
|
||||
Order int `gorm:"default:0;column:order_id" json:"order_id"`
|
||||
AllowNotifications NullBool `gorm:"default:false;column:allow_notifications" json:"allow_notifications"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
Online bool `gorm:"-" json:"online"`
|
||||
Latency float64 `gorm:"-" json:"latency"`
|
||||
PingTime float64 `gorm:"-" json:"ping_time"`
|
||||
Online24Hours float32 `gorm:"-" json:"online_24_hours"`
|
||||
AvgResponse string `gorm:"-" json:"avg_response"`
|
||||
Running chan bool `gorm:"-" json:"-"`
|
||||
Checkpoint time.Time `gorm:"-" json:"-"`
|
||||
SleepDuration time.Duration `gorm:"-" json:"-"`
|
||||
LastResponse string `gorm:"-" json:"-"`
|
||||
LastStatusCode int `gorm:"-" json:"status_code"`
|
||||
LastOnline time.Time `gorm:"-" json:"last_online"`
|
||||
Failures []*Failure `gorm:"-" json:"failures,omitempty"`
|
||||
}
|
||||
|
||||
type ServiceInterface interface {
|
||||
|
|
Loading…
Reference in New Issue