From a88e9b9b13ab703c3ff39595701e1d36b5ed49da Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Tue, 16 Jan 2018 15:05:10 +0200 Subject: update vendor/github.com/DreamItGetIT/statuscake to latest version --- .../DreamItGetIT/statuscake/cmd/statuscake/main.go | 229 +++++++++++++++++++++ .../statuscake/fixtures/auth_error.json | 4 + .../statuscake/fixtures/tests_all_ok.json | 22 ++ .../statuscake/fixtures/tests_delete_error.json | 5 + .../statuscake/fixtures/tests_delete_ok.json | 6 + .../statuscake/fixtures/tests_detail_ok.json | 34 +++ .../statuscake/fixtures/tests_update_error.json | 9 + .../tests_update_error_slice_of_issues.json | 5 + .../statuscake/fixtures/tests_update_ok.json | 6 + .../DreamItGetIT/statuscake/responses.go | 56 +++-- vendor/github.com/DreamItGetIT/statuscake/tests.go | 33 ++- 11 files changed, 389 insertions(+), 20 deletions(-) create mode 100644 vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json create mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json (limited to 'vendor/github.com/DreamItGetIT') 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 @@ +package main + +import ( + "fmt" + logpkg "log" + "os" + "strconv" + + "github.com/DreamItGetIT/statuscake" +) + +var log *logpkg.Logger + +type command func(*statuscake.Client, ...string) error + +var commands map[string]command + +func init() { + log = logpkg.New(os.Stderr, "", 0) + commands = map[string]command{ + "list": cmdList, + "detail": cmdDetail, + "delete": cmdDelete, + "create": cmdCreate, + "update": cmdUpdate, + } +} + +func colouredStatus(s string) string { + switch s { + case "Up": + return fmt.Sprintf("\033[0;32m%s\033[0m", s) + case "Down": + return fmt.Sprintf("\033[0;31m%s\033[0m", s) + default: + return s + } +} + +func getEnv(name string) string { + v := os.Getenv(name) + if v == "" { + log.Fatalf("`%s` env variable is required", name) + } + + return v +} + +func cmdList(c *statuscake.Client, args ...string) error { + tt := c.Tests() + tests, err := tt.All() + if err != nil { + return err + } + + for _, t := range tests { + var paused string + if t.Paused { + paused = "yes" + } else { + paused = "no" + } + + fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) + fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) + fmt.Printf(" TestType: %s\n", t.TestType) + fmt.Printf(" Paused: %s\n", paused) + fmt.Printf(" ContactID: %d\n", t.ContactID) + fmt.Printf(" Uptime: %f\n", t.Uptime) + } + + return nil +} + +func cmdDetail(c *statuscake.Client, args ...string) error { + if len(args) != 1 { + return fmt.Errorf("command `detail` requires a single argument `TestID`") + } + + id, err := strconv.Atoi(args[0]) + if err != nil { + return err + } + + tt := c.Tests() + t, err := tt.Detail(id) + if err != nil { + return err + } + + var paused string + if t.Paused { + paused = "yes" + } else { + paused = "no" + } + + fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) + fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) + fmt.Printf(" WebsiteURL: %s\n", t.WebsiteURL) + fmt.Printf(" PingURL: %s\n", t.PingURL) + fmt.Printf(" TestType: %s\n", t.TestType) + fmt.Printf(" Paused: %s\n", paused) + fmt.Printf(" ContactID: %d\n", t.ContactID) + fmt.Printf(" Uptime: %f\n", t.Uptime) + + return nil +} + +func cmdDelete(c *statuscake.Client, args ...string) error { + if len(args) != 1 { + return fmt.Errorf("command `delete` requires a single argument `TestID`") + } + + id, err := strconv.Atoi(args[0]) + if err != nil { + return err + } + + return c.Tests().Delete(id) +} + +func askString(name string) string { + var v string + + fmt.Printf("%s: ", name) + _, err := fmt.Scanln(&v) + if err != nil { + log.Fatal(err) + } + + return v +} + +func askInt(name string) int { + v := askString(name) + i, err := strconv.Atoi(v) + if err != nil { + log.Fatalf("Invalid number `%s`", v) + } + + return i +} + +func cmdCreate(c *statuscake.Client, args ...string) error { + t := &statuscake.Test{ + WebsiteName: askString("WebsiteName"), + WebsiteURL: askString("WebsiteURL"), + TestType: askString("TestType"), + CheckRate: askInt("CheckRate"), + } + + t2, err := c.Tests().Update(t) + if err != nil { + return err + } + + fmt.Printf("CREATED: \n%+v\n", t2) + + return nil +} + +func cmdUpdate(c *statuscake.Client, args ...string) error { + if len(args) != 1 { + return fmt.Errorf("command `update` requires a single argument `TestID`") + } + + id, err := strconv.Atoi(args[0]) + if err != nil { + return err + } + + tt := c.Tests() + t, err := tt.Detail(id) + if err != nil { + return err + } + + t.TestID = id + t.WebsiteName = askString(fmt.Sprintf("WebsiteName [%s]", t.WebsiteName)) + t.WebsiteURL = askString(fmt.Sprintf("WebsiteURL [%s]", t.WebsiteURL)) + t.TestType = askString(fmt.Sprintf("TestType [%s]", t.TestType)) + t.CheckRate = askInt(fmt.Sprintf("CheckRate [%d]", t.CheckRate)) + + t2, err := c.Tests().Update(t) + if err != nil { + return err + } + + fmt.Printf("UPDATED: \n%+v\n", t2) + + return nil +} + +func usage() { + fmt.Printf("Usage:\n") + fmt.Printf(" %s COMMAND\n", os.Args[0]) + fmt.Printf("Available commands:\n") + for k := range commands { + fmt.Printf(" %+v\n", k) + } +} + +func main() { + username := getEnv("STATUSCAKE_USERNAME") + apikey := getEnv("STATUSCAKE_APIKEY") + + if len(os.Args) < 2 { + usage() + os.Exit(1) + } + + var err error + + c, err := statuscake.New(statuscake.Auth{Username: username, Apikey: apikey}) + if err != nil { + log.Fatal(err) + } + + if cmd, ok := commands[os.Args[1]]; ok { + err = cmd(c, os.Args[2:]...) + } else { + err = fmt.Errorf("Unknown command `%s`", os.Args[1]) + } + + if err != nil { + log.Fatalf("Error running command `%s`: %s", os.Args[1], err.Error()) + } +} 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 @@ +{ + "ErrNo": 0, + "Error": "Can not access account. Was both Username and API Key provided?" +} 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 @@ +[ + { + "TestID": 100, + "Paused": false, + "TestType": "HTTP", + "WebsiteName": "www 1", + "ContactGroup": null, + "ContactID": "1", + "Status": "Up", + "Uptime": 100 + }, + { + "TestID": 101, + "Paused": true, + "TestType": "HTTP", + "WebsiteName": "www 2", + "ContactGroup": null, + "ContactID": "2", + "Status": "Down", + "Uptime": 0 + } +] 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 @@ +{ + "Success": false, + "Error": "this is an error" +} + 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 @@ +{ + "TestID": 6735, + "Affected": 1, + "Success": true, + "Message": "This Check Has Been Deleted. It can not be recovered." +} 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 @@ +{ + "TestID": 6735, + "TestType": "HTTP", + "Paused": false, + "WebsiteName": "NL", + "CustomHeader": "{\"some\":{\"json\": [\"value\"]}}", + "UserAgent": "product/version (comment)", + "ContactGroup": "StatusCake Alerts", + "ContactID": "536", + "Status": "Up", + "Uptime": 0, + "CheckRate": 60, + "Timeout": 40, + "LogoImage": "", + "WebsiteHost": "Various", + "NodeLocations": [ + "UK", + "JP", + "SG1", + "SLC" + ], + "FindString": "", + "DoNotFind": false, + "LastTested": "2013-01-20 14:38:18", + "NextLocation": "USNY", + "Processing": false, + "ProcessingState": "Pretest", + "ProcessingOn": "dalas.localdomain", + "DownTimes": "0", + "UseJar": 0, + "PostRaw": "", + "FinalEndpoint": "", + "FollowRedirect": false +} 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 @@ +{ + "Issues": { + "WebsiteName": "issue a", + "WebsiteURL": "issue b", + "CheckRate": "issue c" + }, + "Success": false, + "Message": "Required Data is Missing." +} 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 @@ +{ + "Issues": ["hello", "world"], + "Success": false, + "Message": "Required Data is Missing." +} 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 @@ +{ + "Issues": {}, + "Success": true, + "Message": "", + "InsertID": 1234 +} 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 @@ package statuscake +import ( + "strings" +) + type autheticationErrorResponse struct { ErrNo int Error string @@ -24,9 +28,11 @@ type detailResponse struct { Paused bool `json:"Paused"` WebsiteName string `json:"WebsiteName"` URI string `json:"URI"` - ContactID int `json:"ContactID"` + ContactID string `json:"ContactID"` Status string `json:"Status"` Uptime float64 `json:"Uptime"` + CustomHeader string `json:"CustomHeader"` + UserAgent string `json:"UserAgent"` CheckRate int `json:"CheckRate"` Timeout int `json:"Timeout"` LogoImage string `json:"LogoImage"` @@ -44,27 +50,39 @@ type detailResponse struct { DownTimes int `json:"DownTimes,string"` Sensitive bool `json:"Sensitive"` TriggerRate int `json:"TriggerRate,string"` + UseJar int `json:"UseJar"` + PostRaw string `json:"PostRaw"` + FinalEndpoint string `json:"FinalEndpoint"` + FollowRedirect bool `json:"FollowRedirect"` + StatusCodes []string `json:"StatusCodes"` } func (d *detailResponse) test() *Test { return &Test{ - TestID: d.TestID, - TestType: d.TestType, - Paused: d.Paused, - WebsiteName: d.WebsiteName, - WebsiteURL: d.URI, - ContactID: d.ContactID, - Status: d.Status, - Uptime: d.Uptime, - CheckRate: d.CheckRate, - Timeout: d.Timeout, - LogoImage: d.LogoImage, - Confirmation: d.Confirmation, - WebsiteHost: d.WebsiteHost, - NodeLocations: d.NodeLocations, - FindString: d.FindString, - DoNotFind: d.DoNotFind, - Port: d.Port, - TriggerRate: d.TriggerRate, + TestID: d.TestID, + TestType: d.TestType, + Paused: d.Paused, + WebsiteName: d.WebsiteName, + WebsiteURL: d.URI, + CustomHeader: d.CustomHeader, + UserAgent: d.UserAgent, + ContactID: d.ContactID, + Status: d.Status, + Uptime: d.Uptime, + CheckRate: d.CheckRate, + Timeout: d.Timeout, + LogoImage: d.LogoImage, + Confirmation: d.Confirmation, + WebsiteHost: d.WebsiteHost, + NodeLocations: d.NodeLocations, + FindString: d.FindString, + DoNotFind: d.DoNotFind, + Port: d.Port, + TriggerRate: d.TriggerRate, + UseJar: d.UseJar, + PostRaw: d.PostRaw, + FinalEndpoint: d.FinalEndpoint, + FollowRedirect: d.FollowRedirect, + StatusCodes: strings.Join(d.StatusCodes[:], ","), } } 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 { // Website name. Tags are stripped out WebsiteName string `json:"WebsiteName" querystring:"WebsiteName"` + // CustomHeader. A special header that will be sent along with the HTTP tests. + CustomHeader string `json:"CustomHeader" querystring:"CustomHeader"` + + // Use to populate the test with a custom user agent + UserAgent string `json:"UserAgent" queryString:"UserAgent"` + // Test location, either an IP (for TCP and Ping) or a fully qualified URL for other TestTypes WebsiteURL string `json:"WebsiteURL" querystring:"WebsiteURL"` @@ -28,7 +34,7 @@ type Test struct { Port int `json:"Port" querystring:"Port"` // Contact group ID - will return int of contact group used else 0 - ContactID int `json:"ContactID" querystring:"ContactGroup"` + ContactID string `json:"ContactID" querystring:"ContactGroup"` // Current status at last test Status string `json:"Status"` @@ -91,6 +97,18 @@ type Test struct { // Comma Seperated List of StatusCodes to Trigger Error on (on Update will replace, so send full list each time) StatusCodes string `json:"StatusCodes" querystring:"StatusCodes"` + + // Set to 1 to enable the Cookie Jar. Required for some redirects. + UseJar int `json:"UseJar" querystring:"UseJar"` + + // Raw POST data seperated by an ampersand + PostRaw string `json:"PostRaw" querystring:"PostRaw"` + + // Use to specify the expected Final URL in the testing process + FinalEndpoint string `json:"FinalEndpoint" querystring:"FinalEndpoint"` + + // Use to specify whether redirects should be followed + FollowRedirect bool `json:"FollowRedirect" querystring:"FollowRedirect"` } // 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 { e["TriggerRate"] = "must be between 0 and 59" } + if t.PostRaw != "" && t.TestType != "HTTP" { + e["PostRaw"] = "must be HTTP to submit a POST request" + } + + if t.FinalEndpoint != "" && t.TestType != "HTTP" { + e["FinalEndpoint"] = "must be a Valid URL" + } + + var jsonVerifiable map[string]interface{} + if json.Unmarshal([]byte(t.CustomHeader), &jsonVerifiable) != nil { + e["CustomHeader"] = "must be provided as json string" + } + if len(e) > 0 { return e } -- cgit v1.2.3 From c9458806c73b69e6af47eddd83391197b6d2a641 Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Wed, 17 Jan 2018 16:55:18 +0200 Subject: merge changes from https://github.com/DreamItGetIT/statuscake/pull/24 to vendor directory --- vendor/github.com/DreamItGetIT/statuscake/responses.go | 2 +- vendor/github.com/DreamItGetIT/statuscake/tests.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'vendor/github.com/DreamItGetIT') diff --git a/vendor/github.com/DreamItGetIT/statuscake/responses.go b/vendor/github.com/DreamItGetIT/statuscake/responses.go index 9cdcb11..3cbf36d 100644 --- a/vendor/github.com/DreamItGetIT/statuscake/responses.go +++ b/vendor/github.com/DreamItGetIT/statuscake/responses.go @@ -28,7 +28,7 @@ type detailResponse struct { Paused bool `json:"Paused"` WebsiteName string `json:"WebsiteName"` URI string `json:"URI"` - ContactID string `json:"ContactID"` + ContactID int `json:"ContactID"` Status string `json:"Status"` Uptime float64 `json:"Uptime"` CustomHeader string `json:"CustomHeader"` diff --git a/vendor/github.com/DreamItGetIT/statuscake/tests.go b/vendor/github.com/DreamItGetIT/statuscake/tests.go index 1b37fa1..a41b0bd 100644 --- a/vendor/github.com/DreamItGetIT/statuscake/tests.go +++ b/vendor/github.com/DreamItGetIT/statuscake/tests.go @@ -34,7 +34,7 @@ type Test struct { Port int `json:"Port" querystring:"Port"` // Contact group ID - will return int of contact group used else 0 - ContactID string `json:"ContactID" querystring:"ContactGroup"` + ContactID int `json:"ContactID" querystring:"ContactGroup"` // Current status at last test Status string `json:"Status"` -- cgit v1.2.3 From 85e124eb0c7b262ff9c486abe9662f515f47fc5b Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Wed, 31 Jan 2018 13:45:28 +0200 Subject: update github.com/DreamItGetIT/statuscake --- .../DreamItGetIT/statuscake/cmd/statuscake/main.go | 229 --------------------- .../statuscake/fixtures/auth_error.json | 4 - .../statuscake/fixtures/tests_all_ok.json | 22 -- .../statuscake/fixtures/tests_delete_error.json | 5 - .../statuscake/fixtures/tests_delete_ok.json | 6 - .../statuscake/fixtures/tests_detail_ok.json | 34 --- .../statuscake/fixtures/tests_update_error.json | 9 - .../tests_update_error_slice_of_issues.json | 5 - .../statuscake/fixtures/tests_update_ok.json | 6 - 9 files changed, 320 deletions(-) delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/cmd/statuscake/main.go delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/auth_error.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_all_ok.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_error.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_delete_ok.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_detail_ok.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_error_slice_of_issues.json delete mode 100644 vendor/github.com/DreamItGetIT/statuscake/fixtures/tests_update_ok.json (limited to 'vendor/github.com/DreamItGetIT') 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 @@ -package main - -import ( - "fmt" - logpkg "log" - "os" - "strconv" - - "github.com/DreamItGetIT/statuscake" -) - -var log *logpkg.Logger - -type command func(*statuscake.Client, ...string) error - -var commands map[string]command - -func init() { - log = logpkg.New(os.Stderr, "", 0) - commands = map[string]command{ - "list": cmdList, - "detail": cmdDetail, - "delete": cmdDelete, - "create": cmdCreate, - "update": cmdUpdate, - } -} - -func colouredStatus(s string) string { - switch s { - case "Up": - return fmt.Sprintf("\033[0;32m%s\033[0m", s) - case "Down": - return fmt.Sprintf("\033[0;31m%s\033[0m", s) - default: - return s - } -} - -func getEnv(name string) string { - v := os.Getenv(name) - if v == "" { - log.Fatalf("`%s` env variable is required", name) - } - - return v -} - -func cmdList(c *statuscake.Client, args ...string) error { - tt := c.Tests() - tests, err := tt.All() - if err != nil { - return err - } - - for _, t := range tests { - var paused string - if t.Paused { - paused = "yes" - } else { - paused = "no" - } - - fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) - fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) - fmt.Printf(" TestType: %s\n", t.TestType) - fmt.Printf(" Paused: %s\n", paused) - fmt.Printf(" ContactID: %d\n", t.ContactID) - fmt.Printf(" Uptime: %f\n", t.Uptime) - } - - return nil -} - -func cmdDetail(c *statuscake.Client, args ...string) error { - if len(args) != 1 { - return fmt.Errorf("command `detail` requires a single argument `TestID`") - } - - id, err := strconv.Atoi(args[0]) - if err != nil { - return err - } - - tt := c.Tests() - t, err := tt.Detail(id) - if err != nil { - return err - } - - var paused string - if t.Paused { - paused = "yes" - } else { - paused = "no" - } - - fmt.Printf("* %d: %s\n", t.TestID, colouredStatus(t.Status)) - fmt.Printf(" WebsiteName: %s\n", t.WebsiteName) - fmt.Printf(" WebsiteURL: %s\n", t.WebsiteURL) - fmt.Printf(" PingURL: %s\n", t.PingURL) - fmt.Printf(" TestType: %s\n", t.TestType) - fmt.Printf(" Paused: %s\n", paused) - fmt.Printf(" ContactID: %d\n", t.ContactID) - fmt.Printf(" Uptime: %f\n", t.Uptime) - - return nil -} - -func cmdDelete(c *statuscake.Client, args ...string) error { - if len(args) != 1 { - return fmt.Errorf("command `delete` requires a single argument `TestID`") - } - - id, err := strconv.Atoi(args[0]) - if err != nil { - return err - } - - return c.Tests().Delete(id) -} - -func askString(name string) string { - var v string - - fmt.Printf("%s: ", name) - _, err := fmt.Scanln(&v) - if err != nil { - log.Fatal(err) - } - - return v -} - -func askInt(name string) int { - v := askString(name) - i, err := strconv.Atoi(v) - if err != nil { - log.Fatalf("Invalid number `%s`", v) - } - - return i -} - -func cmdCreate(c *statuscake.Client, args ...string) error { - t := &statuscake.Test{ - WebsiteName: askString("WebsiteName"), - WebsiteURL: askString("WebsiteURL"), - TestType: askString("TestType"), - CheckRate: askInt("CheckRate"), - } - - t2, err := c.Tests().Update(t) - if err != nil { - return err - } - - fmt.Printf("CREATED: \n%+v\n", t2) - - return nil -} - -func cmdUpdate(c *statuscake.Client, args ...string) error { - if len(args) != 1 { - return fmt.Errorf("command `update` requires a single argument `TestID`") - } - - id, err := strconv.Atoi(args[0]) - if err != nil { - return err - } - - tt := c.Tests() - t, err := tt.Detail(id) - if err != nil { - return err - } - - t.TestID = id - t.WebsiteName = askString(fmt.Sprintf("WebsiteName [%s]", t.WebsiteName)) - t.WebsiteURL = askString(fmt.Sprintf("WebsiteURL [%s]", t.WebsiteURL)) - t.TestType = askString(fmt.Sprintf("TestType [%s]", t.TestType)) - t.CheckRate = askInt(fmt.Sprintf("CheckRate [%d]", t.CheckRate)) - - t2, err := c.Tests().Update(t) - if err != nil { - return err - } - - fmt.Printf("UPDATED: \n%+v\n", t2) - - return nil -} - -func usage() { - fmt.Printf("Usage:\n") - fmt.Printf(" %s COMMAND\n", os.Args[0]) - fmt.Printf("Available commands:\n") - for k := range commands { - fmt.Printf(" %+v\n", k) - } -} - -func main() { - username := getEnv("STATUSCAKE_USERNAME") - apikey := getEnv("STATUSCAKE_APIKEY") - - if len(os.Args) < 2 { - usage() - os.Exit(1) - } - - var err error - - c, err := statuscake.New(statuscake.Auth{Username: username, Apikey: apikey}) - if err != nil { - log.Fatal(err) - } - - if cmd, ok := commands[os.Args[1]]; ok { - err = cmd(c, os.Args[2:]...) - } else { - err = fmt.Errorf("Unknown command `%s`", os.Args[1]) - } - - if err != nil { - log.Fatalf("Error running command `%s`: %s", os.Args[1], err.Error()) - } -} 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 @@ -{ - "ErrNo": 0, - "Error": "Can not access account. Was both Username and API Key provided?" -} 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 @@ -[ - { - "TestID": 100, - "Paused": false, - "TestType": "HTTP", - "WebsiteName": "www 1", - "ContactGroup": null, - "ContactID": "1", - "Status": "Up", - "Uptime": 100 - }, - { - "TestID": 101, - "Paused": true, - "TestType": "HTTP", - "WebsiteName": "www 2", - "ContactGroup": null, - "ContactID": "2", - "Status": "Down", - "Uptime": 0 - } -] 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 @@ -{ - "Success": false, - "Error": "this is an error" -} - 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 @@ -{ - "TestID": 6735, - "Affected": 1, - "Success": true, - "Message": "This Check Has Been Deleted. It can not be recovered." -} 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 @@ -{ - "TestID": 6735, - "TestType": "HTTP", - "Paused": false, - "WebsiteName": "NL", - "CustomHeader": "{\"some\":{\"json\": [\"value\"]}}", - "UserAgent": "product/version (comment)", - "ContactGroup": "StatusCake Alerts", - "ContactID": "536", - "Status": "Up", - "Uptime": 0, - "CheckRate": 60, - "Timeout": 40, - "LogoImage": "", - "WebsiteHost": "Various", - "NodeLocations": [ - "UK", - "JP", - "SG1", - "SLC" - ], - "FindString": "", - "DoNotFind": false, - "LastTested": "2013-01-20 14:38:18", - "NextLocation": "USNY", - "Processing": false, - "ProcessingState": "Pretest", - "ProcessingOn": "dalas.localdomain", - "DownTimes": "0", - "UseJar": 0, - "PostRaw": "", - "FinalEndpoint": "", - "FollowRedirect": false -} 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 @@ -{ - "Issues": { - "WebsiteName": "issue a", - "WebsiteURL": "issue b", - "CheckRate": "issue c" - }, - "Success": false, - "Message": "Required Data is Missing." -} 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 @@ -{ - "Issues": ["hello", "world"], - "Success": false, - "Message": "Required Data is Missing." -} 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 @@ -{ - "Issues": {}, - "Success": true, - "Message": "", - "InsertID": 1234 -} -- cgit v1.2.3