Skip to content

Commit f58751d

Browse files
authored
Merge pull request #139 from Celerium/master
New Get-ITGlueLogs & Added support for the Australian datacenter
2 parents aaffb8e + 1fb4828 commit f58751d

File tree

12 files changed

+147
-31
lines changed

12 files changed

+147
-31
lines changed

ITGlueAPI/ITGlueAPI.psd1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
'Resources/FlexibleAssetTypes.ps1',
8989
'Resources/Groups.ps1',
9090
'Resources/Locations.ps1',
91+
'Resources/Logs.ps1',
9192
'Resources/Manufacturers.ps1',
9293
'Resources/Models.ps1',
9394
'Resources/OperatingSystems.ps1',
@@ -149,7 +150,7 @@
149150
'Set-ITGlueDocuments',
150151

151152
'Get-ITGlueDomains',
152-
153+
153154
'Get-ITGlueExpirations',
154155

155156
'New-ITGlueFlexibleAssetFields',
@@ -173,6 +174,8 @@
173174
'Set-ITGlueLocations',
174175
'Remove-ITGlueLocations',
175176

177+
'Get-ITGlueLogs',
178+
176179
'New-ITGlueManufacturers',
177180
'Get-ITGlueManufacturers',
178181
'Set-ITGlueManufacturers',

ITGlueAPI/ITGlueAPI.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
$ITGlue_Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
2-
$ITGlue_Headers.Add("Content-Type", 'application/vnd.api+json')
1+
$ITGlue_Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
2+
$ITGlue_Headers.Add("Content-Type", 'application/vnd.api+json')
33

44
Set-Variable -Name "ITGlue_Headers" -Value $ITGlue_Headers -Scope global
55

ITGlueAPI/Internal/BaseURI.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ function Add-ITGlueBaseURI {
55
[string]$base_uri = 'https://api.itglue.com',
66

77
[Alias('locale','dc')]
8-
[ValidateSet( 'US', 'EU')]
8+
[ValidateSet( 'US', 'EU', 'AU')]
99
[String]$data_center = ''
1010
)
1111

12-
# Trim superflous forward slash from address (if applicable)
12+
# Trim superfluous forward slash from address (if applicable)
1313
if($base_uri[$base_uri.Length-1] -eq "/") {
1414
$base_uri = $base_uri.Substring(0,$base_uri.Length-1)
1515
}
1616

1717
switch ($data_center) {
1818
'US' {$base_uri = 'https://api.itglue.com'}
1919
'EU' {$base_uri = 'https://api.eu.itglue.com'}
20+
'AU' {$base_uri = 'https://api.au.itglue.com'}
2021
Default {}
2122
}
2223

2324
Set-Variable -Name "ITGlue_Base_URI" -Value $base_uri -Option ReadOnly -Scope global -Force
2425
}
2526

2627
function Remove-ITGlueBaseURI {
27-
Remove-Variable -Name "ITGlue_Base_URI" -Scope global -Force
28+
Remove-Variable -Name "ITGlue_Base_URI" -Scope global -Force
2829
}
2930

