statping/core/setup.go

103 lines
2.0 KiB
Go
Raw Normal View History

2018-06-30 00:57:05 +00:00
package core
import (
2018-07-02 06:21:41 +00:00
"github.com/hunterlong/statup/types"
2018-06-30 00:57:05 +00:00
"github.com/hunterlong/statup/utils"
"os"
)
func InsertDefaultComms() {
2018-07-02 06:21:41 +00:00
emailer := SelectCommunication(1)
if emailer == nil {
emailer := &types.Communication{
Method: "email",
Removable: false,
Enabled: false,
}
Create(emailer)
2018-06-30 00:57:05 +00:00
}
2018-07-02 06:21:41 +00:00
slack := SelectCommunication(2)
if slack == nil {
slack := &types.Communication{
Method: "slack",
Removable: false,
Enabled: false,
}
Create(slack)
}
2018-06-30 00:57:05 +00:00
}
func DeleteConfig() {
err := os.Remove("./config.yml")
if err != nil {
utils.Log(3, err)
}
}
type ErrorResponse struct {
Error string
}
func LoadSampleData() error {
utils.Log(1, "Inserting Sample Data...")
2018-06-30 00:57:05 +00:00
s1 := &Service{
Name: "Google",
Domain: "https://google.com",
ExpectedStatus: 200,
Interval: 10,
Port: 0,
Type: "http",
2018-06-30 00:57:05 +00:00
Method: "GET",
}
s2 := &Service{
Name: "Statup Github",
Domain: "https://github.com/hunterlong/statup",
2018-06-30 00:57:05 +00:00
ExpectedStatus: 200,
Interval: 30,
2018-06-30 00:57:05 +00:00
Port: 0,
Type: "http",
2018-06-30 00:57:05 +00:00
Method: "GET",
}
s3 := &Service{
Name: "JSON Users Test",
Domain: "https://jsonplaceholder.typicode.com/users",
2018-06-30 00:57:05 +00:00
ExpectedStatus: 200,
Interval: 60,
2018-06-30 00:57:05 +00:00
Port: 443,
Type: "http",
Method: "GET",
2018-06-30 00:57:05 +00:00
}
s4 := &Service{
Name: "JSON API Tester",
Domain: "https://jsonplaceholder.typicode.com/posts",
ExpectedStatus: 201,
Expected: `(title)": "((\\"|[statup])*)"`,
Interval: 30,
Type: "http",
Method: "POST",
PostData: `{ "title": "statup", "body": "bar", "userId": 19999 }`,
2018-06-30 00:57:05 +00:00
}
s1.Create()
s2.Create()
s3.Create()
s4.Create()
checkin := &Checkin{
Service: s2.Id,
Interval: 30,
Api: utils.NewSHA1Hash(18),
}
checkin.Create()
2018-07-02 06:21:41 +00:00
//for i := 0; i < 3; i++ {
// s1.Check()
// s2.Check()
// s3.Check()
// s4.Check()
//}
utils.Log(1, "Sample data has finished importing")
2018-06-30 00:57:05 +00:00
return nil
}