Skip to content

Instantly share code, notes, and snippets.

@178inaba
Created December 21, 2016 05:48
Show Gist options
  • Save 178inaba/5f9c57333af797985358a6db95c69057 to your computer and use it in GitHub Desktop.
Save 178inaba/5f9c57333af797985358a6db95c69057 to your computer and use it in GitHub Desktop.
Print HipChat status with Go.
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