2020-03-04 10:29:00 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2020-03-09 18:17:55 +00:00
|
|
|
"github.com/statping/statping/types/null"
|
2020-03-23 02:50:30 +00:00
|
|
|
"github.com/statping/statping/utils"
|
2020-03-04 10:29:00 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-06-15 07:46:27 +00:00
|
|
|
func Example(online bool) *Service {
|
|
|
|
return &Service{
|
|
|
|
Id: 6283,
|
|
|
|
Name: "Statping Example",
|
2020-06-19 09:14:40 +00:00
|
|
|
Domain: "https://statping.com",
|
2020-06-15 07:46:27 +00:00
|
|
|
Expected: null.NewNullString(""),
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
Interval: int(time.Duration(15 * time.Second).Seconds()),
|
|
|
|
Type: "http",
|
|
|
|
Method: "get",
|
|
|
|
PostData: null.NullString{},
|
2020-06-19 09:14:40 +00:00
|
|
|
Port: 443,
|
2020-06-15 07:46:27 +00:00
|
|
|
Timeout: int(time.Duration(2 * time.Second).Seconds()),
|
|
|
|
Order: 0,
|
|
|
|
VerifySSL: null.NewNullBool(true),
|
|
|
|
Public: null.NewNullBool(true),
|
|
|
|
GroupId: 0,
|
|
|
|
TLSCert: null.NullString{},
|
|
|
|
TLSCertKey: null.NullString{},
|
|
|
|
TLSCertRoot: null.NullString{},
|
|
|
|
Headers: null.NullString{},
|
|
|
|
Permalink: null.NewNullString("example-service"),
|
|
|
|
Redirect: null.NewNullBool(true),
|
|
|
|
CreatedAt: utils.Now().Add(-23 * time.Hour),
|
|
|
|
UpdatedAt: utils.Now().Add(-23 * time.Hour),
|
|
|
|
Online: online,
|
|
|
|
Latency: 393443,
|
|
|
|
PingTime: 83526,
|
|
|
|
Online24Hours: 0.98,
|
|
|
|
Online7Days: 0.99,
|
|
|
|
AvgResponse: 303443,
|
|
|
|
FailuresLast24Hours: 2,
|
|
|
|
Checkpoint: time.Time{},
|
|
|
|
SleepDuration: 5 * time.Second,
|
|
|
|
LastResponse: "The example service is hitting this page",
|
|
|
|
NotifyAfter: 0,
|
|
|
|
notifyAfterCount: 0,
|
|
|
|
AllowNotifications: null.NewNullBool(true),
|
|
|
|
UserNotified: false,
|
|
|
|
UpdateNotify: null.NewNullBool(true),
|
2020-06-19 09:14:40 +00:00
|
|
|
DownText: "The service was responding with 500 status code",
|
2020-06-15 07:46:27 +00:00
|
|
|
SuccessNotified: false,
|
|
|
|
LastStatusCode: 200,
|
|
|
|
Failures: nil,
|
|
|
|
AllCheckins: nil,
|
|
|
|
LastLookupTime: 4600,
|
|
|
|
LastLatency: 124399,
|
|
|
|
LastCheck: utils.Now().Add(-37 * time.Second),
|
|
|
|
LastOnline: utils.Now().Add(-37 * time.Second),
|
2020-06-19 09:14:40 +00:00
|
|
|
LastOffline: utils.Now().Add(-75 * time.Second),
|
2020-06-15 07:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 15:15:15 +00:00
|
|
|
func Samples() error {
|
2020-05-26 05:11:32 +00:00
|
|
|
log.Infoln("Inserting Sample Services...")
|
2020-03-23 02:50:30 +00:00
|
|
|
createdOn := utils.Now().Add(((-24 * 30) * 3) * time.Hour)
|
2020-03-04 10:29:00 +00:00
|
|
|
s1 := &Service{
|
|
|
|
Name: "Google",
|
|
|
|
Domain: "https://google.com",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
Interval: 10,
|
|
|
|
Type: "http",
|
|
|
|
Method: "GET",
|
|
|
|
Timeout: 10,
|
|
|
|
Order: 1,
|
|
|
|
GroupId: 1,
|
2020-03-29 01:21:32 +00:00
|
|
|
Public: null.NewNullBool(true),
|
2020-03-04 10:29:00 +00:00
|
|
|
Permalink: null.NewNullString("google"),
|
|
|
|
VerifySSL: null.NewNullBool(true),
|
2020-04-19 11:16:44 +00:00
|
|
|
Redirect: null.NewNullBool(true),
|
2020-03-23 02:50:30 +00:00
|
|
|
NotifyAfter: 3,
|
2020-03-04 10:29:00 +00:00
|
|
|
CreatedAt: createdOn,
|
|
|
|
}
|
2020-03-09 15:15:15 +00:00
|
|
|
if err := s1.Create(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-03-04 14:20:47 +00:00
|
|
|
|
2020-03-04 10:29:00 +00:00
|
|
|
s2 := &Service{
|
|
|
|
Name: "Statping Github",
|
2020-03-09 18:17:55 +00:00
|
|
|
Domain: "https://github.com/statping/statping",
|
2020-03-04 10:29:00 +00:00
|
|
|
ExpectedStatus: 200,
|
|
|
|
Interval: 30,
|
|
|
|
Type: "http",
|
|
|
|
Method: "GET",
|
|
|
|
Timeout: 20,
|
|
|
|
Order: 2,
|
2020-04-07 11:53:32 +00:00
|
|
|
Public: null.NewNullBool(true),
|
2020-03-04 10:29:00 +00:00
|
|
|
Permalink: null.NewNullString("statping_github"),
|
|
|
|
VerifySSL: null.NewNullBool(true),
|
2020-03-23 02:50:30 +00:00
|
|
|
NotifyAfter: 1,
|
2020-03-04 10:29:00 +00:00
|
|
|
CreatedAt: createdOn,
|
|
|
|
}
|
2020-03-09 15:15:15 +00:00
|
|
|
if err := s2.Create(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-03-04 14:20:47 +00:00
|
|
|
|
2020-03-04 10:29:00 +00:00
|
|
|
s3 := &Service{
|
|
|
|
Name: "JSON Users Test",
|
|
|
|
Domain: "https://jsonplaceholder.typicode.com/users",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
Interval: 60,
|
|
|
|
Type: "http",
|
|
|
|
Method: "GET",
|
|
|
|
Timeout: 30,
|
|
|
|
Order: 3,
|
|
|
|
Public: null.NewNullBool(true),
|
|
|
|
VerifySSL: null.NewNullBool(true),
|
|
|
|
GroupId: 2,
|
2020-03-23 02:50:30 +00:00
|
|
|
NotifyAfter: 2,
|
2020-03-04 10:29:00 +00:00
|
|
|
CreatedAt: createdOn,
|
|
|
|
}
|
2020-03-09 15:15:15 +00:00
|
|
|
if err := s3.Create(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-03-04 14:20:47 +00:00
|
|
|
|
2020-03-04 10:29:00 +00:00
|
|
|
s4 := &Service{
|
|
|
|
Name: "JSON API Tester",
|
|
|
|
Domain: "https://jsonplaceholder.typicode.com/posts",
|
|
|
|
ExpectedStatus: 201,
|
|
|
|
Expected: null.NewNullString(`(title)": "((\\"|[statping])*)"`),
|
|
|
|
Interval: 30,
|
|
|
|
Type: "http",
|
|
|
|
Method: "POST",
|
|
|
|
PostData: null.NewNullString(`{ "title": "statping", "body": "bar", "userId": 19999 }`),
|
|
|
|
Timeout: 30,
|
|
|
|
Order: 4,
|
|
|
|
Public: null.NewNullBool(true),
|
|
|
|
VerifySSL: null.NewNullBool(true),
|
2020-04-19 11:16:44 +00:00
|
|
|
Redirect: null.NewNullBool(true),
|
2020-03-04 10:29:00 +00:00
|
|
|
GroupId: 2,
|
2020-03-23 02:50:30 +00:00
|
|
|
NotifyAfter: 3,
|
2020-03-04 10:29:00 +00:00
|
|
|
CreatedAt: createdOn,
|
|
|
|
}
|
2020-03-09 15:15:15 +00:00
|
|
|
if err := s4.Create(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-03-04 14:20:47 +00:00
|
|
|
|
2020-03-04 10:29:00 +00:00
|
|
|
s5 := &Service{
|
|
|
|
Name: "Google DNS",
|
|
|
|
Domain: "8.8.8.8",
|
|
|
|
Interval: 20,
|
|
|
|
Type: "tcp",
|
|
|
|
Port: 53,
|
|
|
|
Timeout: 120,
|
|
|
|
Order: 5,
|
|
|
|
Public: null.NewNullBool(true),
|
|
|
|
GroupId: 1,
|
|
|
|
CreatedAt: createdOn,
|
|
|
|
}
|
2020-03-09 15:15:15 +00:00
|
|
|
if err := s5.Create(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-07 11:53:32 +00:00
|
|
|
s6 := &Service{
|
|
|
|
Name: "Private Service",
|
|
|
|
Domain: "https://push.statping.com",
|
2020-06-13 01:23:30 +00:00
|
|
|
Method: "GET",
|
2020-04-07 11:53:32 +00:00
|
|
|
Interval: 30,
|
|
|
|
Type: "http",
|
|
|
|
Timeout: 120,
|
|
|
|
Order: 6,
|
|
|
|
Public: null.NewNullBool(false),
|
2020-04-19 11:16:44 +00:00
|
|
|
Redirect: null.NewNullBool(true),
|
2020-04-07 11:53:32 +00:00
|
|
|
GroupId: 3,
|
|
|
|
CreatedAt: createdOn,
|
|
|
|
}
|
|
|
|
if err := s6.Create(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-09 15:15:15 +00:00
|
|
|
return nil
|
2020-03-04 10:29:00 +00:00
|
|
|
}
|