statping/core/setup.go

111 lines
2.5 KiB
Go
Raw Normal View History

2018-06-30 00:57:05 +00:00
package core
import (
"fmt"
2018-07-14 02:37:39 +00:00
"github.com/hunterlong/statup/types"
2018-06-30 00:57:05 +00:00
"github.com/hunterlong/statup/utils"
"os"
)
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-07-14 02:37:39 +00:00
s1 := &types.Service{
2018-06-30 00:57:05 +00:00
Name: "Google",
Domain: "https://google.com",
ExpectedStatus: 200,
Interval: 10,
Type: "http",
2018-06-30 00:57:05 +00:00
Method: "GET",
Timeout: 10,
2018-06-30 00:57:05 +00:00
}
2018-07-14 02:37:39 +00:00
s2 := &types.Service{
Name: "Statup Github",
Domain: "https://github.com/hunterlong/statup",
2018-06-30 00:57:05 +00:00
ExpectedStatus: 200,
Interval: 30,
Type: "http",
2018-06-30 00:57:05 +00:00
Method: "GET",
Timeout: 20,
2018-06-30 00:57:05 +00:00
}
2018-07-14 02:37:39 +00:00
s3 := &types.Service{
Name: "JSON Users Test",
Domain: "https://jsonplaceholder.typicode.com/users",
2018-06-30 00:57:05 +00:00
ExpectedStatus: 200,
Interval: 60,
Type: "http",
Method: "GET",
Timeout: 30,
2018-06-30 00:57:05 +00:00
}
2018-07-14 02:37:39 +00:00
s4 := &types.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 }`,
Timeout: 30,
}
s5 := &types.Service{
Name: "Postgres TCP Check",
Domain: "0.0.0.0",
Interval: 20,
Type: "tcp",
Port: 5432,
Timeout: 120,
2018-06-30 00:57:05 +00:00
}
2018-07-14 02:37:39 +00:00
id, err := CreateService(s1)
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
2018-07-14 02:37:39 +00:00
id, err = CreateService(s2)
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
2018-07-14 02:37:39 +00:00
id, err = CreateService(s3)
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
2018-07-14 02:37:39 +00:00
id, err = CreateService(s4)
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
id, err = CreateService(s5)
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating TCP Service %v: %v", id, err))
}
2018-06-30 00:57:05 +00:00
//checkin := &Checkin{
// Service: s2.Id,
// Interval: 30,
// Api: utils.NewSHA1Hash(18),
//}
//id, err = checkin.Create()
//if err != nil {
// utils.Log(3, fmt.Sprintf("Error creating Checkin %v: %v", id, err))
//}
2018-06-30 00:57:05 +00:00
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
}