Skip to content

Commit 7ed6162

Browse files
Merge pull request #28 from joshjohanning/add-enterprise-audit-log
Add enterprise audit log
2 parents deeb1ca + 623fc68 commit 7ed6162

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
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
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
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+
5+
if [ -z "$2" ]; then
6+
echo "Usage: $0 <enterprise> <org> <date>"
7+
echo "Example: ./get-enterprise-audit-log-for-organization.sh avocado-corp joshjohanning-org 2023-09-05"
8+
exit 1
9+
fi
10+
11+
enterprise="$1"
12+
org="$2"
13+
date="$3"
14+
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
18+
fi
19+
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)