@@ -21,9 +21,44 @@ Specifies the collection of messages/events to send. Each item may be a hashtabl
2121Returns PSCustomObject entries containing status, payload, and optional error details for each attempted message.
2222
2323. EXAMPLE
24- Send-LMWebhookMessage -SourceName "Meraki_CustomerA" -Events $Messages -Properties @{ accountId = '12345' }
24+ Send-LMWebhookMessage -SourceName "Meraki_CustomerA" -Messages $Messages -Properties @{ accountId = '12345' }
2525Sends each event in `$Messages` to the Meraki webhook LogSource, appending the `accountId` property to every payload.
2626
27+ . EXAMPLE
28+ $jsonString = '{"eventType":"alert","severity":"critical","description":"Database connection failed"}'
29+ Send-LMWebhookMessage -SourceName "MyWebhookSource" -Messages @($jsonString)
30+ Sends a JSON string that will be automatically parsed and sent as structured data to the webhook endpoint.
31+
32+ . EXAMPLE
33+ Send-LMWebhookMessage -SourceName "AppLogs" -Messages @("Application started successfully", "User login detected")
34+ Sends plain text messages that will be wrapped in a message property for ingestion.
35+
36+ . EXAMPLE
37+ $event = @{
38+ eventType = "deployment"
39+ version = "1.2.3"
40+ environment = "production"
41+ timestamp = (Get-Date).ToString("o")
42+ }
43+ Send-LMWebhookMessage -SourceName "Deployments" -Messages @($event) -PassThru
44+ Sends a hashtable as a structured event and returns the result with status information.
45+
46+ . EXAMPLE
47+ $events = @(
48+ [PSCustomObject]@{ eventType = "login"; user = "john.doe"; status = "success" }
49+ [PSCustomObject]@{ eventType = "logout"; user = "jane.smith"; status = "success" }
50+ )
51+ Send-LMWebhookMessage -SourceName "AuthEvents" -Messages $events -Properties @{ source = "AD"; region = "us-east-1" }
52+ Sends multiple PSCustomObject events with additional properties merged into each payload.
53+
54+ . EXAMPLE
55+ $jsonEvents = @(
56+ '{"metric":"cpu","value":85,"host":"server01"}'
57+ '{"metric":"memory","value":72,"host":"server01"}'
58+ )
59+ Send-LMWebhookMessage -SourceName "Metrics" -Messages $jsonEvents
60+ Sends multiple JSON strings that will be automatically parsed and sent as individual structured events.
61+
2762. OUTPUTS
2863Outputs a confirmation message for each accepted webhook event, or an error message if the request fails. When -PassThru is specified, returns PSCustomObject entries containing status, payload, and optional error details for each attempted message.
2964#>
@@ -70,6 +105,18 @@ function Send-LMWebhookMessage {
70105 foreach ($message in $Messages ) {
71106 $payload = [ordered ]@ {}
72107
108+ # Check if message is a JSON string and convert it
109+ if ($message -is [String ]) {
110+ try {
111+ $jsonObject = $message | ConvertFrom-Json - ErrorAction Stop
112+ $message = $jsonObject
113+ }
114+ catch {
115+ # Not valid JSON, treat as plain string message
116+ $payload [" message" ] = $message
117+ }
118+ }
119+
73120 if ($message -is [System.Collections.IDictionary ]) {
74121 foreach ($key in $message.Keys ) {
75122 $payload [$key ] = $message [$key ]
@@ -80,7 +127,8 @@ function Send-LMWebhookMessage {
80127 $payload [$property.Name ] = $property.Value
81128 }
82129 }
83- else {
130+ elseif (-not ($payload.Contains (" message" ))) {
131+ # Only wrap in message if not already handled above
84132 $payload [" message" ] = [String ]$message
85133 }
86134
0 commit comments