aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go229
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json4
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json22
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json5
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json6
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json34
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json9
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json5
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json6
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/responses.go56
-rw-r--r--vendor/github.com/DreamItGetIT/statuscake/tests.go33
-rw-r--r--vendor/vendor.json6
12 files changed, 392 insertions, 23 deletions
diff --git a/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go b/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go
new file mode 100644
index 0000000..dc86b47
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go
@@ -0,0 +1,229 @@
1package main
2
3import (
4 "fmt"
5 logpkg "log"
6 "os"
7 "strconv"
8
9 "github.com/DreamItGetIT/statuscake"
10)
11
12var log *logpkg.Logger
13
14type command func(*statuscake.Client, ...string) error
15
16var commands map[string]command
17
18func init() {
19 log = logpkg.New(os.Stderr, "", 0)
20 commands = map[string]command{
21 "list": cmdList,
22 "detail": cmdDetail,
23 "delete": cmdDelete,
24 "create": cmdCreate,
25 "update": cmdUpdate,
26 }
27}
28
29func colouredStatus(s string) string {
30 switch s {
31 case "Up":
32 return fmt.Sprintf("\033[0;32m%s\033[0m", s)
33 case "Down":
34 return fmt.Sprintf("\033[0;31m%s\033[0m", s)
35 default:
36 return s
37 }
38}
39
40func getEnv(name string) string {
41 v := os.Getenv(name)
42 if v == "" {
43 log.Fatalf("`%s` env variable is required", name)
44 }
45
46 return v
47}
48
49func cmdList(c *statuscake.Client, args ...string) error {
50 tt := c.Tests()
51 tests, err := tt.All()
52 if err != nil {
53 return err
54 }
55
56 for _, t := range tests {
57 var paused string
58 if t.Paused {
59 paused = "yes"
60 } else {
61 paused = "no"
62 }
63
64 fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status))
65 fmt.Printf(" WebsiteName: %s\n", t.WebsiteName)
66 fmt.Printf(" TestType: %s\n", t.TestType)
67 fmt.Printf(" Paused: %s\n", paused)
68 fmt.Printf(" ContactID: %d\n", t.ContactID)
69 fmt.Printf(" Uptime: %f\n", t.Uptime)
70 }
71
72 return nil
73}
74
75func cmdDetail(c *statuscake.Client, args ...string) error {
76 if len(args) != 1 {
77 return fmt.Errorf("command `detail` requires a single argument `TestID`")
78 }
79
80 id, err := strconv.Atoi(args[0])
81 if err != nil {
82 return err
83 }
84
85 tt := c.Tests()
86 t, err := tt.Detail(id)
87 if err != nil {
88 return err
89 }
90
91 var paused string
92 if t.Paused {
93 paused = "yes"
94 } else {
95 paused = "no"
96 }
97
98 fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status))
99 fmt.Printf(" WebsiteName: %s\n", t.WebsiteName)
100 fmt.Printf(" WebsiteURL: %s\n", t.WebsiteURL)
101 fmt.Printf(" PingURL: %s\n", t.PingURL)
102 fmt.Printf(" TestType: %s\n", t.TestType)
103 fmt.Printf(" Paused: %s\n", paused)
104 fmt.Printf(" ContactID: %d\n", t.ContactID)
105 fmt.Printf(" Uptime: %f\n", t.Uptime)
106
107 return nil
108}
109
110func cmdDelete(c *statuscake.Client, args ...string) error {
111 if len(args) != 1 {
112 return fmt.Errorf("command `delete` requires a single argument `TestID`")
113 }
114
115 id, err := strconv.Atoi(args[0])
116 if err != nil {
117 return err
118 }
119
120 return c.Tests().Delete(id)
121}
122
123func askString(name string) string {
124 var v string
125
126 fmt.Printf("%s: ", name)
127 _, err := fmt.Scanln(&v)
128 if err != nil {
129 log.Fatal(err)
130 }
131
132 return v
133}
134
135func askInt(name string) int {
136 v := askString(name)
137 i, err := strconv.Atoi(v)
138 if err != nil {
139 log.Fatalf("Invalid number `%s`", v)
140 }
141
142 return i
143}
144
145func cmdCreate(c *statuscake.Client, args ...string) error {
146 t := &statuscake.Test{
147 WebsiteName: askString("WebsiteName"),
148 WebsiteURL: askString("WebsiteURL"),
149 TestType: askString("TestType"),
150 CheckRate: askInt("CheckRate"),
151 }
152
153 t2, err := c.Tests().Update(t)
154 if err != nil {
155 return err
156 }
157
158 fmt.Printf("CREATED: \n%+v\n", t2)
159
160 return nil
161}
162
163func cmdUpdate(c *statuscake.Client, args ...string) error {
164 if len(args) != 1 {
165 return fmt.Errorf("command `update` requires a single argument `TestID`")
166 }
167
168 id, err := strconv.Atoi(args[0])
169 if err != nil {
170 return err
171 }
172
173 tt := c.Tests()
174 t, err := tt.Detail(id)
175 if err != nil {
176 return err
177 }
178
179 t.TestID = id
180 t.WebsiteName = askString(fmt.Sprintf("WebsiteName [%s]", t.WebsiteName))
181 t.WebsiteURL = askString(fmt.Sprintf("WebsiteURL [%s]", t.WebsiteURL))
182 t.TestType = askString(fmt.Sprintf("TestType [%s]", t.TestType))
183 t.CheckRate = askInt(fmt.Sprintf("CheckRate [%d]", t.CheckRate))
184
185 t2, err := c.Tests().Update(t)
186 if err != nil {
187 return err
188 }
189
190 fmt.Printf("UPDATED: \n%+v\n", t2)
191
192 return nil
193}
194
195func usage() {
196 fmt.Printf("Usage:\n")
197 fmt.Printf(" %s COMMAND\n", os.Args[0])
198 fmt.Printf("Available commands:\n")
199 for k := range commands {
200 fmt.Printf(" %+v\n", k)
201 }
202}
203
204func main() {
205 username := getEnv("STATUSCAKE_USERNAME")
206 apikey := getEnv("STATUSCAKE_APIKEY")
207
208 if len(os.Args) < 2 {
209 usage()
210 os.Exit(1)
211 }
212
213 var err error
214
215 c, err := statuscake.New(statuscake.Auth{Username: username, Apikey: apikey})
216 if err != nil {
217 log.Fatal(err)
218 }
219
220 if cmd, ok := commands[os.Args[1]]; ok {
221 err = cmd(c, os.Args[2:]...)
222 } else {
223 err = fmt.Errorf("Unknown command `%s`", os.Args[1])
224 }
225
226 if err != nil {
227 log.Fatalf("Error running command `%s`: %s", os.Args[1], err.Error())
228 }
229}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json
new file mode 100644
index 0000000..4f14be5
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json
@@ -0,0 +1,4 @@
1{
2 "ErrNo": 0,
3 "Error": "Can not access account. Was both Username and API Key provided?"
4}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json
new file mode 100644
index 0000000..81a913d
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json
@@ -0,0 +1,22 @@
1[
2 {
3 "TestID": 100,
4 "Paused": false,
5 "TestType": "HTTP",
6 "WebsiteName": "www 1",
7 "ContactGroup": null,
8 "ContactID": "1",
9 "Status": "Up",
10 "Uptime": 100
11 },
12 {
13 "TestID": 101,
14 "Paused": true,
15 "TestType": "HTTP",
16 "WebsiteName": "www 2",
17 "ContactGroup": null,
18 "ContactID": "2",
19 "Status": "Down",
20 "Uptime": 0
21 }
22]
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json
new file mode 100644
index 0000000..6fad58e
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json
@@ -0,0 +1,5 @@
1{
2 "Success": false,
3 "Error": "this is an error"
4}
5
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json
new file mode 100644
index 0000000..0dd279b
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json
@@ -0,0 +1,6 @@
1{
2 "TestID": 6735,
3 "Affected": 1,
4 "Success": true,
5 "Message": "This Check Has Been Deleted. It can not be recovered."
6}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json
new file mode 100644
index 0000000..9754aa2
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json
@@ -0,0 +1,34 @@
1{
2 "TestID": 6735,
3 "TestType": "HTTP",
4 "Paused": false,
5 "WebsiteName": "NL",
6 "CustomHeader": "{\"some\":{\"json\": [\"value\"]}}",
7 "UserAgent": "product/version (comment)",
8 "ContactGroup": "StatusCake Alerts",
9 "ContactID": "536",
10 "Status": "Up",
11 "Uptime": 0,
12 "CheckRate": 60,
13 "Timeout": 40,
14 "LogoImage": "",
15 "WebsiteHost": "Various",
16 "NodeLocations": [
17 "UK",
18 "JP",
19 "SG1",
20 "SLC"
21 ],
22 "FindString": "",
23 "DoNotFind": false,
24 "LastTested": "2013-01-20 14:38:18",
25 "NextLocation": "USNY",
26 "Processing": false,
27 "ProcessingState": "Pretest",
28 "ProcessingOn": "dalas.localdomain",
29 "DownTimes": "0",
30 "UseJar": 0,
31 "PostRaw": "",
32 "FinalEndpoint": "",
33 "FollowRedirect": false
34}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json
new file mode 100644
index 0000000..a76c5eb
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json
@@ -0,0 +1,9 @@
1{
2 "Issues": {
3 "WebsiteName": "issue a",
4 "WebsiteURL": "issue b",
5 "CheckRate": "issue c"
6 },
7 "Success": false,
8 "Message": "Required Data is Missing."
9}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json
new file mode 100644
index 0000000..02e98eb
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json
@@ -0,0 +1,5 @@
1{
2 "Issues": ["hello", "world"],
3 "Success": false,
4 "Message": "Required Data is Missing."
5}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json
new file mode 100644
index 0000000..7c2dee2
--- /dev/null
+++ b/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json
@@ -0,0 +1,6 @@
1{
2 "Issues": {},
3 "Success": true,
4 "Message": "",
5 "InsertID": 1234
6}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/responses.go b/vendor/github.com/DreamItGetIT/statuscake/responses.go
index b9216b7..9cdcb11 100644
--- a/vendor/github.com/DreamItGetIT/statuscake/responses.go
+++ b/vendor/github.com/DreamItGetIT/statuscake/responses.go
@@ -1,5 +1,9 @@
1package statuscake 1package statuscake
2 2
3import (
4 "strings"
5)
6
3type autheticationErrorResponse struct { 7type autheticationErrorResponse struct {
4 ErrNo int 8 ErrNo int
5 Error string 9 Error string
@@ -24,9 +28,11 @@ type detailResponse struct {
24 Paused bool `json:"Paused"` 28 Paused bool `json:"Paused"`
25 WebsiteName string `json:"WebsiteName"` 29 WebsiteName string `json:"WebsiteName"`
26 URI string `json:"URI"` 30 URI string `json:"URI"`
27 ContactID int `json:"ContactID"` 31 ContactID string `json:"ContactID"`
28 Status string `json:"Status"` 32 Status string `json:"Status"`
29 Uptime float64 `json:"Uptime"` 33 Uptime float64 `json:"Uptime"`
34 CustomHeader string `json:"CustomHeader"`
35 UserAgent string `json:"UserAgent"`
30 CheckRate int `json:"CheckRate"` 36 CheckRate int `json:"CheckRate"`
31 Timeout int `json:"Timeout"` 37 Timeout int `json:"Timeout"`
32 LogoImage string `json:"LogoImage"` 38 LogoImage string `json:"LogoImage"`
@@ -44,27 +50,39 @@ type detailResponse struct {
44 DownTimes int `json:"DownTimes,string"` 50 DownTimes int `json:"DownTimes,string"`
45 Sensitive bool `json:"Sensitive"` 51 Sensitive bool `json:"Sensitive"`
46 TriggerRate int `json:"TriggerRate,string"` 52 TriggerRate int `json:"TriggerRate,string"`
53 UseJar int `json:"UseJar"`
54 PostRaw string `json:"PostRaw"`
55 FinalEndpoint string `json:"FinalEndpoint"`
56 FollowRedirect bool `json:"FollowRedirect"`
57 StatusCodes []string `json:"StatusCodes"`
47} 58}
48 59
49func (d *detailResponse) test() *Test { 60func (d *detailResponse) test() *Test {
50 return &Test{ 61 return &Test{
51 TestID: d.TestID, 62 TestID: d.TestID,
52 TestType: d.TestType, 63 TestType: d.TestType,
53 Paused: d.Paused, 64 Paused: d.Paused,
54 WebsiteName: d.WebsiteName, 65 WebsiteName: d.WebsiteName,
55 WebsiteURL: d.URI, 66 WebsiteURL: d.URI,
56 ContactID: d.ContactID, 67 CustomHeader: d.CustomHeader,
57 Status: d.Status, 68 UserAgent: d.UserAgent,
58 Uptime: d.Uptime, 69 ContactID: d.ContactID,
59 CheckRate: d.CheckRate, 70 Status: d.Status,
60 Timeout: d.Timeout, 71 Uptime: d.Uptime,
61 LogoImage: d.LogoImage, 72 CheckRate: d.CheckRate,
62 Confirmation: d.Confirmation, 73 Timeout: d.Timeout,
63 WebsiteHost: d.WebsiteHost, 74 LogoImage: d.LogoImage,
64 NodeLocations: d.NodeLocations, 75 Confirmation: d.Confirmation,
65 FindString: d.FindString, 76 WebsiteHost: d.WebsiteHost,
66 DoNotFind: d.DoNotFind, 77 NodeLocations: d.NodeLocations,
67 Port: d.Port, 78 FindString: d.FindString,
68 TriggerRate: d.TriggerRate, 79 DoNotFind: d.DoNotFind,
80 Port: d.Port,
81 TriggerRate: d.TriggerRate,
82 UseJar: d.UseJar,
83 PostRaw: d.PostRaw,
84 FinalEndpoint: d.FinalEndpoint,
85 FollowRedirect: d.FollowRedirect,
86 StatusCodes: strings.Join(d.StatusCodes[:], ","),
69 } 87 }
70} 88}
diff --git a/vendor/github.com/DreamItGetIT/statuscake/tests.go b/vendor/github.com/DreamItGetIT/statuscake/tests.go
index 4053e53..1b37fa1 100644
--- a/vendor/github.com/DreamItGetIT/statuscake/tests.go
+++ b/vendor/github.com/DreamItGetIT/statuscake/tests.go
@@ -21,6 +21,12 @@ type Test struct {
21 // Website name. Tags are stripped out 21 // Website name. Tags are stripped out
22 WebsiteName string `json:"WebsiteName" querystring:"WebsiteName"` 22 WebsiteName string `json:"WebsiteName" querystring:"WebsiteName"`
23 23
24 // CustomHeader. A special header that will be sent along with the HTTP tests.
25 CustomHeader string `json:"CustomHeader" querystring:"CustomHeader"`
26
27 // Use to populate the test with a custom user agent
28 UserAgent string `json:"UserAgent" queryString:"UserAgent"`
29
24 // Test location, either an IP (for TCP and Ping) or a fully qualified URL for other TestTypes 30 // Test location, either an IP (for TCP and Ping) or a fully qualified URL for other TestTypes
25 WebsiteURL string `json:"WebsiteURL" querystring:"WebsiteURL"` 31 WebsiteURL string `json:"WebsiteURL" querystring:"WebsiteURL"`
26 32
@@ -28,7 +34,7 @@ type Test struct {
28 Port int `json:"Port" querystring:"Port"` 34 Port int `json:"Port" querystring:"Port"`
29 35
30 // Contact group ID - will return int of contact group used else 0 36 // Contact group ID - will return int of contact group used else 0
31 ContactID int `json:"ContactID" querystring:"ContactGroup"` 37 ContactID string `json:"ContactID" querystring:"ContactGroup"`
32 38
33 // Current status at last test 39 // Current status at last test
34 Status string `json:"Status"` 40 Status string `json:"Status"`
@@ -91,6 +97,18 @@ type Test struct {
91 97
92 // Comma Seperated List of StatusCodes to Trigger Error on (on Update will replace, so send full list each time) 98 // Comma Seperated List of StatusCodes to Trigger Error on (on Update will replace, so send full list each time)
93 StatusCodes string `json:"StatusCodes" querystring:"StatusCodes"` 99 StatusCodes string `json:"StatusCodes" querystring:"StatusCodes"`
100
101 // Set to 1 to enable the Cookie Jar. Required for some redirects.
102 UseJar int `json:"UseJar" querystring:"UseJar"`
103
104 // Raw POST data seperated by an ampersand
105 PostRaw string `json:"PostRaw" querystring:"PostRaw"`
106
107 // Use to specify the expected Final URL in the testing process
108 FinalEndpoint string `json:"FinalEndpoint" querystring:"FinalEndpoint"`
109
110 // Use to specify whether redirects should be followed
111 FollowRedirect bool `json:"FollowRedirect" querystring:"FollowRedirect"`
94} 112}
95 113
96// Validate checks if the Test is valid. If it's invalid, it returns a ValidationError with all invalid fields. It returns nil otherwise. 114// Validate checks if the Test is valid. If it's invalid, it returns a ValidationError with all invalid fields. It returns nil otherwise.
@@ -137,6 +155,19 @@ func (t *Test) Validate() error {
137 e["TriggerRate"] = "must be between 0 and 59" 155 e["TriggerRate"] = "must be between 0 and 59"
138 } 156 }
139 157
158 if t.PostRaw != "" && t.TestType != "HTTP" {
159 e["PostRaw"] = "must be HTTP to submit a POST request"
160 }
161
162 if t.FinalEndpoint != "" && t.TestType != "HTTP" {
163 e["FinalEndpoint"] = "must be a Valid URL"
164 }
165
166 var jsonVerifiable map[string]interface{}
167 if json.Unmarshal([]byte(t.CustomHeader), &jsonVerifiable) != nil {
168 e["CustomHeader"] = "must be provided as json string"
169 }
170
140 if len(e) > 0 { 171 if len(e) > 0 {
141 return e 172 return e
142 } 173 }
diff --git a/vendor/vendor.json b/vendor/vendor.json
index 8b44fbd..921131f 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -3,10 +3,10 @@
3 "ignore": "appengine test github.com/hashicorp/nomad/ github.com/hashicorp/terraform/backend", 3 "ignore": "appengine test github.com/hashicorp/nomad/ github.com/hashicorp/terraform/backend",
4 "package": [ 4 "package": [
5 { 5 {
6 "checksumSHA1": "MV5JueYPwNkLZ+KNqmDcNDhsKi4=", 6 "checksumSHA1": "xjfJ6T+mQFmC9oMR+UKdGtbs/p4=",
7 "path": "github.com/DreamItGetIT/statuscake", 7 "path": "github.com/DreamItGetIT/statuscake",
8 "revision": "acc13ec021cd1e8a6ebb1d9035f513217f5c4562", 8 "revision": "2081e16dbe691bccf20b1901897d8f8245beefcd",
9 "revisionTime": "2017-04-10T11:34:45Z" 9 "revisionTime": "2018-01-09T18:02:45Z"
10 }, 10 },
11 { 11 {
12 "checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=", 12 "checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=",