Skip to content

Commit 623fc68

Browse files
committed
adding updated version with date
1 parent 7800061 commit 623fc68

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

gh-cli/README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,16 @@ In a 1 year block, return the date of the first non-public contribution
492492

493493
See also: [Another example](https://github.com/orgs/community/discussions/24427#discussioncomment-3244093)
494494

495-
## get-enterprise-id.sh
495+
### get-enterprise-audit-log-for-organization.sh
496+
497+
This queries the [Enterprise audit log API](https://docs.github.com/en/enterprise-cloud@latest/admin/monitoring-activity-in-your-enterprise/reviewing-audit-logs-for-your-enterprise/using-the-audit-log-api-for-your-enterprise) to specifically return if features have been enabled or disabled in an organization since a given date.
498+
499+
Additional resources:
500+
501+
- [Using the audit log API for your enterprise](https://docs.github.com/en/enterprise-cloud@latest/admin/monitoring-activity-in-your-enterprise/reviewing-audit-logs-for-your-enterprise/using-the-audit-log-api-for-your-enterprise)
502+
- [Searching the audit log for your enterprise](https://docs.github.com/en/enterprise-cloud@latest/admin/monitoring-activity-in-your-enterprise/reviewing-audit-logs-for-your-enterprise/searching-the-audit-log-for-your-enterprise)
503+
- [Get the audit log for an enterprise](https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/audit-log?apiVersion=2022-11-28#get-the-audit-log-for-an-enterprise)
504+
496505
### get-enterprise-id.sh
497506

498507
Get the enterprise ID used for other GraphQL calls. Use the URL slug of the Enterprise as the input.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
#!/bin/bash
22

3+
# This queries the Enterprise audit log APIs to specifically return if features have been enabled or disabled in an organization since a given date
4+
35
if [ -z "$2" ]; then
4-
echo "Usage: $0 <enterprise> <org> <optional: actor>"
6+
echo "Usage: $0 <enterprise> <org> <date>"
7+
echo "Example: ./get-enterprise-audit-log-for-organization.sh avocado-corp joshjohanning-org 2023-09-05"
58
exit 1
69
fi
710

811
enterprise="$1"
912
org="$2"
10-
actor="$3" # this is optional, but adding it can really filter down results
13+
date="$3"
1114

12-
if [ -z "$actor" ]; then
13-
actor_field="-f \"phrase=actor:$actor\""
15+
# if date is empty, default to yesterdays date
16+
if [ -z "$date" ]; then
17+
date=$(gdate -d "yesterday" +%Y-%m-%d) # if on linux, change from gdate to date
1418
fi
1519

16-
# we are using JQ to look for when things have specifically been enable[d] or disable[d] at the organization level
17-
gh api -X GET "/enterprises/$enterprise/audit-log" $actor_field -f per_page=100 | jq --arg org "$org" '.[] | select(.org == $org) | select(.action | test("disable[d]?|enable[d]?")) | {action, actor, org, "@timestamp"} | .["@timestamp"] /= 1000 | .["@timestamp"] |= strftime("%Y-%m-%d %H:%M:%S")'
20+
# take note of rate limits: Each audit log API endpoint has a rate limit of 1,750 queries per hour for a given combination of user and IP address
21+
# - may receive errors and partial results if user does not have admin rights to all organizations / repositories
22+
23+
gh api -X GET --paginate "/enterprises/$enterprise/audit-log" -f "phrase=org:$org+created:>=$date" -f per_page=100 | \
24+
sed 's/{"message":"Must have admin rights to Repository.","documentation_url":"https:\/\/docs.github.com\/rest\/enterprise-admin\/audit-log#get-the-audit-log-for-an-enterprise"}/]/g' | \
25+
jq '.[] | select(.action | test("disable[d]?|enable[d]?")) | {action, actor, org, "@timestamp"} | .["@timestamp"] /= 1000 | .["@timestamp"] |= strftime("%Y-%m-%d %H:%M:%S")'

0 commit comments

Comments
 (0)