Refactor Get-GraylogStreamId to use Get-GraylogStreams function
This commit is contained in:
parent
5edba53ffc
commit
9f9078dbc8
@ -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
|
||||||
}
|
}
|
24
Functions/Public/Get-GraylogStreamIds.ps1
Normal file
24
Functions/Public/Get-GraylogStreamIds.ps1
Normal 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
|
||||||
|
}
|
@ -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
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user