PSGraylog/Functions/Public/Test-GraylogSession.ps1

46 lines
1.6 KiB
PowerShell

function Test-GraylogSession {
<#
.SYNOPSIS
Tests the current session to the Graylog server.
.DESCRIPTION
Tests the current session to the Graylog server to ensure that it is still valid.
.PARAMETER SkipSecretCheck
An optional switch to skip the check for the required secrets.
.PARAMETER SkipSessionCheck
An optional switch to skip the check for the session secret.
.OUTPUTS
True if the session is valid, otherwise false.
.EXAMPLE
Test-GraylogSession
Tests the current session to the Graylog server.
.NOTES
This function is used to test the current session to the Graylog server to ensure that it is still valid.
#>
param (
[Parameter()]
[Switch]
$SkipSecretCheck,
[Parameter()]
[Switch]
$SkipSessionCheck
)
if (-NOT $SkipSecretCheck) {
try { $null = Get-Secret Graylog_BaseURI -Vault Graylog -ErrorAction Stop }
catch { Write-Error "The Graylog BaseURI secret is missing, try running Initialize-GraylogServiceVault?"; return $false }
try { $null = Get-Secret Graylog_Credential -Vault Graylog -ErrorAction Stop }
catch { Write-Error "The Graylog Credential secret is missing, try running Initialize-GraylogServiceVault?"; return $false }
try { $null = Get-Secret Graylog_Session -Vault Graylog -ErrorAction Stop }
catch { Write-Error "The Graylog Session secret is missing, try running Connect-GraylogService?"; return $false }
if ($SkipSessionCheck) { return $true }
}
if (-NOT $SkipSessionCheck) {
try { return (Invoke-GraylogRequest GET "/system/sessions").is_valid }
catch { return $false }
}
throw "-SkipSecretCheck and -SkipSessionCheck are mutually exclusive."
}