mirror of https://github.com/statping/statping
delete incidents and checkins when service is deleted
parent
848c46c3c3
commit
86d6a5a727
|
@ -11,6 +11,7 @@
|
||||||
- Modified node version from 10.x to 12.18.2
|
- Modified node version from 10.x to 12.18.2
|
||||||
- Modified Notifier's struct values to be NullString and NullInt to allow empty values
|
- Modified Notifier's struct values to be NullString and NullInt to allow empty values
|
||||||
- Added Search ability to Logs in UI
|
- Added Search ability to Logs in UI
|
||||||
|
- Fixed issue with Incidents and Checkins not being deleted once service is deleted
|
||||||
|
|
||||||
# 0.90.60 (07-15-2020)
|
# 0.90.60 (07-15-2020)
|
||||||
- Added LETSENCRYPT_ENABLE (boolean) env to enable/disable letsencrypt SSL
|
- Added LETSENCRYPT_ENABLE (boolean) env to enable/disable letsencrypt SSL
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommandNotifier(t *testing.T) {
|
func TestCommandNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
|
@ -19,6 +19,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiscordNotifier(t *testing.T) {
|
func TestDiscordNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
DISCORD_URL = utils.Params.GetString("DISCORD_URL")
|
DISCORD_URL = utils.Params.GetString("DISCORD_URL")
|
||||||
|
|
|
@ -24,6 +24,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEmailNotifier(t *testing.T) {
|
func TestEmailNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGotifyNotifier(t *testing.T) {
|
func TestGotifyNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
GOTIFY_URL = utils.Params.GetString("GOTIFY_URL")
|
GOTIFY_URL = utils.Params.GetString("GOTIFY_URL")
|
||||||
|
|
|
@ -19,6 +19,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMobileNotifier(t *testing.T) {
|
func TestMobileNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReplaceTemplate(t *testing.T) {
|
func TestReplaceTemplate(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
temp := `{"id":{{.Service.Id}},"name":"{{.Service.Name}}"}`
|
temp := `{"id":{{.Service.Id}},"name":"{{.Service.Name}}"}`
|
||||||
replaced := ReplaceTemplate(temp, replacer{Service: services.Example(true)})
|
replaced := ReplaceTemplate(temp, replacer{Service: services.Example(true)})
|
||||||
assert.Equal(t, `{"id":6283,"name":"Statping Example"}`, replaced)
|
assert.Equal(t, `{"id":6283,"name":"Statping Example"}`, replaced)
|
||||||
|
|
|
@ -19,6 +19,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPushoverNotifier(t *testing.T) {
|
func TestPushoverNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSlackNotifier(t *testing.T) {
|
func TestSlackNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
|
|
|
@ -19,6 +19,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStatpingEmailerNotifier(t *testing.T) {
|
func TestStatpingEmailerNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
|
|
|
@ -20,6 +20,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTelegramNotifier(t *testing.T) {
|
func TestTelegramNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
telegramToken = utils.Params.GetString("TELEGRAM_TOKEN")
|
||||||
|
telegramChannel = utils.Params.GetString("TELEGRAM_CHANNEL")
|
||||||
if telegramToken == "" || telegramChannel == "" {
|
if telegramToken == "" || telegramChannel == "" {
|
||||||
t.Log("Telegram notifier testing skipped, missing TELEGRAM_TOKEN and TELEGRAM_CHANNEL environment variable")
|
t.Log("Telegram notifier testing skipped, missing TELEGRAM_TOKEN and TELEGRAM_CHANNEL environment variable")
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
|
@ -28,8 +32,6 @@ func TestTelegramNotifier(t *testing.T) {
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
telegramToken = utils.Params.GetString("TELEGRAM_TOKEN")
|
|
||||||
telegramChannel = utils.Params.GetString("TELEGRAM_CHANNEL")
|
|
||||||
Telegram.ApiSecret = null.NewNullString(telegramToken)
|
Telegram.ApiSecret = null.NewNullString(telegramToken)
|
||||||
Telegram.Var1 = null.NewNullString(telegramChannel)
|
Telegram.Var1 = null.NewNullString(telegramChannel)
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTwilioNotifier(t *testing.T) {
|
func TestTwilioNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWebhookNotifier(t *testing.T) {
|
func TestWebhookNotifier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
err := utils.InitLogs()
|
err := utils.InitLogs()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
|
@ -87,5 +87,10 @@ func (i *Incident) Update() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Incident) Delete() error {
|
func (i *Incident) Delete() error {
|
||||||
|
for _, u := range i.Updates() {
|
||||||
|
if err := u.Delete(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return db.Delete(i).Error()
|
return db.Delete(i).Error()
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,9 @@ func (s *Service) Delete() error {
|
||||||
if err := s.DeleteCheckins(); err != nil {
|
if err := s.DeleteCheckins(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := s.DeleteIncidents(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
delete(allServices, s.Id)
|
delete(allServices, s.Id)
|
||||||
q := db.Model(&Service{}).Delete(s)
|
q := db.Model(&Service{}).Delete(s)
|
||||||
return q.Error()
|
return q.Error()
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/statping/statping/types/incidents"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Service) Incidents() []*incidents.Incident {
|
||||||
|
var i []*incidents.Incident
|
||||||
|
db.Where("service = ?", s.Id).Find(&i)
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) DeleteIncidents() error {
|
||||||
|
for _, i := range s.Incidents() {
|
||||||
|
if err := i.Delete(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/statping/statping/types/checkins"
|
"github.com/statping/statping/types/checkins"
|
||||||
"github.com/statping/statping/types/failures"
|
"github.com/statping/statping/types/failures"
|
||||||
"github.com/statping/statping/types/hits"
|
"github.com/statping/statping/types/hits"
|
||||||
|
"github.com/statping/statping/types/incidents"
|
||||||
"github.com/statping/statping/types/null"
|
"github.com/statping/statping/types/null"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -83,6 +84,20 @@ var fail2 = &failures.Failure{
|
||||||
CreatedAt: utils.Now().Add(-5 * time.Second),
|
CreatedAt: utils.Now().Add(-5 * time.Second),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var incident1 = &incidents.Incident{
|
||||||
|
Title: "Theres something going on",
|
||||||
|
Description: "this is an example",
|
||||||
|
ServiceId: 1,
|
||||||
|
CreatedAt: utils.Now().Add(-30 * time.Second),
|
||||||
|
}
|
||||||
|
|
||||||
|
var incidentUpdate1 = &incidents.IncidentUpdate{
|
||||||
|
IncidentId: 1,
|
||||||
|
Message: "This is an update",
|
||||||
|
Type: "pending",
|
||||||
|
CreatedAt: utils.Now().Add(-5 * time.Second),
|
||||||
|
}
|
||||||
|
|
||||||
type exampleGRPC struct {
|
type exampleGRPC struct {
|
||||||
pb.UnimplementedRouteGuideServer
|
pb.UnimplementedRouteGuideServer
|
||||||
}
|
}
|
||||||
|
@ -168,9 +183,10 @@ func TestServices(t *testing.T) {
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db, err := database.OpenTester()
|
db, err := database.OpenTester()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
db.AutoMigrate(&Service{}, &hits.Hit{}, &checkins.Checkin{}, &checkins.CheckinHit{}, &failures.Failure{})
|
db.AutoMigrate(&Service{}, &hits.Hit{}, &checkins.Checkin{}, &checkins.CheckinHit{}, &failures.Failure{}, &incidents.Incident{}, &incidents.IncidentUpdate{})
|
||||||
checkins.SetDB(db)
|
checkins.SetDB(db)
|
||||||
failures.SetDB(db)
|
failures.SetDB(db)
|
||||||
|
incidents.SetDB(db)
|
||||||
hits.SetDB(db)
|
hits.SetDB(db)
|
||||||
SetDB(db)
|
SetDB(db)
|
||||||
|
|
||||||
|
@ -181,6 +197,8 @@ func TestServices(t *testing.T) {
|
||||||
db.Create(&exmapleCheckin)
|
db.Create(&exmapleCheckin)
|
||||||
db.Create(&fail1)
|
db.Create(&fail1)
|
||||||
db.Create(&fail2)
|
db.Create(&fail2)
|
||||||
|
db.Create(&incident1)
|
||||||
|
db.Create(&incidentUpdate1)
|
||||||
|
|
||||||
tlsCert := utils.Params.GetString("STATPING_DIR") + "/cert.pem"
|
tlsCert := utils.Params.GetString("STATPING_DIR") + "/cert.pem"
|
||||||
tlsCertKey := utils.Params.GetString("STATPING_DIR") + "/key.pem"
|
tlsCertKey := utils.Params.GetString("STATPING_DIR") + "/key.pem"
|
||||||
|
@ -499,6 +517,22 @@ func TestServices(t *testing.T) {
|
||||||
err = item.Delete()
|
err = item.Delete()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
checkin := item.Checkins()
|
||||||
|
assert.Len(t, checkin, 0)
|
||||||
|
for _, c := range checkin {
|
||||||
|
assert.Len(t, c.Failures().List(), 0)
|
||||||
|
assert.Len(t, c.Hits(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Len(t, item.AllFailures().List(), 0)
|
||||||
|
assert.Len(t, item.AllHits().List(), 0)
|
||||||
|
|
||||||
|
inc := item.Incidents()
|
||||||
|
assert.Len(t, inc, 0)
|
||||||
|
for _, i := range inc {
|
||||||
|
assert.Len(t, i.Updates(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
all = All()
|
all = All()
|
||||||
assert.Len(t, all, 1)
|
assert.Len(t, all, 1)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue