Skip to content

Instantly share code, notes, and snippets.

@paulmooring
Created August 28, 2014 00:36
Show Gist options
  • Save paulmooring/e5d477f2d12702516577 to your computer and use it in GitHub Desktop.
Save paulmooring/e5d477f2d12702516577 to your computer and use it in GitHub Desktop.
-- rbenv: 2.1.2 - git: master - knife: rs-prod --------------------- /Users/paul/Github/mon-cli --
-- Wed Aug 27 17:23:54 - paul@galactica $ go run sensu-cli.go -H 192.168.112.120 /clients
[{"name":"i-a8409ba7","address":"192.168.112.94","subscriptions":["base","all"],"timestamp":1409185437},{"name":"i-516cb55e","address":"192.168.112.231","subscriptions":["base","graphite-server","all"],"timestamp":1409185423},{"name":"i-48a37d47","address":"192.168.112.120","subscriptions":["base","sensu-server","all"],"timestamp":1409185436}]
null
-- rbenv: 2.1.2 - git: master - knife: rs-prod --------------------- /Users/paul/Github/mon-cli --
-- Wed Aug 27 17:23:59 - paul@galactica $ go run sensu-cli.go -H 192.168.112.120 /info
{"sensu":{"version":"0.12.6"},"rabbitmq":{"keepalives":{"messages":0,"consumers":1},"results":{"messages":0,"consumers":1},"connected":true},"redis":{"connected":true}}
{
"rabbitmq": {
"connected": true,
"keepalives": {
"consumers": 1,
"messages": 0
},
"results": {
"consumers": 1,
"messages": 0
}
},
"redis": {
"connected": true
},
"sensu": {
"version": "0.12.6"
}
}
func get(serv SensuServer, endpoint string) (error, int, interface{}) {
var content []byte
var dat map[string]interface{}
res, err := http.Get("http://" + serv.Host + ":" + strconv.Itoa(serv.Port) + endpoint)
if err != nil {
content = []byte("")
} else {
content, err = ioutil.ReadAll(res.Body)
res.Body.Close()
}
fmt.Println(string(content))
json.Unmarshal(content, &dat) // Off the wire into data structures
return err, res.StatusCode, dat
}
func get_debug(s SensuServer, ep string) {
err, stat, data := get(s, ep)
body, _ := json.MarshalIndent(data, "", " ")
if err != nil {
Error.Printf("%#v\n", err)
} else if stat != 200 {
Error.Printf("Unexpected HTTP return code: %#v\n", stat)
} else {
fmt.Println(string(body))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment