Refactor Get-GraylogStreamId to use Get-GraylogStreams function

This commit is contained in:
Nathan Windisch 2024-07-25 03:11:15 +01:00
parent 5edba53ffc
commit 9f9078dbc8
4 changed files with 28 additions and 8 deletions

View File

@ -19,13 +19,7 @@ function Get-GraylogStreamId {
$LogName $LogName
) )
# TODO: Use Secret Management module to get the Graylog API URI $Stream = (Get-GraylogStreams).Where{$_.Title -eq $LogName}
if ($null -eq $global:GraylogStreams) {
$Response = Invoke-GraylogRequest GET "/streams"
$global:GraylogStreams = $Response.Streams
}
$Stream = $global:GraylogStreams.Where{$_.Title -eq $LogName}
if ($null -eq $Stream) { return $null } if ($null -eq $Stream) { return $null }
return $Stream.Id return $Stream.Id
} }

View File

@ -0,0 +1,24 @@
function Get-GraylogStreams {
<#
.SYNOPSIS
Gets the streams available in Graylog.
.DESCRIPTION
Gets a list of the streams available in Graylog.
.OUTPUTS
The streams available in Graylog.
.EXAMPLE
Get-GraylogStreams
Gets a list of the streams available in Graylog.
#>
param ()
try { $null = Get-Secret Graylog_BaseURI -Vault Graylog -AsPlainText -ErrorAction Stop }
catch {
try { $Response = Invoke-GraylogRequest GET "/streams" }
catch { throw $_.Exception.Message }
ConvertTo-Json $Response.Streams | Set-Secret Graylog_Streams -Vault Graylog -AsPlainText
}
$Streams = Get-Secret Graylog_Streams -Vault Graylog -AsPlainText -ErrorAction Stop
return ConvertFrom-Json $Streams
}

View File

@ -69,7 +69,7 @@ function Search-Graylog {
$Detailed $Detailed
) )
$LogId = Get-GraylogLogStreamId -LogName $LogName $LogId = Get-GraylogStreamId -LogName $LogName
if ($null -eq $LogId) { throw "The log stream '$LogName' does not exist." } if ($null -eq $LogId) { throw "The log stream '$LogName' does not exist." }
$SearchId = [String]::Join('', [GUID]::NewGUID().GUID.Replace("-", "")[0..23]) # Generate a unique identifier for the search $SearchId = [String]::Join('', [GUID]::NewGUID().GUID.Replace("-", "")[0..23]) # Generate a unique identifier for the search
$QueryId = [GUID]::NewGUID().GUID.ToString() # Generate a unique identifier for the query $QueryId = [GUID]::NewGUID().GUID.ToString() # Generate a unique identifier for the query

View File

@ -69,6 +69,7 @@ RequiredModules = @("Microsoft.PowerShell.SecretManagement", "Microsoft.PowerShe
NestedModules = @( NestedModules = @(
"Functions\Public\Connect-GraylogService.ps1", "Functions\Public\Connect-GraylogService.ps1",
"Functions\Public\Disconnect-GraylogService.ps1", "Functions\Public\Disconnect-GraylogService.ps1",
"Functions\Public\Get-GraylogStreams.ps1",
"Functions\Public\Get-GraylogStreamId.ps1", "Functions\Public\Get-GraylogStreamId.ps1",
"Functions\Public\Initialize-GraylogServiceVault.ps1", "Functions\Public\Initialize-GraylogServiceVault.ps1",
"Functions\Public\Invoke-GraylogRequest.ps1", "Functions\Public\Invoke-GraylogRequest.ps1",
@ -83,6 +84,7 @@ NestedModules = @(
FunctionsToExport = @( FunctionsToExport = @(
"Connect-GraylogService", "Connect-GraylogService",
"Disconnect-GraylogService", "Disconnect-GraylogService",
"Get-GraylogStreams",
"Get-GraylogStreamId", "Get-GraylogStreamId",
"Initialize-GraylogServiceVault", "Initialize-GraylogServiceVault",
"Invoke-GraylogRequest", "Invoke-GraylogRequest",