Functions/Public/IntegrationsOther.ps1
|
# WebRTC, Genesys, Cisco, and Cloud Agent functions Function Get-NectarCiscoCluster { <# .SYNOPSIS Return base information about all Cisco clusters .DESCRIPTION Return base information about all Cisco clusters .PARAMETER ClusterName Return the cluster matching the given name .PARAMETER TimePeriod The time period to show event data from. Select from 'LAST_HOUR','LAST_DAY','LAST_WEEK'. .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .EXAMPLE Get-NectarCiscoCluster .NOTES Version 1.0 #> Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$ClusterName, [Parameter(Mandatory=$False)] [ValidateSet('LAST_HOUR','LAST_DAY','LAST_WEEK', IgnoreCase=$True)] [string]$TimePeriod = 'LAST_DAY', [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$TenantName, [Parameter(Mandatory=$False)] [ValidateRange(1,100000)] [int]$PageSize = 1000 ) Begin { Connect-NectarCloud } Process { Try { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } ElseIf ($TenantName) { If ($TenantName -NotIn $Global:NectarTenantList) { $TList = $Global:NectarTenantList -join ', ' Throw "Could not find a tenant with the name $TenantName on https://$Global:NectarCloud. Select one of $TList. $($_.Exception.Message)" } } $FilterSession = Set-NectarFilterParams -Scope DEFAULT -Platform CISCO -TenantName $TenantName -TimePeriod $TimePeriod $URI = "https://$Global:NectarCloud/dapi/platform/clusters?pageSize=$PageSize&platform=CISCO&tenant=$TenantName" Write-Verbose $URI $Results = (Invoke-RestMethod -Method GET -URI $URI -Headers $Global:NectarAuthHeader -WebSession $FilterSession).elements If ($TenantName) {$Results | Add-Member -Name 'TenantName' -Value $TenantName -MemberType NoteProperty} If ($ClusterName) { $Results = $Results | Where-Object {$_.name -like "*$ClusterName*"} } Return $Results } Catch { Write-Error "Could not get platform items. $($_.Exception.Message)" If ($PSCmdlet.MyInvocation.BoundParameters["ErrorAction"] -ne "SilentlyContinue") { Get-JSONErrorStream -JSONResponse $_ } } } } Function Get-NectarCiscoClusterInventory { <# .SYNOPSIS Return inventory information for a given Cisco cluster .DESCRIPTION Return inventory information for a given Cisco cluster .PARAMETER ClusterID The Nectar-defined ClusterID for the given cluster. Accepts pipelined results .PARAMETER InventorySet What specified inventory set to pull information about .PARAMETER SearchQuery A string to search for. Will search for match against all fields .PARAMETER OrderByField Sort the output by the selected field .PARAMETER OrderDirection Sort ordered output in ascending or descending order .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .PARAMETER PageSize The size of the page used to return data. Defaults to 10000 .PARAMETER ResultSize The total number of results to return. Maximum result size is 9,999,999 results .EXAMPLE Get-NectarCiscoClusterInventory -ClusterID 39_1 -InventorySet CallManagers Returns information about the call managers for the specified clusterID .EXAMPLE Get-NectarCiscoCluster | Get-NectarCiscoClusterInventory -InventorySet Gateways Returns information about gateways from all Cisco clusters .NOTES Version 1.0 #> Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)] [string]$ClusterID, [Parameter(Mandatory=$True)] [ValidateSet('Annunciators','ApplicationServers','AssignedPresenceServers','CallManagers','ConferenceBridges','DevicePools','Gatekeepers','Gateways','GatewayEndpoints','H323Gateways','HuntLists','HuntPilots','InteractiveVoiceResponses','LicenseUsers','Locations','Mtp','MusicOnholdServers','Phones','RecordingProfiles','Services','SipTrunk','Transcoders','Users','VoiceMailPilots','VoiceMailPorts', IgnoreCase=$True)] [string]$InventorySet, [Parameter(Mandatory=$False)] [string]$SearchQuery, [Parameter(Mandatory=$False)] [string]$OrderByField = 'idx', [Parameter(Mandatory=$False)] [ValidateSet('asc', 'desc', IgnoreCase=$True)] [string]$OrderDirection = 'asc', [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$TenantName, [Parameter(Mandatory=$False)] [ValidateRange(1,999999)] [int]$PageSize = 10000, [Parameter(Mandatory=$False)] [ValidateRange(1,999999)] [int]$ResultSize, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$Name ) Begin { Connect-NectarCloud } Process { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } # The URLs for each inventory set is usually split on capital letters # This little function takes care of that # EG: MySampleTests turns into /my/sample/tests $InventoryURL = ($InventorySet -CReplace '([A-Z])', '/$1').ToLower() # Take care of any cases that don't match the above rule Switch ($InventorySet) { 'HuntLists' { $InventoryURL = '/hunts'; Break} } # Set the page size to the result size if -ResultSize switch is used to limit the number of returned items # Otherwise, set page size (defaults to 1000) If ($ResultSize) { $PageSize = $ResultSize } $Params = @{ 'pageNumber' = 1 'pageSize' = $PageSize 'orderByField' = $OrderByField 'orderDirection' = $OrderDirection 'platform' = 'CISCO' 'tenant' = $TenantName } If ($SearchQuery) { $Params.Add('q', $SearchQuery) } $URI = "https://$Global:NectarCloud/dapi/platform/cluster/$ClusterID/inventory$InventoryURL" Write-Verbose $URI $Results = Invoke-RestMethod -Method GET -URI $URI -Headers $Global:NectarAuthHeader -Body $Params $TotalPages = $Results.totalPages If ($TenantName) { $Results.elements | Add-Member -Name 'TenantName' -Value $TenantName -MemberType NoteProperty } If ($Name) { $Results.elements | Add-Member -Name 'ClusterName' -Value $Name -MemberType NoteProperty } $Results.elements If ($TotalPages -gt 1 -and !($ResultSize)) { $PageNum = 2 Write-Verbose "Page size: $PageSize" While ($PageNum -le $TotalPages) { Write-Verbose "Working on page $PageNum of $TotalPages" $Params.PageNumber = $PageNum $Results = Invoke-RestMethod -Method GET -URI $URI -Headers $Global:NectarAuthHeader -Body $Params If ($TenantName) {$Results.elements | Add-Member -Name 'TenantName' -Value $TenantName -MemberType NoteProperty} If ($Name) { $Results.elements | Add-Member -Name 'ClusterName' -Value $Name -MemberType NoteProperty } $Results.elements $PageNum++ } } } } ################################################################################################################################################# # # # Platform Functions # # # Function New-NectarGenesysConfig { <# .SYNOPSIS Enables Genesys Cloud integration with Nectar DXP .DESCRIPTION Enables Genesys Cloud integration with Nectar DXP. Requires a global admin account. Not available to tenant-level admins. .PARAMETER DisplayName The display name for the configuration. Defaults to 'Genesys Cloud tenantname'. Can only contain letters, numbers and spaces. .PARAMETER AWSEventBus The AWS Event bus URL for the application. .PARAMETER AWSRegion The AWS cloud region where the event bus resides .PARAMETER GenesysOAuthClientID The OAuth Client ID of the Genesys Cloud application. .PARAMETER GenesysOAuthClientSecret The OAuth Client secret of the Genesys Cloud application. .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .NOTES Version 1.0 #> Param ( [ValidatePattern("^[a-zA-Z0-9 ]+$")] [Parameter(ValueFromPipelineByPropertyName, HelpMessage = "Display name can only contain letters, numbers and spaces", Mandatory=$False)] [string]$DisplayName, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)] [string]$AWSEventBus, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)][ValidateSet( "us-east-1", "us-east-2", "us-west-1", "us-west-2", "af-south-1", "ap-east-1", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ca-central-1", "ca-west-1", "eu-central-1", "eu-central-2", "eu-west-1", "eu-west-2", "eu-west-3", "eu-north-1", "eu-south-1", "eu-south-2", "il-central-1", "me-central-1", "me-south-1", "sa-east-1", "us-gov-east-1", "us-gov-west-1", "cn-north-1", "cn-northwest-1" )] [string]$AWSRegion, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)] [string]$GenesysOAuthClientID, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)] [string]$GenesysOAuthClientSecret, [Parameter(Mandatory=$False)] [string]$TenantName ) Begin { Connect-NectarCloud } Process { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } ElseIf ($TenantName) { If ($TenantName -NotIn $Global:NectarTenantList) { $TList = $Global:NectarTenantList -join ', ' Throw "Could not find a tenant with the name $TenantName on https://$Global:NectarCloud. Select one of $TList. $($_.Exception.Message)" } } $CloudAgentList = Get-NectarCloudAgent If ($CloudAgentList.Count -gt 1) { $CloudAgentName = Select-FromList -Prompt 'Multiple cloud agents found. Pick the desired cloud agent from the below list:' -Items $CloudAgentList.cloudAgentName } Else { $CloudAgentName = $CloudAgentList[0].cloudAgentName } If (!$PSBoundParameters.ContainsKey('DisplayName')) { $DisplayName = "Genesys Cloud $TenantName" } # Build the JSON body for creating the config $Body = @{ awsApiKey = '' awsEventBus = $AWSEventBus cloudAgentName = $CloudAgentName cloudRegion = $AWSRegion.Replace('-','_') displayName = $DisplayName oauthClientId = $GenesysOAuthClientID oauthClientSecret = $GenesysOAuthClientSecret tenant = $TenantName } $URI = "https://$($Global:NectarCloud)/aapi/clouddatasources/configuration/genesys?tenant=$TenantName" Write-Verbose $URI $JSONBody = $Body | ConvertTo-Json Write-Verbose $JSONBody $JSON = Invoke-RestMethod -Method POST -URI $URI -Headers $Global:NectarAuthHeader -Body $JSONBody -ContentType 'application/json' Return $JSON.data } } ################################################################################################################################################# # # # Zoom Functions # # # Function Get-NectarWebRTCConfig { <# .SYNOPSIS Return information about an existing WebRTC call data integration with Nectar DXP .DESCRIPTION Return information about an existing WebRTC call data integration with Nectar DXP. Requires a global admin account. Not available to tenant-level admins. .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .EXAMPLE Get-NectarWebRTCConfig .NOTES Version 1.0 #> Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$TenantName ) Begin { Connect-NectarCloud } Process { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } ElseIf ($TenantName) { If ($TenantName -NotIn $Global:NectarTenantList) { $TList = $Global:NectarTenantList -join ', ' Throw "Could not find a tenant with the name $TenantName on https://$Global:NectarCloud. Select one of $TList. $($_.Exception.Message)" } } # Get the existing WebRTC configuration $URI = "https://$Global:NectarCloud/aapi/configuration/webrtc?tenant=$TenantName" Write-Verbose $URI $Body = (Invoke-RestMethod -Method GET -URI $URI -Headers $Global:NectarAuthHeader).data Return $Body } } Function Set-NectarWebRTCConfig { <# .SYNOPSIS Modify an existing WebRTC call data integration with Nectar DXP .DESCRIPTION Modify an existing WebRTC call data integration with Nectar DXP. Requires a global admin account. Not available to tenant-level admins. .PARAMETER Platforms One or more platforms to pull WebRTC call data from .PARAMETER DisplayName The internal display name of the WebRTC configuration .PARAMETER RTCCollectionIntervalSecs How often (in seconds) to sample call quality data. Defaults to 60 .PARAMETER LoginRefreshIntervalSecs How often (in seconds) to refresh login credentials for client WebRTC connections. Defaults to 86400 (1 day). .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .EXAMPLE Set-NectarWebRTCConfig -CertID .NOTES Version 1.0 #> [cmdletbinding(SupportsShouldProcess, ConfirmImpact = 'High')] Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [ValidateSet('Teams','Zoom','AirBnB','CiscoWebEx', IgnoreCase=$False)] [string[]]$Platforms, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$DisplayName, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [int]$RTCCollectionIntervalSecs, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [int]$LoginRefreshIntervalSecs, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$TenantName ) Begin { Connect-NectarCloud } Process { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } ElseIf ($TenantName) { If ($TenantName -NotIn $Global:NectarTenantList) { $TList = $Global:NectarTenantList -join ', ' Throw "Could not find a tenant with the name $TenantName on https://$Global:NectarCloud. Select one of $TList. $($_.Exception.Message)" } } # Get the existing WebRTC config details $Body = (Get-NectarWebRTCConfig)[0] $URI = "https://$Global:NectarCloud/aapi/configuration/webrtc/$($Body.id)" Write-Verbose $URI # Remove extraneous details $Body.psobject.Properties.Remove('Id') $Body.psobject.Properties.Remove('stateId') $Body.psobject.Properties.Remove('lastUpdatedTime') $Body.psobject.Properties.Remove('clientId') $Body.psobject.Properties.Remove('kafkaTopic') $Body.psobject.Properties.Remove('sourceId') $Body | Add-Member -MemberType NoteProperty -Name 'tenant' -Value $TenantName # Update with entered parameters ForEach ($Param in $PSBoundParameters.GetEnumerator()) { $Body.($Param.key) = $Param.value } $JSONBody = $Body | ConvertTo-Json Write-Verbose $JSONBody If ($PSCmdlet.ShouldProcess(("Updating Nectar DXP WebRTC config on tenant {0}" -f $TenantName), ("Update Nectar DXP WebRTC config on tenant {0}?" -f $TenantName), 'Nectar DXP WebRTC Config Update')) { Try { $NULL = Invoke-RestMethod -Method PUT -URI $URI -Headers $Global:NectarAuthHeader -Body $JSONBody -ContentType 'application/json; charset=utf-8' } Catch { If ($PSCmdlet.MyInvocation.BoundParameters["ErrorAction"] -ne "SilentlyContinue") { Get-JSONErrorStream -JSONResponse $_ } } } } } Function New-NectarWebRTCConfig { <# .SYNOPSIS Enables WebRTC call data integration with Nectar DXP .DESCRIPTION Enables WebRTC call data integration with Nectar DXP. Requires a global admin account. Not available to tenant-level admins. .PARAMETER Platforms One or more platforms to pull WebRTC call data from .PARAMETER DisplayName The internal display name of the WebRTC configuration .PARAMETER RTCCollectionIntervalSecs How often (in seconds) to sample call quality data. Defaults to 60 .PARAMETER LoginRefreshIntervalSecs How often (in seconds) to refresh login credentials for client WebRTC connections. Defaults to 86400 (1 day). .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .EXAMPLE New-NectarWebRTCConfig .NOTES Version 1.0 #> Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)] [ValidateSet('Teams','Zoom','AirBnB','CiscoWebEx', IgnoreCase=$False)] [string[]]$Platforms, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$DisplayName = 'WebRTC', [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [int]$RTCCollectionIntervalSecs = 60, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [int]$LoginRefreshIntervalSecs = 86400, [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$TenantName ) Begin { Connect-NectarCloud } Process { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } ElseIf ($TenantName) { If ($TenantName -NotIn $Global:NectarTenantList) { $TList = $Global:NectarTenantList -join ', ' Throw "Could not find a tenant with the name $TenantName on https://$Global:NectarCloud. Select one of $TList. $($_.Exception.Message)" } } $URI = "https://$Global:NectarCloud/aapi/configuration/webrtc" Write-Verbose $URI # Check for existing Teams/Azure config # Will increment the sourceID if one already exists [int]$WebRTCSourceID = ((Get-NectarWebRTCConfig -ErrorAction:SilentlyContinue).sourceID | Measure-Object -Maximum).Maximum + 1 # Build the JSON body for creating the config $Body = @{ tenant = $TenantName platforms = $Platforms displayName = $DisplayName rtcCollectionIntervalSecs = $RTCCollectionIntervalSecs loginRefreshIntervalSecs = $LoginRefreshIntervalSecs sourceId = $WebRTCSourceID } $JSONBody = $Body | ConvertTo-Json Write-Verbose $JSONBody Try { $NULL = Invoke-RestMethod -Method POST -URI $URI -Headers $Global:NectarAuthHeader -Body $JSONBody -ContentType 'application/json; charset=utf-8' } Catch { If ($PSCmdlet.MyInvocation.BoundParameters["ErrorAction"] -ne "SilentlyContinue") { Get-JSONErrorStream -JSONResponse $_ } } } } Function Remove-NectarWebRTCConfig { <# .SYNOPSIS Removes an existing WebRTC call data integration from Nectar DXP .DESCRIPTION Removes an existing WebRTC call data integration from Nectar DXP. Requires a global admin account. Not available to tenant-level admins. .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .EXAMPLE Remove-NectarWebRTCConfig -TenantName contoso .NOTES Version 1.0 #> [cmdletbinding(SupportsShouldProcess, ConfirmImpact = 'High')] Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$TenantName ) Begin { Connect-NectarCloud } Process { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } ElseIf ($TenantName) { If ($TenantName -NotIn $Global:NectarTenantList) { $TList = $Global:NectarTenantList -join ', ' Throw "Could not find a tenant with the name $TenantName on https://$Global:NectarCloud. Select one of $TList. $($_.Exception.Message)" } } # Get the existing WebRTC config details $ExistingConfig = (Get-NectarWebRTCConfig)[0] $URI = "https://$Global:NectarCloud/aapi/configuration/webrtc/$($ExistingConfig.id)" Write-Verbose $URI $Body = @{ tenant = $TenantName } $JSONBody = $Body | ConvertTo-JSON Write-Verbose $JSONBody If ($PSCmdlet.ShouldProcess(("Deleting Nectar DXP WebRTC config on tenant {0}" -f $TenantName), ("Delete Nectar DXP WebRTC config on tenant {0}?" -f $TenantName), 'Nectar DXP WebRTC Config Deletion')) { Try { $NULL = Invoke-RestMethod -Method DELETE -URI $URI -Headers $Global:NectarAuthHeader -Body $JSONBody -ContentType 'application/json; charset=utf-8' } Catch { If ($PSCmdlet.MyInvocation.BoundParameters["ErrorAction"] -ne "SilentlyContinue") { Get-JSONErrorStream -JSONResponse $_ } } } } } ################################################################################################################################################# # # # Supporting Admin Functions # # # Function Get-NectarCloudAgent { <# .SYNOPSIS Returns a list of cloud agents for a given tenant from Nectar DXP .DESCRIPTION Returns a list of cloud agents for a given tenant from Nectar DXP. Requires a global admin account. Not available to tenant-level admins. .PARAMETER TenantName The name of the Nectar DXP tenant. Used in multi-tenant configurations. .EXAMPLE Get-NectarCloudAgent -TenantName nectarcorp .NOTES Version 1.0 #> Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)] [string]$TenantName ) Begin { Connect-NectarCloud } Process { # Use globally set tenant name, if one was set and not explicitly included in the command If ($Global:NectarTenantName -And !$PSBoundParameters.ContainsKey('TenantName')) { $TenantName = $Global:NectarTenantName } ElseIf ($TenantName) { If ($TenantName -NotIn $Global:NectarTenantList) { $TList = $Global:NectarTenantList -join ', ' Throw "Could not find a tenant with the name $TenantName on https://$Global:NectarCloud. Select one of $TList. $($_.Exception.Message)" } } # Get the cloud agents for the specified tenant $URI = "https://$($Global:NectarCloud)/aapi/cloudagents?tenant=$TenantName" Write-Verbose $URI Try { $Response = Invoke-RestMethod -Method GET -URI $URI -Headers $Global:NectarAuthHeader Return $Response } Catch { Write-Error "Failed to retrieve cloud agents. $($_.Exception.Message)" If ($PSCmdlet.MyInvocation.BoundParameters["ErrorAction"] -ne "SilentlyContinue") { Get-JSONErrorStream -JSONResponse $_ } } } } ################################################################################################################################################# # # # Supporting Functions # # # |