Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Solutions/SAP BTP/Tools/BtpHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ function Get-BtpServiceKeyCredentials {
function New-BtpConnectionRequestBody {
param(
[Parameter(Mandatory=$true)]
[object]$BtpCredentials
[object]$BtpCredentials,
[Parameter(Mandatory=$false)]
[string]$SubaccountName
)

try {
Expand All @@ -512,6 +514,9 @@ function New-BtpConnectionRequestBody {
properties = @{
connectorDefinitionName = "SAPBTPAuditEvents"
dataType = "SAPBTPAuditLog_CL"
addOnAttributes = @{
SubaccountName = if ([string]::IsNullOrWhiteSpace($SubaccountName)) { "Unknown" } else { $SubaccountName }
}
auth = @{
type = "OAuth2"
ClientId = $BtpCredentials.ClientId
Expand All @@ -525,10 +530,11 @@ function New-BtpConnectionRequestBody {
request = @{
apiEndpoint = $apiEndpoint
httpMethod = "Get"
queryWindowInMin = 5
queryWindowInMin = 1
queryTimeFormat = "yyyy-MM-ddTHH:mm:ss.fff"
retryCount = 3
timeoutInSeconds = 120
timeoutInSeconds = 60
queryWindowDelayInMin = 20
startTimeAttributeName = "time_from"
endTimeAttributeName = "time_to"
headers = @{
Expand Down Expand Up @@ -729,19 +735,11 @@ function Get-BtpConnectionName {
[string]$SubaccountId
)

# Use subdomain from UAA URL for connection name with subaccount ID suffix
# Pattern: subdomain_subaccountid (e.g., msdemo_12345678-90ab-cdef-1234-567890abcdef)
# Falls back to subaccount ID only if subdomain cannot be extracted
$cleanSubaccountId = $SubaccountId.Replace('-', '')
# Use subaccount ID as connection name
# Pattern: subaccount-id (e.g., 59408ac3-f5b3-4fba-9ee1-ded934352397)
$connectionName = $SubaccountId

if ([string]::IsNullOrWhiteSpace($BtpCredentials.Subdomain)) {
Write-Log "Subdomain not found in UAA URL, using subaccount ID only for connection name" -Level "WARNING"
$connectionName = "$cleanSubaccountId"
} else {
# Remove any special characters and ensure valid Azure resource name
$cleanSubdomain = $BtpCredentials.Subdomain -replace '[^a-zA-Z0-9]', ''
$connectionName = "${cleanSubdomain}_${cleanSubaccountId}"
}
Write-Log "Using subaccount ID as connection name: $connectionName"

return $connectionName
}
Expand All @@ -762,6 +760,8 @@ function New-SentinelBtpConnection {
[Parameter(Mandatory=$true)]
[string]$SubaccountId,
[Parameter(Mandatory=$false)]
[string]$SubaccountName,
[Parameter(Mandatory=$false)]
[string]$ApiVersion = "2025-09-01"
)

Expand Down Expand Up @@ -790,7 +790,7 @@ function New-SentinelBtpConnection {
}

# Build request body
$bodyObject = New-BtpConnectionRequestBody -BtpCredentials $BtpCredentials
$bodyObject = New-BtpConnectionRequestBody -BtpCredentials $BtpCredentials -SubaccountName $SubaccountName
if ($null -eq $bodyObject) {
return $false
}
Expand Down
2 changes: 2 additions & 0 deletions Solutions/SAP BTP/Tools/connect-sentinel-to-btp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ $currentApiEndpoint = $null

foreach ($subaccount in $subaccounts) {
$subaccountId = $subaccount.SubaccountId
$subaccountName = $subaccount.DisplayName
$apiEndpoint = $subaccount.'cf-api-endpoint'
$orgName = $subaccount.'cf-org-name'
$spaceName = $subaccount.'cf-space-name'
Expand Down Expand Up @@ -195,6 +196,7 @@ foreach ($subaccount in $subaccounts) {
-ConnectionName $connectionName `
-BtpCredentials $btpCredentials `
-SubaccountId $subaccountId `
-SubaccountName $subaccountName `
-ApiVersion $ApiVersion

if ($connectionCreated) {
Expand Down
1 change: 1 addition & 0 deletions Solutions/SAP BTP/Tools/export-subaccounts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ try {
# Create subaccount entry with default space placeholder
$subaccountEntry = [PSCustomObject]@{
SubaccountId = $subaccountId
DisplayName = $subaccountName
"cf-api-endpoint" = $cfDetails.ApiEndpoint
"cf-org-name" = $cfDetails.OrgName
"cf-space-name" = "dev" # Common default - user should verify/update
Expand Down
Loading