forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
118 lines (109 loc) · 2.5 KB
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package core
import (
"fmt"
"github.com/hunterlong/statup/types"
"github.com/hunterlong/statup/utils"
"os"
)
func InsertDefaultComms() {
emailer := SelectCommunication(1)
if emailer == nil {
emailer := &types.Communication{
Method: "email",
Removable: false,
Enabled: false,
}
Create(emailer)
}
slack := SelectCommunication(2)
if slack == nil {
slack := &types.Communication{
Method: "slack",
Removable: false,
Enabled: false,
}
Create(slack)
}
}
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...")
s1 := &Service{
Name: "Google",
Domain: "https://google.com",
ExpectedStatus: 200,
Interval: 10,
Port: 0,
Type: "http",
Method: "GET",
}
s2 := &Service{
Name: "Statup Github",
Domain: "https://github.com/hunterlong/statup",
ExpectedStatus: 200,
Interval: 30,
Port: 0,
Type: "http",
Method: "GET",
}
s3 := &Service{
Name: "JSON Users Test",
Domain: "https://jsonplaceholder.typicode.com/users",
ExpectedStatus: 200,
Interval: 60,
Port: 443,
Type: "http",
Method: "GET",
}
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 }`,
}
id, err := s1.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
id, err = s2.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
id, err = s3.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
id, err = s4.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
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))
}
//for i := 0; i < 3; i++ {
// s1.Check()
// s2.Check()
// s3.Check()
// s4.Check()
//}
utils.Log(1, "Sample data has finished importing")
return nil
}