Skip to content

Commit 5a82d40

Browse files
committed
bug fixes
1 parent 01badb4 commit 5a82d40

4 files changed

Lines changed: 79 additions & 5 deletions

File tree

Private/Resolve-LMDebugInfo.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function Resolve-LMDebugInfo {
9393
Write-Debug "Portal: $($UriObj.Host)"
9494

9595
# Display headers with partial redaction for identification
96-
$SensitiveHeaders = @('accessKey', 'bearerToken', 'cookie', 'X-CSRF-Token')
96+
$SensitiveHeaders = @('accessKey', 'bearerToken', 'cookie', 'X-CSRF-Token', 'Authorization')
9797
$HeaderInfo = $Headers.GetEnumerator() | ForEach-Object {
9898
$Value = if ($SensitiveHeaders -contains $_.Key) {
9999
if ($_.Value.Length -gt 25) {

Private/Test-LMFilterField.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ function Test-LMFilterField {
8080
# String filter (v2 format) - extract field names before operators
8181
# Pattern: field_name followed by -eq, -ne, -gt, -lt, -ge, -le, -contains, -notcontains
8282
$Pattern = '(?:^|\s+)([a-zA-Z_][a-zA-Z0-9_\.]*)\s+(?:-eq|-ne|-gt|-lt|-ge|-le|-contains|-notcontains)\s+'
83-
$Matches = [regex]::Matches($Filter, $Pattern)
83+
$PatternMatches = [regex]::Matches($Filter, $Pattern)
8484

85-
foreach ($Match in $Matches) {
85+
foreach ($Match in $PatternMatches) {
8686
if ($Match.Groups.Count -ge 2) {
8787
$FilterFields += $Match.Groups[1].Value
8888
}

Public/Send-LMWebhookMessage.ps1

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,44 @@ Specifies the collection of messages/events to send. Each item may be a hashtabl
2121
Returns 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' }
2525
Sends 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
2863
Outputs 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

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ Connect-LMAccount -UseCachedCredential
7373

7474
# Change List
7575

76+
## 7.7.2
77+
### Hotfixes
78+
- **Send-LMWebhookMessage**: Fixed payload formatting when sending webhook messages to LM Logs:
79+
- JSON strings are now automatically detected and parsed into structured data, preventing escaped JSON in payloads
80+
- Plain text messages are properly encapsulated in a `message` property for consistent parsing
81+
- Removed unnecessary payload wrapping that caused ingestion issues
82+
- **Resolve-LMDebugInfo**: Fix bug where BearerTokens were not being obfuscated when running commands with the -Debug parameter.
83+
84+
```powershell
85+
#Sends multiple PSCustomObject events with additional properties merged into each payload.
86+
$events = @(
87+
[PSCustomObject]@{ eventType = "login"; user = "john.doe"; status = "success" }
88+
[PSCustomObject]@{ eventType = "logout"; user = "jane.smith"; status = "success" }
89+
)
90+
Send-LMWebhookMessage -SourceName "AuthEvents" -Messages $events -Properties @{ source = "AD"; region = "us-east-1" }
91+
92+
#Sends a hashtable as a structured event and returns the result with status information.
93+
$event = @{
94+
eventType = "deployment"
95+
version = "1.2.3"
96+
environment = "production"
97+
timestamp = (Get-Date).ToString("o")
98+
}
99+
Send-LMWebhookMessage -SourceName "Deployments" -Messages @($event) -PassThru
100+
```
101+
76102
## 7.7.1
77103
### Hotfixes
78104
- Fix bug with **ConvertTo-LMUpdateDevice** when trying to migrate Websites using an packet count of 50.

0 commit comments

Comments
 (0)