Created
December 21, 2016 05:48
-
-
Save 178inaba/5f9c57333af797985358a6db95c69057 to your computer and use it in GitHub Desktop.
Print HipChat status with Go.
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 main | |
import ( | |
"encoding/json" | |
"fmt" | |
"net/http" | |
"os" | |
"time" | |
) | |
func main() { | |
for { | |
start := time.Now() | |
fmt.Printf("Check time: %s\n", start) | |
err := printStatus() | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
fmt.Println() | |
time.Sleep(time.Second*30 - time.Since(start)) | |
} | |
} | |
func printStatus() error { | |
url := "https://88u221he7c.execute-api.us-west-2.amazonaws.com/v1/api/components" | |
resp, err := http.Get(url) | |
if err != nil { | |
return err | |
} | |
var statuses []map[string]interface{} | |
json.NewDecoder(resp.Body).Decode(&statuses) | |
for _, status := range statuses { | |
if status["status"] == "major_outage" { | |
fmt.Printf("%s is outage.\n", status["name"]) | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment