Last active
May 4, 2018 10:01
-
-
Save dcarley/eecacbe0be6f6ee718b30482db559904 to your computer and use it in GitHub Desktop.
CF apps inspection script
This file contains 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 ( | |
"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