Created
December 6, 2017 15:02
-
-
Save seeker815/f480192b6439474b8abd3fdb607e3935 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package checks | |
import ( | |
"fmt" | |
"time" | |
"strings" | |
maps "github.com/ashwanthkumar/golang-utils/maps" | |
"github.com/gambol99/go-marathon" | |
) | |
// Checks App health status periodically (configurable -5m) | |
// Get App Endpoint by reading router.hosts and Check for 200 status code | |
func Check(app marathon.Application) AppCheck { | |
host := maps.GetString(app.Labels, "router.hosts", "notDefined") | |
host_path := app.HealthChecks.path | |
host_url = strings.Join("http://", host, host_path) | |
result := Pass | |
resp, err := http.Get(host_url) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
log.Fatal(err) | |
} | |
responseString := string(body) | |
fmt.Println(responseString) | |
fmt.Println("HTTP Response Status: " + strconv.Itoa(resp.StatusCode)) | |
if resp.StatusCode >= 200 && resp.StatusCode <= 299 { | |
result = Pass | |
message = fmt.Println("HTTP Status OK!") | |
} else { | |
result = Critical | |
message = fmt.Printf("Critical, brokem") | |
} | |
return AppCheck{ | |
App: app.ID, | |
Labels: app.Labels, | |
CheckName: n.Name(), | |
Result: result, | |
Message: message, | |
Timestamp: time.Now(), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment