Skip to content

Instantly share code, notes, and snippets.

@dcarley dcarley/apps.go
Last active May 4, 2018

Embed
What would you like to do?
CF apps inspection script
package main
import (
"flag"
"fmt"
"log"
"net/url"
cfclient "github.com/cloudfoundry-community/go-cfclient"
)
// go run apps.go -api "$(cf target | awk '/api endpoint/ {print $3}')" -token "$(cf oauth-token | awk '{print $2}')"
func main() {
var (
api = flag.String("api", "", "hostname")
token = flag.String("token", "", "token")
)
flag.Parse()
config := &cfclient.Config{
ApiAddress: *api,
Token: *token,
}
client, err := cfclient.NewClient(config)
if err != nil {
log.Fatalln(err)
}
params := url.Values{}
apps, err := client.ListAppsByQuery(params)
if err != nil {
log.Fatalln(err)
}
for _, app := range apps {
// Do some stuff with apps here, e.g.
if _, ok := app.Environment["STATSD_ENDPOINT"]; ok {
fmt.Println(app.Name, app.Guid, app.SpaceGuid, app.Environment["METRIC_WHITELIST"])
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.