Repository navigation
Expand file tree
/
Copy pathAdd-ModuleWebSocketMessageToQueue.ps1
More file actions
65 lines (52 loc) · 2.66 KB
/
Copy pathAdd-ModuleWebSocketMessageToQueue.ps1
File metadata and controls
65 lines (52 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<#
.SYNOPSIS
Enqueue a message for a WebSocket writer worker.
.DESCRIPTION
`Add-ModuleWebSocketMessageToQueue` places a message into the configured
WebSocket writer queue. It validates the WebSocket name (allowing an
override) and the message payload, logs the enqueue operation and returns a
structured module return on error conditions.
.PARAMETER Message
| Name | Type | Description | Default |
|---------|---------------|-----------------------------|---------|
| Message | System.String | Message payload to enqueue. | |
.PARAMETER OverrideWebSocketName
| Name | Type | Description | Default |
|-----------------------|---------------|-------------------------------------------|---------|
| OverrideWebSocketName | System.String | Optional runtime websocket name override. | |
.OUTPUTS
System.Object -- Emits module structured return values on error; otherwise the
message is placed in the BlockingCollection and the function returns without
an explicit value.
.EXAMPLE
PS> Add-ModuleWebSocketMessageToQueue -Message $payload
.NOTES
The message is written directly to the `WriterWorker` BlockingCollection stored
in `$Global:ModuleName.Public.WebSocket.<Name>.WriterWorker`. This collection is
consumed by `Write-ModuleWebSocket` running in a separate worker thread. The
function must be called from within a worker context where
`Get-GlobalRuntimeVariable` provides a valid WebSocket name via
`Private.WebSocket.Name`.
SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com>
SPDX-License-Identifier: GPL-3.0-or-later
#>
function Add-ModuleWebSocketMessageToQueue()
{
param (
[string]$Message = $null,
[string]$OverrideWebSocketName = $null
);
$GlobalVariable = Get-GlobalRuntimeVariable;
[string]$WebSocketName = $GlobalVariable.Private.WebSocket.Name;
if (-not [string]::IsNullOrEmpty($OverrideWebSocketName)) {
$WebSocketName = $OverrideWebSocketName;
}
if ([string]::IsNullOrEmpty($WebSocketName)) {
return (Write-FunctionReturnValue -ReturnValue 'WebSocketMessageAddQueueWebSocketNameMissing');
}
if ([string]::IsNullOrEmpty($Message)) {
return (Write-FunctionReturnValue -ReturnValue 'WebSocketMessageAddQueueMessageMissing' -Data @{ 'WebSocketName' = $WebSocketName; });
}
$GlobalVariable.Public.WebSocket.$WebSocketName.WriterWorker.Add($Message) | Out-Null;
Write-LoggingEntry -Message 'Add-ModuleWebSocketMessageToQueue: Message added to WebSocket write queue' -Level 'Debug' -Data @{ 'WebSocketName' = $WebSocketName; 'MessageLength' = $Message.Length; 'Message' = $Message; };
}