Skip to content

Instantly share code, notes, and snippets.

@dcarley
Last active May 4, 2018 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcarley/eecacbe0be6f6ee718b30482db559904 to your computer and use it in GitHub Desktop.
Save dcarley/eecacbe0be6f6ee718b30482db559904 to your computer and use it in GitHub Desktop.
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