Created
April 3, 2018 15:11
-
-
Save srpomeroy/5bb5afe379845f1d5a83138aa83a8c84 to your computer and use it in GitHub Desktop.
Get RightScale account audit entries for the past hour
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
# Gets Audit Entries from a RightScale account for the past hour. | |
# Relies on Instance Auth for API access | |
# Currently just adds all audits to an object to allow for manipulation or forwarding | |
$tz = "-0000" | |
$now = Get-Date | |
$endDate = Get-Date $now -Format "yyyy/MM/dd HH:mm:ss" | |
$startDate = Get-Date (Get-Date $now).AddHours(-1) -Format "yyyy/MM/dd HH:mm:ss" | |
# Audit Entries - Index: http://reference.rightscale.com/api1.5/resources/ResourceAuditEntries.html#index | |
$auditEntries = rsc.exe --rl10 cm15 index audit_entries "start_date=$startDate $tz" "end_date=$endDate $tz" "limit=1000" | ConvertFrom-Json | |
$allEntryObjects = @() | |
foreach ($auditEntry in $auditEntries) { | |
$selfHref = $auditEntry.links | Where-Object { $_.rel -eq "self"} | Select-Object -ExpandProperty href | |
$auditeeHref = $auditEntry.links | Where-Object { $_.rel -eq "auditee"} | Select-Object -ExpandProperty href | |
$detailHref = $auditEntry.links | Where-Object { $_.rel -eq "detail"} | Select-Object -ExpandProperty href | |
$entryTime = $auditEntry.updated_at | |
$entryEmail = $auditEntry.user_email | |
$entrySummary = $auditEntry.summary | |
# Audit Entries - Detail: http://reference.rightscale.com/api1.5/resources/ResourceAuditEntries.html#detail | |
$entryDetail = rsc.exe --rl10 cm15 detail $detailHref | |
$entryObject = [PSCustomObject]@{ | |
Time = $entryTime | |
Href = $selfHref | |
Summary = $entrySummary | |
Email = $entryEmail | |
Detail = $entryDetail | |
} | |
$allEntryObjects += $entryObject | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment