Skip to content

Commit daf9cf9

Browse files
committed
7.6.1
-add webhook - add extra field - add external id
1 parent 6b9a5b8 commit daf9cf9

File tree

5 files changed

+201
-3
lines changed

5 files changed

+201
-3
lines changed

Public/Get-LMAWSAccountId.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<#
22
.SYNOPSIS
3-
Retrieves the AWS External Account ID associated with the LogicMonitor account.
3+
Retrieves the AWS Account ID associated with the LogicMonitor account.
44
55
.DESCRIPTION
6-
The Get-LMAWSAccountId function retrieves the AWS External Account ID that is associated with the current LogicMonitor account. This ID is used for AWS integration purposes and helps identify the AWS account linked to your LogicMonitor instance.
6+
The Get-LMAWSAccountId function retrieves the AWS Account ID that is associated with the current LogicMonitor account. This ID is used for AWS integration purposes and helps identify the AWS account linked to your LogicMonitor instance.
77
88
.EXAMPLE
9-
#Retrieve the AWS External Account ID
9+
#Retrieve the AWS Account ID
1010
Get-LMAWSAccountId
1111
1212
.NOTES

Public/Get-LMAWSExternalId.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<#
2+
.SYNOPSIS
3+
Retrieves the AWS External ID associated with the LogicMonitor account.
4+
5+
.DESCRIPTION
6+
The Get-LMAWSExternalId function retrieves the AWS External ID that is associated with the current LogicMonitor account. This ID is used for AWS integration purposes and helps identify the AWS account linked to your LogicMonitor instance.
7+
8+
.EXAMPLE
9+
#Retrieve the AWS External ID
10+
Get-LMAWSExternalId
11+
12+
.NOTES
13+
You must run Connect-LMAccount before running this command.
14+
15+
.INPUTS
16+
None. You cannot pipe objects to this command.
17+
18+
.OUTPUTS
19+
Returns a string containing the AWS External ID.
20+
#>
21+
22+
function Get-LMAWSExternalId {
23+
[CmdletBinding(DefaultParameterSetName = 'All')]
24+
param ()
25+
26+
#Check if we are logged in and have valid api creds
27+
if ($Script:LMAuth.Valid) {
28+
29+
#Build header and uri
30+
$ResourcePath = "/aws/externalId"
31+
32+
33+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "GET" -ResourcePath $ResourcePath
34+
$Uri = "https://$($Script:LMAuth.Portal).$(Get-LMPortalURI)" + $ResourcePath + $QueryParams
35+
36+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
37+
38+
#Issue request
39+
$Response = Invoke-LMRestMethod -CallerPSCmdlet $PSCmdlet -Uri $Uri -Method "GET" -Headers $Headers[0] -WebSession $Headers[1]
40+
return $Response
41+
42+
}
43+
else {
44+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
45+
}
46+
}

Public/New-LMDeviceGroup.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ The description of the device group.
1414
.PARAMETER Properties
1515
A hashtable of custom properties for the device group.
1616
17+
.PARAMETER Extra
18+
Specifies a object of extra properties for the device group. Used for LM Cloud resource groups
19+
1720
.PARAMETER DisableAlerting
1821
Specifies whether alerting is disabled for the device group. The default value is $false.
1922
@@ -59,6 +62,8 @@ function New-LMDeviceGroup {
5962

6063
[Hashtable]$Properties,
6164

65+
[Object]$Extra,
66+
6267
[Int]$DefaultCollectorId = 0,
6368

6469
[Int]$DefaultAutoBalancedCollectorGroupId = 0,
@@ -115,6 +120,7 @@ function New-LMDeviceGroup {
115120
defaultAutoBalancedCollectorGroupId = $DefaultAutoBalancedCollectorGroupId
116121
defaultCollectorGroupId = $DefaultCollectorGroupId
117122
defaultCollectorId = $DefaultCollectorId
123+
extra = $Extra
118124
}
119125

120126
$Data = ($Data | ConvertTo-Json)

Public/Send-LMWebhookMessage.ps1

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<#
2+
.SYNOPSIS
3+
Sends webhook events to LogicMonitor.
4+
5+
.DESCRIPTION
6+
The Send-LMWebhookMessage function submits webhook messages to LogicMonitor for ingestion via the Webhook LogSource endpoint. Provide an array of events to transmit; each entry is converted into a JSON payload. Optional common properties can be merged into every event to support downstream parsing in LogicMonitor.
7+
8+
.PARAMETER SourceName
9+
Specifies the LogicMonitor LogSource identifier used in the ingest URL. This typically matches the sourceName configured in LogicMonitor.
10+
11+
.PARAMETER Events
12+
Specifies the collection of events to send. Each item may be a hashtable, PSCustomObject, or simple value. Simple values are wrapped in a payload under the `message` property.
13+
14+
.PARAMETER Properties
15+
Specifies additional key/value pairs that are merged into every event payload before sending.
16+
17+
.EXAMPLE
18+
Send-LMWebhookMessage -SourceName "Meraki_CustomerA" -Events $Messages -Properties @{ accountId = '12345' }
19+
Sends each event in `$Messages` to the Meraki webhook LogSource, appending the `accountId` property to every payload.
20+
21+
.OUTPUTS
22+
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.
23+
#>
24+
function Send-LMWebhookMessage {
25+
26+
[CmdletBinding()]
27+
param (
28+
29+
[Parameter(Mandatory)]
30+
[String]$SourceName,
31+
32+
[Parameter(Mandatory)]
33+
[Object[]]$Messages,
34+
35+
[Hashtable]$Properties,
36+
37+
[Switch]$PassThru
38+
)
39+
40+
begin {
41+
if (-not $Properties) {
42+
$Properties = @{}
43+
}
44+
45+
if ($PassThru) {
46+
$SentPayloads = New-Object System.Collections.Generic.List[pscustomobject]
47+
}
48+
}
49+
process {
50+
if (-not $Script:LMAuth.Valid) {
51+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
52+
return
53+
}
54+
55+
if ($Script:LMAuth.Type -ne "Bearer") {
56+
Write-Error "This cmdlet does not support LMv1 or SessionSync auth. Use Connect-LMAccount to login with the correct auth type and try again"
57+
return
58+
}
59+
60+
$encodedSource = [System.Uri]::EscapeDataString($SourceName)
61+
$resourcePath = "/api/v1/webhook/ingest/$encodedSource"
62+
$uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/rest" + $resourcePath
63+
64+
foreach ($message in $Messages) {
65+
$payload = [ordered]@{}
66+
67+
if ($message -is [System.Collections.IDictionary]) {
68+
foreach ($key in $message.Keys) {
69+
$payload[$key] = $message[$key]
70+
}
71+
}
72+
elseif ($message -is [PSCustomObject]) {
73+
foreach ($property in $message.PSObject.Properties) {
74+
$payload[$property.Name] = $property.Value
75+
}
76+
}
77+
else {
78+
$payload["message"] = [String]$message
79+
}
80+
81+
foreach ($propertyKey in $Properties.Keys) {
82+
$payload[$propertyKey] = $Properties[$propertyKey]
83+
}
84+
85+
foreach ($key in @($payload.Keys)) {
86+
if ($null -eq $payload[$key]) {
87+
$payload.Remove($key)
88+
}
89+
}
90+
91+
$body = ConvertTo-Json -InputObject $payload -Depth 10
92+
93+
$headers = New-LMHeader -Auth $Script:LMAuth -Method "POST" -ResourcePath $resourcePath -Data $body
94+
95+
Resolve-LMDebugInfo -Url $uri -Headers $headers[0] -Command $MyInvocation -Payload $body
96+
97+
$response = Invoke-LMRestMethod -CallerPSCmdlet $PSCmdlet -Uri $uri -Method "POST" -Headers $headers[0] -WebSession $headers[1] -Body $body
98+
$isAccepted = ($response -eq "Accepted")
99+
100+
if ($isAccepted) {
101+
if ($PassThru) {
102+
$SentPayloads.Add([pscustomobject]$payload)
103+
}
104+
else {
105+
Write-Output "Webhook message accepted successfully."
106+
}
107+
continue
108+
}
109+
110+
$statusMessage = "Error"
111+
if ($PassThru) {
112+
$SentPayloads.Add([pscustomobject]@{
113+
status = $statusMessage
114+
payload = [pscustomobject]$payload
115+
error = [pscustomobject]@{
116+
code = $response.errors.code
117+
error = $response.errors.error
118+
}
119+
})
120+
}
121+
122+
Write-Error -Message "$($response.errors.code): $($response.errors.error)"
123+
}
124+
}
125+
end {
126+
if ($PassThru -and $SentPayloads -and $SentPayloads.Count -gt 0) {
127+
foreach ($result in $SentPayloads) {
128+
if (-not ($result.PSObject.Properties.Name -contains 'status')) {
129+
$SentPayloads[$SentPayloads.IndexOf($result)] = [pscustomobject]@{
130+
status = "Accepted"
131+
payload = $result
132+
}
133+
}
134+
}
135+
$SentPayloads.ToArray()
136+
}
137+
}
138+
}
139+
140+

Public/Set-LMDeviceGroup.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Specifies the ID of the parent group.
3838
.PARAMETER ParentGroupName
3939
Specifies the name of the parent group.
4040
41+
.PARAMETER Extra
42+
Specifies a object of extra properties for the device group. Used for LM Cloud resource groups
43+
4144
.EXAMPLE
4245
Set-LMDeviceGroup -Id 123 -NewName "Updated Group" -Description "New description"
4346
Updates the device group with ID 123 with a new name and description.
@@ -69,6 +72,8 @@ function Set-LMDeviceGroup {
6972

7073
[Hashtable]$Properties,
7174

75+
[Object]$Extra,
76+
7277
[Nullable[Int]]$DefaultCollectorId,
7378

7479
[Nullable[Int]]$DefaultAutoBalancedCollectorGroupId,
@@ -147,6 +152,7 @@ function Set-LMDeviceGroup {
147152
enableNetflow = $EnableNetFlow
148153
customProperties = $customProperties
149154
parentId = $ParentGroupId
155+
extra = $Extra
150156
}
151157

152158
#Remove empty keys so we dont overwrite them

0 commit comments

Comments
 (0)