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/vendor.json5
10 files changed, 2 insertions, 323 deletions
diff --git a/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go b/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go
deleted file mode 100644
index dc86b47..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go
+++ /dev/null
@@ -1,229 +0,0 @@
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
deleted file mode 100644
index 4f14be5..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json
+++ /dev/null
@@ -1,4 +0,0 @@
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
deleted file mode 100644
index 81a913d..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json
+++ /dev/null
@@ -1,22 +0,0 @@
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
deleted file mode 100644
index 6fad58e..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json
+++ /dev/null
@@ -1,5 +0,0 @@
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
deleted file mode 100644
index 0dd279b..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json
+++ /dev/null
@@ -1,6 +0,0 @@
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
deleted file mode 100644
index 9754aa2..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json
+++ /dev/null
@@ -1,34 +0,0 @@
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
deleted file mode 100644
index a76c5eb..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json
+++ /dev/null
@@ -1,9 +0,0 @@
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
deleted file mode 100644
index 02e98eb..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json
+++ /dev/null
@@ -1,5 +0,0 @@
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
deleted file mode 100644
index 7c2dee2..0000000
--- a/vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json
+++ /dev/null
@@ -1,6 +0,0 @@
1{
2 "Issues": {},
3 "Success": true,
4 "Message": "",
5 "InsertID": 1234
6}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index d2bc87c..61dd8f3 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -4,10 +4,9 @@
4 "package": [ 4 "package": [
5 { 5 {
6 "checksumSHA1": "6Fo7YzTT+MDviHOsqg6dNw8WrV4=", 6 "checksumSHA1": "6Fo7YzTT+MDviHOsqg6dNw8WrV4=",
7 "origin": "github.com/matschaffer/statuscake",
8 "path": "github.com/DreamItGetIT/statuscake", 7 "path": "github.com/DreamItGetIT/statuscake",
9 "revision": "24c596002b80d84cf3bfb0f714e880c1b2e9af16", 8 "revision": "f69198f958d7326f3c110dd9be1c21abbd8a87a7",
10 "revisionTime": "2018-01-16T08:09:52Z" 9 "revisionTime": "2018-01-30T22:14:43Z"
11 }, 10 },
12 { 11 {
13 "checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=", 12 "checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=",