Skip to content

Commit a490037

Browse files
committed
Update 6.5.6
1 parent d783053 commit a490037

File tree

5 files changed

+280
-5
lines changed

5 files changed

+280
-5
lines changed

Logic.Monitor.Format.ps1xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,65 @@
5454
</TableRowEntries>
5555
</TableControl>
5656
</View>
57+
<!-- New View LogicMonitor.NormalizedProperties-->
58+
<View>
59+
<Name>LogicMonitorNormalizedProperties</Name>
60+
<ViewSelectedBy>
61+
<TypeName>LogicMonitor.NormalizedProperties</TypeName>
62+
</ViewSelectedBy>
63+
<TableControl>
64+
<TableHeaders>
65+
<TableColumnHeader>
66+
<Label>id</Label>
67+
</TableColumnHeader>
68+
<TableColumnHeader>
69+
<Label>model</Label>
70+
</TableColumnHeader>
71+
<TableColumnHeader>
72+
<Label>alias</Label>
73+
</TableColumnHeader>
74+
<TableColumnHeader>
75+
<Label>hostProperty</Label>
76+
</TableColumnHeader>
77+
<TableColumnHeader>
78+
<Label>hostPropertyPriority</Label>
79+
</TableColumnHeader>
80+
<TableColumnHeader>
81+
<Label>isEditable</Label>
82+
</TableColumnHeader>
83+
<TableColumnHeader>
84+
<Label>isDeletable</Label>
85+
</TableColumnHeader>
86+
</TableHeaders>
87+
<TableRowEntries>
88+
<TableRowEntry>
89+
<TableColumnItems>
90+
<TableColumnItem>
91+
<PropertyName>id</PropertyName>
92+
</TableColumnItem>
93+
<TableColumnItem>
94+
<PropertyName>model</PropertyName>
95+
</TableColumnItem>
96+
<TableColumnItem>
97+
<PropertyName>alias</PropertyName>
98+
</TableColumnItem>
99+
<TableColumnItem>
100+
<PropertyName>hostProperty</PropertyName>
101+
</TableColumnItem>
102+
<TableColumnItem>
103+
<PropertyName>hostPropertyPriority</PropertyName>
104+
</TableColumnItem>
105+
<TableColumnItem>
106+
<PropertyName>isEditable</PropertyName>
107+
</TableColumnItem>
108+
<TableColumnItem>
109+
<PropertyName>isDeletable</PropertyName>
110+
</TableColumnItem>
111+
</TableColumnItems>
112+
</TableRowEntry>
113+
</TableRowEntries>
114+
</TableControl>
115+
</View>
57116
<!-- New View LogicMonitor.Alert-->
58117
<View>
59118
<Name>LogicMonitorAlert</Name>

Public/Get-LMNormalizedProperties.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ Function Get-LMNormalizedProperties {
4545
pageOffsetCount = 0
4646
}
4747
sort = "alias, hostPropertyPriority"
48+
columns = @(
49+
@{ properties = "id, name, propertyType"}
50+
)
4851
}
4952
} | ConvertTo-Json -Depth 10
5053

@@ -56,14 +59,31 @@ Function Get-LMNormalizedProperties {
5659

5760
#Issue request
5861
$Response = Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Body
62+
63+
# Transform the response to return just the normalized property values
64+
if ($Response.data.byId.normalizedProperties) {
65+
$normalizedProperties = $Response.data.byId.normalizedProperties
66+
$transformedProperties = @()
67+
68+
# Get all property names and sort them numerically
69+
$propertyNames = $normalizedProperties.PSObject.Properties.Name | Sort-Object { [int]$_ }
70+
71+
# Add each property's value to the array
72+
foreach ($propName in $propertyNames) {
73+
$transformedProperties += $normalizedProperties.$propName
74+
}
75+
76+
Return (Add-ObjectTypeInfo -InputObject $transformedProperties -TypeName "LogicMonitor.NormalizedProperties" )
77+
}
78+
79+
return $Response
5980
}
6081
Catch [Exception] {
6182
$Proceed = Resolve-LMException -LMException $PSItem
6283
If (!$Proceed) {
6384
Return
6485
}
6586
}
66-
Return $Response
6787
}
6888
Else {
6989
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<#
2+
.SYNOPSIS
3+
Updates normalized properties in LogicMonitor.
4+
5+
.DESCRIPTION
6+
The Set-LMNormalizedProperties cmdlet updates normalized properties in LogicMonitor. Normalized properties allow you to map multiple host properties to a single alias that can be used across your environment.
7+
8+
.PARAMETER Alias
9+
The alias name for the normalized property.
10+
11+
.PARAMETER Properties
12+
An array of host property names to map to the alias.
13+
14+
.EXAMPLE
15+
PS C:\> Set-LMNormalizedProperties -Add -Alias "location" -Properties @("location", "snmp.sysLocation", "auto.meraki.location")
16+
Updates a normalized property with alias "location" to include the new properties.
17+
18+
PS C:\> Set-LMNormalizedProperties -Remove -Alias "location" -Properties @("auto.meraki.location")
19+
Removes the "auto.meraki.location" property from the "location" alias.
20+
21+
.NOTES
22+
Requires valid LogicMonitor API credentials set via Connect-LMAccount.
23+
This cmdlet uses LogicMonitor API v4.
24+
#>
25+
26+
Function Set-LMNormalizedProperties {
27+
28+
[CmdletBinding()]
29+
Param (
30+
[Parameter(Mandatory = $true)]
31+
[String]$Alias,
32+
[Parameter(Mandatory = $true, ParameterSetName = "Add")]
33+
[Switch]$Add,
34+
[Parameter(Mandatory = $true, ParameterSetName = "Remove")]
35+
[Switch]$Remove,
36+
[Parameter(Mandatory = $true)]
37+
[Array]$Properties
38+
)
39+
40+
#Check if we are logged in and have valid api creds
41+
Begin {}
42+
Process {
43+
If ($Script:LMAuth.Valid) {
44+
#Get existing normalized properties as all updates have to be done via bulk
45+
$ExistingProperties = Get-LMNormalizedProperties
46+
47+
#Build header and uri
48+
$ResourcePath = "/normalizedProperties/bulk"
49+
50+
#Initialize the body with existing properties that don't match our alias
51+
$Body = [PSCustomObject]@{
52+
data = [PSCustomObject]@{
53+
items = @()
54+
}
55+
}
56+
57+
# Track the highest priority for the current alias
58+
$maxPriority = 0
59+
60+
# If we're removing properties, we need to preserve all other aliases
61+
if ($Remove) {
62+
# Add all existing properties
63+
foreach ($prop in $ExistingProperties) {
64+
if ($prop.isEditable) {
65+
if ($prop.alias -eq $Alias) {
66+
# Only keep properties that aren't in our removal list
67+
if ($prop.hostProperty -notin $Properties) {
68+
$Body.data.items += [PSCustomObject]@{
69+
id = $prop.id
70+
model = "normalizedProperties"
71+
alias = $prop.alias
72+
hostProperty = $prop.hostProperty
73+
hostPropertyPriority = $prop.hostPropertyPriority
74+
description = $prop.description
75+
}
76+
}
77+
}
78+
else {
79+
# For non-editable properties, only include id and model
80+
$Body.data.items += [PSCustomObject]@{
81+
id = $prop.id
82+
model = "normalizedProperties"
83+
}
84+
}
85+
}
86+
}
87+
}
88+
# If we're adding properties, we need to preserve existing properties for other aliases
89+
# and add our new properties
90+
else {
91+
# First add all existing properties
92+
foreach ($prop in $ExistingProperties) {
93+
if ($prop.alias -eq $Alias) {
94+
# Track the highest priority for this alias
95+
if ($prop.hostPropertyPriority -gt $maxPriority) {
96+
$maxPriority = $prop.hostPropertyPriority
97+
}
98+
# Only include full property details if it's editable
99+
if ($prop.isEditable) {
100+
$Body.data.items += [PSCustomObject]@{
101+
id = $prop.id
102+
model = "normalizedProperties"
103+
alias = $prop.alias
104+
hostProperty = $prop.hostProperty
105+
hostPropertyPriority = $prop.hostPropertyPriority
106+
description = $prop.description
107+
}
108+
}
109+
else {
110+
# For non-editable properties, only include id and model
111+
$Body.data.items += [PSCustomObject]@{
112+
id = $prop.id
113+
model = "normalizedProperties"
114+
}
115+
}
116+
}
117+
else {
118+
# For other aliases, only include id and model
119+
$Body.data.items += [PSCustomObject]@{
120+
id = $prop.id
121+
model = "normalizedProperties"
122+
}
123+
}
124+
}
125+
126+
# Then add our new properties starting from the next available priority
127+
$Index = $maxPriority + 1
128+
foreach ($Property in $Properties) {
129+
# Check if this property already exists for this alias
130+
$exists = $false
131+
foreach ($prop in $ExistingProperties) {
132+
if ($prop.alias -eq $Alias -and $prop.hostProperty -eq $Property) {
133+
$exists = $true
134+
break
135+
}
136+
}
137+
138+
# Only add if it doesn't already exist
139+
if (-not $exists) {
140+
$Body.data.items += [PSCustomObject]@{
141+
model = "normalizedProperties"
142+
alias = $Alias
143+
hostProperty = $Property
144+
hostPropertyPriority = $Index
145+
}
146+
$Index++
147+
}
148+
}
149+
}
150+
151+
$Body = $Body | ConvertTo-Json -Depth 10
152+
153+
Try {
154+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "PATCH" -ResourcePath $ResourcePath -Version 4
155+
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath
156+
157+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation -Payload $Body
158+
159+
#Issue request
160+
$Response = Invoke-RestMethod -Uri $Uri -Method "PATCH" -Headers $Headers[0] -WebSession $Headers[1] -Body $Body
161+
162+
# Check for errors in the response
163+
if ($Response.errors.Count -gt 0) {
164+
foreach ($error in $Response.errors) {
165+
Write-Error "Error updating normalized properties: $($error.message)"
166+
}
167+
Return
168+
}
169+
Write-Output "Normalized properties updated successfully"
170+
return
171+
}
172+
Catch [Exception] {
173+
$Proceed = Resolve-LMException -LMException $PSItem
174+
If (!$Proceed) {
175+
Return
176+
}
177+
}
178+
}
179+
Else {
180+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
181+
}
182+
}
183+
End {}
184+
}

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,20 @@ This change aims to enhance visibility within the community and to foster a more
431431

432432
We appreciate your continued support and enthusiasm for the Logic.Monitor PowerShell module. Your contributions and feedback are vital to the success of this project, and we look forward to seeing how the module evolves with your participation.
433433

434-
## 6.5.5
435-
### Bug Fixes
436-
- Fixed a bug that prevented the Get-LMAlerts cmdlet from respecting custom -Sort parameters.
437-
- Fixed a bug that prevented setting a prefered log collecor when using Set-LMDevice. Use *-EnableLogCollection* $true to enable log collection on the device while specifying a preferred log collector using *-LogCollectorId*.
434+
## 6.5.6
435+
### New Cmdlets:
436+
- **Set-LMNormalizedProperties**: Allows updating of existing normalized properties.
437+
438+
```
439+
#Add new properties to an existing alias
440+
Set-LMNormalizedProperties -Add -Alias "location" -Properties @("location", "snmp.sysLocation", "auto.meraki.location")
441+
442+
#Remove a property from existing alias
443+
Set-LMNormalizedProperties -Remove -Alias "location" -Properties @("auto.meraki.location")
444+
```
445+
446+
### Updated Cmdlets:
447+
- **Get-LMNormalizedProperties**: Updated the output object type to make the returned object easier to work with. Returned object now contains the following fields: id,model,alias,hostProperty,hostPropertyPriority,isEditable,isDeletable
438448
439449
440450
[Previous Release Notes](RELEASENOTES.md)

RELEASENOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Previous module release notes
22
## 6.5.5
33
### Bug Fixes
4+
- Fixed a bug that prevented the Get-LMAlerts cmdlet from respecting custom -Sort parameters.
5+
- Fixed a bug that prevented setting a prefered log collecor when using Set-LMDevice. Use *-EnableLogCollection* $true to enable log collection on the device while specifying a preferred log collector using *-LogCollectorId*.
46
- Bug fix with Get-LMLogMessage. Fixed issue with Async queries defaulting to 15minute time range.
57

68
## 6.5.4

0 commit comments

Comments
 (0)