3031
function Get-ITGlueBaseURI {

ITGlueAPI/Internal/ModuleSettings.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Import-ITGlueModuleSettings {
2727
if(test-path ($ITGlueAPIConfPath+"\"+$ITGlueAPIConfFile) ) {
2828
$tmp_config = Import-LocalizedData -BaseDirectory $ITGlueAPIConfPath -FileName $ITGlueAPIConfFile
2929

30-
# Send to function to strip potentially superflous slash (/)
30+
# Send to function to strip potentially superfluous slash (/)
3131
Add-ITGlueBaseURI $tmp_config.ITGlue_Base_URI
3232

3333
$tmp_config.ITGlue_API_key = ConvertTo-SecureString $tmp_config.ITGlue_API_key
@@ -36,7 +36,7 @@ function Import-ITGlueModuleSettings {
3636
-Option ReadOnly -Scope global -Force
3737

3838
Set-Variable -Name "ITGlue_JSON_Conversion_Depth" -Value $tmp_config.ITGlue_JSON_Conversion_Depth `
39-
-Scope global -Force
39+
-Scope global -Force
4040

4141
Write-Host "ITGlueAPI Module configuration loaded successfully from $ITGlueAPIConfPath\$ITGlueAPIConfFile!" -ForegroundColor Green
4242

@@ -45,12 +45,12 @@ function Import-ITGlueModuleSettings {
4545
}
4646
else {
4747
Write-Host "No configuration file was found at $ITGlueAPIConfPath\$ITGlueAPIConfFile." -ForegroundColor Red
48-
48+
4949
Set-Variable -Name "ITGlue_Base_URI" -Value "https://api.itglue.com" -Option ReadOnly -Scope global -Force
50-
50+
5151
Write-Host "Using https://api.itglue.com as Base URI. Run Add-ITGlueBaseURI to modify."
5252
Write-Host "Please run Add-ITGlueAPIKey to get started." -ForegroundColor Red
53-
53+
5454
Set-Variable -Name "ITGlue_JSON_Conversion_Depth" -Value 100 -Scope global -Force
5555
}
5656
}

ITGlueAPI/Resources/Attachments.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function New-ITGlueAttachments {
22
[CmdletBinding()]
33
Param (
4-
[Parameter(Mandatory = $true)]
4+
[Parameter(Mandatory = $true)]
55
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
66
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
77
[string]$resource_type,
@@ -32,14 +32,14 @@ function New-ITGlueAttachments {
3232
}
3333

3434
$data = @{}
35-
$data = $rest_output
35+
$data = $rest_output
3636
return $data
3737
}
3838

3939
function Set-ITGlueAttachments {
4040
[CmdletBinding()]
4141
Param (
42-
[Parameter(Mandatory = $true)]
42+
[Parameter(Mandatory = $true)]
4343
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
4444
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
4545
[string]$resource_type,
@@ -74,14 +74,14 @@ function Set-ITGlueAttachments {
7474
}
7575

7676
$data = @{}
77-
$data = $rest_output
77+
$data = $rest_output
7878
return $data
7979
}
8080

8181
function Remove-ITGlueAttachments {
8282
[CmdletBinding()]
8383
Param (
84-
[Parameter(Mandatory = $true)]
84+
[Parameter(Mandatory = $true)]
8585
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
8686
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
8787
[string]$resource_type,
@@ -112,6 +112,6 @@ function Remove-ITGlueAttachments {
112112
}
113113

114114
$data = @{}
115-
$data = $rest_output
115+
$data = $rest_output
116116
return $data
117117
}

ITGlueAPI/Resources/Documents.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ function Set-ITGlueDocuments {
3636
}
3737

3838
$data = @{}
39-
$data = $rest_output
39+
$data = $rest_output
4040
return $data
4141
}

ITGlueAPI/Resources/Expirations.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Get-ITGlueExpirations {
2222

2323
[Parameter(ParameterSetName = 'index')]
2424
[String]$filter_expiration_date = '',
25-
25+
2626
[Parameter(ParameterSetName = 'index')]
2727
[Int64]$filter_organization_id = '',
2828

ITGlueAPI/Resources/Logs.ps1

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
function Get-ITGlueLogs {
2+
<#
3+
.SYNOPSIS
4+
Get all activity logs of the account for the most recent 30 days.
5+
6+
.DESCRIPTION
7+
The Get-ITGlueLogs cmdlet gets all activity logs of the account for the most recent 30 days.
8+
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.
11+
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.
15+
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+
}
91+
}
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
101+
}
102+
103+
$data = @{}
104+
$data = $rest_output
105+
return $data
106+
}

ITGlueAPI/Resources/Organizations.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function Get-ITGlueOrganizations {
5050

5151
[Parameter(ParameterSetName = 'index')]
5252
[Nullable[Int64]]$filter_my_glue_account_id = $null,
53-
53+
5454
[Parameter(ParameterSetName = 'index')]
5555
[Nullable[Int64]]$filter_group_id = $null,
5656

ITGlueAPI/Resources/RelatedItems.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function New-ITGlueRelatedItems {
22
[CmdletBinding()]
33
Param (
4-
[Parameter(Mandatory = $true)]
4+
[Parameter(Mandatory = $true)]
55
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
66
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
77
[string]$resource_type,
@@ -32,14 +32,14 @@ function New-ITGlueRelatedItems {
3232
}
3333

3434
$data = @{}
35-
$data = $rest_output
35+
$data = $rest_output
3636
return $data
3737
}
3838

3939
function Set-ITGlueRelatedItems {
4040
[CmdletBinding()]
4141
Param (
42-
[Parameter(Mandatory = $true)]
42+
[Parameter(Mandatory = $true)]
4343
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
4444
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
4545
[string]$resource_type,
@@ -74,14 +74,14 @@ function Set-ITGlueRelatedItems {
7474
}
7575

7676
$data = @{}
77-
$data = $rest_output
77+
$data = $rest_output
7878
return $data
7979
}
8080

8181
function Remove-ITGlueRelatedItems {
8282
[CmdletBinding()]
8383
Param (
84-
[Parameter(Mandatory = $true)]
84+
[Parameter(Mandatory = $true)]
8585
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
8686
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
8787
[string]$resource_type,
@@ -112,6 +112,6 @@ function Remove-ITGlueRelatedItems {
112112
}
113113

114114
$data = @{}
115-
$data = $rest_output
115+
$data = $rest_output
116116
return $data
117117
}

ITGlueAPI/Tests/BaseURI.Tests.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@ $ThisFileName = $ThisFile | Split-Path -Leaf
66

77
Describe "Tests" {
88
Context "Test $ThisFileName Functions" {
9-
It "Add-ITGlueBaseURI without parameter should reutrn a valid URI" {
9+
It "Add-ITGlueBaseURI without parameter should return a valid URI" {
1010
Add-ITGlueBaseURI
1111
$BaseURI = Get-ITGlueBaseURI
1212
$BaseURI | Should -Be 'https://api.itglue.com'
1313
}
14-
It "Add-ITGlueBaseURI parameter US should reutrn a valid URI" {
14+
It "Add-ITGlueBaseURI parameter US should return a valid URI" {
1515
Add-ITGlueBaseURI -data_center 'US'
1616
$BaseURI = Get-ITGlueBaseURI
1717
$BaseURI | Should -Be 'https://api.itglue.com'
1818
}
19-
It "Add-ITGlueBaseURI parameter EU should reutrn a valid URI" {
19+
It "Add-ITGlueBaseURI parameter EU should return a valid URI" {
2020
Add-ITGlueBaseURI -data_center 'EU'
2121
$BaseURI = Get-ITGlueBaseURI
2222
$BaseURI | Should -Be 'https://api.eu.itglue.com'
2323
}
24+
It "Add-ITGlueBaseURI parameter AU should return a valid URI" {
25+
Add-ITGlueBaseURI -data_center 'AU'
26+
$BaseURI = Get-ITGlueBaseURI
27+
$BaseURI | Should -Be 'https://api.au.itglue.com'
28+
}
2429
It "Remove-ITGlueBaseURI should remove the variable" {
2530
Remove-ITGlueBaseURI
2631
$BaseURI = Get-ITGlueBaseURI

ITGlueAPI/Tests/ITGlueAPI.Tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ $ResourceDirectoryFiles = (
4242
'FlexibleAssetTypes.ps1',
4343
'Groups.ps1',
4444
'Locations.ps1',
45+
'Logs.ps1',
4546
'Manufacturers.ps1',
4647
'Models.ps1',
4748
'OperatingSystems.ps1',
@@ -137,10 +138,10 @@ Describe "Module Tests" {
137138
}
138139
# TODO - add tests to check for tests files
139140
}
140-
141+
141142
Context "PowerShell $ThisModuleName Import Test" {
142143
# Credit - borrowed with care from https://github.com/TheMattCollins0/MattTools/blob/master/Tests/ModuleImport.Tests.ps1 and modified as needed
143-
It "Should import PowerShell $ThisModuleName succesfully" {
144+
It "Should import PowerShell $ThisModuleName successfully" {
144145
Import-Module -Name $ThisModulePath -ErrorVariable ImportError
145146
$ImportError | Should Be $null
146147
}

0 commit comments

Comments
 (0)