Jun 22, 2026, 2:23 PM

This commit is contained in:
Paweł Domański
2026-06-22 12:23:33 +00:00
parent 957d46fd2e
commit dbcfa02044
+20 -4
View File
@@ -157,7 +157,7 @@ function Get-SplunkAPIHosts {
# 1. Metoda główna: GET /v2/dimension?query=host
try {
Write-Log "DEBUG: Rozpoczynam pobieranie wymiarów (Metoda 1: GET /v2/dimension?query=host)..."
$limit = 100
$limit = 20
$offset = 0
$hasMore = $true
@@ -185,10 +185,18 @@ function Get-SplunkAPIHosts {
if ($item.key -eq "host" -and -not [string]::IsNullOrWhiteSpace($item.value)) {
[void]$hostsSet.Add($item.value.Trim())
}
# Przerywamy natychmiast, gdy zebraliśmy już 20 unikalnych hostów
if ($hostsSet.Count -ge 20) {
$hasMore = $false
break
}
}
Write-Log "DEBUG: Pobrano $($results.Count) obiektów wymiarów (offset: $offset). Dotychczas unikalnych hostów: $($hostsSet.Count)"
if ($results.Count -lt $limit) {
if ($hostsSet.Count -ge 20) {
$hasMore = $false
} elseif ($results.Count -lt $limit) {
$hasMore = $false
} else {
$offset += $limit
@@ -206,7 +214,7 @@ function Get-SplunkAPIHosts {
if ($hostsSet.Count -eq 0) {
try {
Write-Log "DEBUG: Metoda 1 nie zwróciła hostów. Uruchamiam Metodę zapasową 2 (GET /v2/metrictimeseries)..."
$limit = 100
$limit = 20
$offset = 0
$hasMore = $true
@@ -228,10 +236,18 @@ function Get-SplunkAPIHosts {
[void]$hostsSet.Add($val.Trim())
}
}
# Przerywamy natychmiast, gdy zebraliśmy już 20 unikalnych hostów
if ($hostsSet.Count -ge 20) {
$hasMore = $false
break
}
}
Write-Log "DEBUG: Pobrano $($results.Count) rekordów MTS (offset: $offset). Dotychczas unikalnych hostów: $($hostsSet.Count)"
if ($results.Count -lt $limit) {
if ($hostsSet.Count -ge 20) {
$hasMore = $false
} elseif ($results.Count -lt $limit) {
$hasMore = $false
} else {
$offset += $limit