|
1 | 1 | function Get-ITGlueLogs {
|
2 |
| - [CmdletBinding(DefaultParameterSetName = 'index')] |
3 |
| - Param ( |
4 |
| - [Parameter(ParameterSetName = 'index')] |
5 |
| - [ValidateSet( 'created_at', 'updated_at', '-created_at', '-updated_at' )] |
6 |
| - [String]$sort = '', |
| 2 | +<# |
| 3 | + .SYNOPSIS |
| 4 | + Get all activity logs of the account for the most recent 30 days. |
7 | 5 |
|
8 |
| - [Parameter(ParameterSetName = 'index')] |
9 |
| - [Nullable[Int64]]$page_number = $null, |
| 6 | + .DESCRIPTION |
| 7 | + The Get-ITGlueLogs cmdlet gets all activity logs of the account for the most recent 30 days. |
10 | 8 |
|
11 |
| - [Parameter(ParameterSetName = 'index')] |
12 |
| - [Nullable[int]]$page_size = $null |
13 |
| - ) |
| 9 | + This endpoint is limited to 5 pages of results. If more results are desired, |
| 10 | + setting a larger page [size] will increase the number of results per page. |
14 | 11 |
|
15 |
| - $resource_uri = '/logs' |
| 12 | + To iterate over even more results, use filter [created_at] (with created_at sort) |
| 13 | + to fetch a subset of results based on timestamp, then use the last timestamp |
| 14 | + in the last page the start date in the filter for the next request. |
16 | 15 |
|
17 |
| - if ($PSCmdlet.ParameterSetName -eq 'index') { |
18 |
| - if ($sort) { |
19 |
| - $body += @{'sort' = $sort} |
20 |
| - } |
21 |
| - if ($page_number) { |
22 |
| - $body += @{'page[number]' = $page_number} |
| 16 | + .PARAMETER sort |
| 17 | + Sort the order of the returned data |
| 18 | +
|
| 19 | + Allowed values: |
| 20 | + 'created_at','-created_at' |
| 21 | +
|
| 22 | + .PARAMETER page_number |
| 23 | + The page number to return data from |
| 24 | +
|
| 25 | + This endpoint is limited to 5 pages of results. |
| 26 | +
|
| 27 | + .PARAMETER page_size |
| 28 | + The number of results to return with each page |
| 29 | +
|
| 30 | + By default ITGlues API returned the first 50 items. |
| 31 | +
|
| 32 | + Allowed values: |
| 33 | + 1 - 1000 |
| 34 | +
|
| 35 | + .EXAMPLE |
| 36 | + Get-ITGlueLogs |
| 37 | +
|
| 38 | + Pulls the first 50 activity logs from the last 30 days with data |
| 39 | + being sorted newest to oldest. |
| 40 | +
|
| 41 | + .EXAMPLE |
| 42 | + Get-ITGlueLogs -sort -created_at |
| 43 | +
|
| 44 | + Pulls the first 50 activity logs from the last 30 days with data |
| 45 | + being sorted oldest to newest. |
| 46 | +
|
| 47 | + .EXAMPLE |
| 48 | + Get-ITGlueLogs -page_number 2 |
| 49 | +
|
| 50 | + Pulls the first 50 activity logs starting from page 2 from the last 30 days |
| 51 | + with data being sorted newest to oldest. |
| 52 | +
|
| 53 | + .NOTES |
| 54 | + As of 2022-11 |
| 55 | + Need to add in the "filter[created_at]" parameter |
| 56 | +
|
| 57 | + .LINK |
| 58 | + https://api.itglue.com/developer/#logs |
| 59 | +
|
| 60 | + .LINK |
| 61 | + https://github.com/itglue/powershellwrapper |
| 62 | +
|
| 63 | +#> |
| 64 | + |
| 65 | + [CmdletBinding(DefaultParameterSetName = 'index')] |
| 66 | + Param ( |
| 67 | + [Parameter(ParameterSetName = 'index')] |
| 68 | + [ValidateSet( 'created_at','-created_at' )] |
| 69 | + [String]$sort = '', |
| 70 | + |
| 71 | + [Parameter(ParameterSetName = 'index')] |
| 72 | + [Nullable[Int64]]$page_number = $null, |
| 73 | + |
| 74 | + [Parameter(ParameterSetName = 'index')] |
| 75 | + [ValidateRange ( 1, 1000 )] |
| 76 | + [Nullable[int]]$page_size = $null |
| 77 | + ) |
| 78 | + |
| 79 | + $resource_uri = '/logs' |
| 80 | + |
| 81 | + if ($PSCmdlet.ParameterSetName -eq 'index') { |
| 82 | + if ($sort) { |
| 83 | + $body += @{'sort' = $sort} |
| 84 | + } |
| 85 | + if ($page_number) { |
| 86 | + $body += @{'page[number]' = $page_number} |
| 87 | + } |
| 88 | + if ($page_size) { |
| 89 | + $body += @{'page[size]' = $page_size} |
| 90 | + } |
23 | 91 | }
|
24 |
| - if ($page_size) { |
25 |
| - $body += @{'page[size]' = $page_size} |
| 92 | + |
| 93 | + try { |
| 94 | + $ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password) |
| 95 | + $rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers ` |
| 96 | + -body $body -ErrorAction Stop -ErrorVariable web_error |
| 97 | + } catch { |
| 98 | + Write-Error $_ |
| 99 | + } finally { |
| 100 | + [void] ($ITGlue_Headers.Remove('x-api-key')) # Quietly clean up scope so the API key doesn't persist |
26 | 101 | }
|
27 |
| - } |
28 | 102 |
|
29 |
| - try { |
30 |
| - $ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password) |
31 |
| - $rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers ` |
32 |
| - -body $body -ErrorAction Stop -ErrorVariable $web_error |
33 |
| - } catch { |
34 |
| - Write-Error $_ |
35 |
| - } finally { |
36 |
| - [void] ($ITGlue_Headers.Remove('x-api-key')) # Quietly clean up scope so the API key doesn't persist |
| 103 | + $data = @{} |
| 104 | + $data = $rest_output |
| 105 | + return $data |
37 | 106 | }
|
38 |
| - |
39 |
| - $data = @{} |
40 |
| - $data = $rest_output |
41 |
| - return $data |
42 |
| -} |
|
0 commit comments