Skip to content

Instantly share code, notes, and snippets.

@keymon
Created December 10, 2018 13:21
Show Gist options
  • Save keymon/d5155ebd98c4249700455a422d7cb6bd to your computer and use it in GitHub Desktop.
Save keymon/d5155ebd98c4249700455a422d7cb6bd to your computer and use it in GitHub Desktop.
Iterate `cf curl` responses page by page and group all the underlying `.resources[]`
#!/bin/bash
SCRIPT="$0"
set -eu -o pipefail
help() {
cat <<EOF
Executes a cf curl and iterates across all the pages returned by CF,
aggregating the resources in a big json.
e.g.:
${SCRIPT} /v2/apps?results-per-page=100
EOF
}
next_url="$1"
while [ -n "${next_url}" ] && [ "${next_url}" != "null" ] ; do
echo "Querying ${next_url}..." 1>&2
json_output="$(cf curl "${next_url}")"
next_url="$(echo "${json_output}" | jq -r .next_url)"
echo "${json_output}" | jq -r '.resources[]'
done | jq -s '{ "resources": . }'
#!/bin/bash
# Gets all events in last hours
scripts/regex_get_apps.sh "/v2/events?q=timestamp>$(date -d '1 hour ago' --iso-8601=seconds)Z&order-by=timestamp&order-by=id&order-direction=desc&results-per-page=100" > /tmp/events.json
cat /tmp/events.json | jq -r '.resources[] | "\(.metadata.created_at) \(.entity.actor_type) \(.entity.actor_username) \(.entity.type) \(.entity.actee_type) \(.entity.actee_name)"' | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment