Skip to content

Commit 29eb08b

Browse files
committed
Add Integration cmdlets
### New Cmdlets - **Get-LMIntegration**: Retrieve integration configurations from LogicMonitor. - **Remove-LMIntegration**: Remove integrations by ID or name. - **Remove-LMEscalationChain**: Remove escalation chains by ID or name.
1 parent e4bc73b commit 29eb08b

File tree

5 files changed

+368
-0
lines changed

5 files changed

+368
-0
lines changed

Logic.Monitor.Format.ps1xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,53 @@
14531453
</TableRowEntries>
14541454
</TableControl>
14551455
</View>
1456+
<!-- New View LogicMonitor.Integration-->
1457+
<View>
1458+
<Name>LogicMonitorIntegration</Name>
1459+
<ViewSelectedBy>
1460+
<TypeName>LogicMonitor.Integration</TypeName>
1461+
</ViewSelectedBy>
1462+
<TableControl>
1463+
<TableHeaders>
1464+
<TableColumnHeader>
1465+
<Label>id</Label>
1466+
</TableColumnHeader>
1467+
<TableColumnHeader>
1468+
<Label>name</Label>
1469+
</TableColumnHeader>
1470+
<TableColumnHeader>
1471+
<Label>type</Label>
1472+
</TableColumnHeader>
1473+
<TableColumnHeader>
1474+
<Label>enabledStatus</Label>
1475+
</TableColumnHeader>
1476+
<TableColumnHeader>
1477+
<Label>description</Label>
1478+
</TableColumnHeader>
1479+
</TableHeaders>
1480+
<TableRowEntries>
1481+
<TableRowEntry>
1482+
<TableColumnItems>
1483+
<TableColumnItem>
1484+
<PropertyName>id</PropertyName>
1485+
</TableColumnItem>
1486+
<TableColumnItem>
1487+
<PropertyName>name</PropertyName>
1488+
</TableColumnItem>
1489+
<TableColumnItem>
1490+
<PropertyName>type</PropertyName>
1491+
</TableColumnItem>
1492+
<TableColumnItem>
1493+
<PropertyName>enabledStatus</PropertyName>
1494+
</TableColumnItem>
1495+
<TableColumnItem>
1496+
<PropertyName>description</PropertyName>
1497+
</TableColumnItem>
1498+
</TableColumnItems>
1499+
</TableRowEntry>
1500+
</TableRowEntries>
1501+
</TableControl>
1502+
</View>
14561503
<!-- New View LogicMonitor.RecentlyDeleted-->
14571504
<View>
14581505
<Name>LogicMonitorRecentlyDeleted</Name>

Public/Get-LMIntegration.ps1

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<#
2+
.SYNOPSIS
3+
Retrieves integrations from LogicMonitor.
4+
5+
.DESCRIPTION
6+
The Get-LMIntegration function retrieves integration configurations from LogicMonitor. It can retrieve all integrations, a specific integration by ID or name, or filter the results.
7+
8+
.PARAMETER Id
9+
The ID of the specific integration to retrieve.
10+
11+
.PARAMETER Name
12+
The name of the specific integration to retrieve.
13+
14+
.PARAMETER Filter
15+
A filter object to apply when retrieving integrations.
16+
17+
.PARAMETER BatchSize
18+
The number of results to return per request. Must be between 1 and 1000. Defaults to 1000.
19+
20+
.EXAMPLE
21+
#Retrieve all integrations
22+
Get-LMIntegration
23+
24+
.EXAMPLE
25+
#Retrieve a specific integration by name
26+
Get-LMIntegration -Name "Slack-Integration"
27+
28+
.NOTES
29+
You must run Connect-LMAccount before running this command.
30+
31+
.INPUTS
32+
None. You cannot pipe objects to this command.
33+
34+
.OUTPUTS
35+
Returns integration objects from LogicMonitor.
36+
#>
37+
38+
function Get-LMIntegration {
39+
40+
[CmdletBinding(DefaultParameterSetName = 'All')]
41+
param (
42+
[Parameter(ParameterSetName = 'Id')]
43+
[Int]$Id,
44+
45+
[Parameter(ParameterSetName = 'Name')]
46+
[String]$Name,
47+
48+
[Parameter(ParameterSetName = 'Filter')]
49+
[Object]$Filter,
50+
51+
[ValidateRange(1, 1000)]
52+
[Int]$BatchSize = 1000
53+
)
54+
#Check if we are logged in and have valid api creds
55+
if ($Script:LMAuth.Valid) {
56+
57+
#Build header and uri
58+
$ResourcePath = "/setting/integrations"
59+
60+
#Initalize vars
61+
$QueryParams = ""
62+
$Count = 0
63+
$Done = $false
64+
$Results = @()
65+
66+
#Loop through requests
67+
while (!$Done) {
68+
#Build query params
69+
switch ($PSCmdlet.ParameterSetName) {
70+
"All" { $QueryParams = "?size=$BatchSize&offset=$Count&sort=+id" }
71+
"Id" { $resourcePath += "/$Id" }
72+
"Name" { $QueryParams = "?filter=name:`"$Name`"&size=$BatchSize&offset=$Count&sort=+id" }
73+
"Filter" {
74+
#List of allowed filter props
75+
$PropList = @()
76+
$ValidFilter = Format-LMFilter -Filter $Filter -PropList $PropList
77+
$QueryParams = "?filter=$ValidFilter&size=$BatchSize&offset=$Count&sort=+id"
78+
}
79+
}
80+
81+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "GET" -ResourcePath $ResourcePath
82+
$Uri = "https://$($Script:LMAuth.Portal).$(Get-LMPortalURI)" + $ResourcePath + $QueryParams
83+
84+
85+
86+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
87+
88+
#Issue request
89+
$Response = Invoke-LMRestMethod -CallerPSCmdlet $PSCmdlet -Uri $Uri -Method "GET" -Headers $Headers[0] -WebSession $Headers[1]
90+
91+
#Stop looping if single device, no need to continue
92+
if ($PSCmdlet.ParameterSetName -eq "Id") {
93+
$Done = $true
94+
return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.Integration" )
95+
}
96+
#Check result size and if needed loop again
97+
else {
98+
[Int]$Total = $Response.Total
99+
[Int]$Count += ($Response.Items | Measure-Object).Count
100+
$Results += $Response.Items
101+
if ($Count -ge $Total) {
102+
$Done = $true
103+
}
104+
}
105+
106+
}
107+
return (Add-ObjectTypeInfo -InputObject $Results -TypeName "LogicMonitor.Integration" )
108+
}
109+
else {
110+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
111+
}
112+
}
113+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<#
2+
.SYNOPSIS
3+
Removes a LogicMonitor escalation chain.
4+
5+
.DESCRIPTION
6+
The Remove-LMEscalationChain function removes a LogicMonitor escalation chain based on either its ID or name.
7+
8+
.PARAMETER Id
9+
Specifies the ID of the escalation chain to be removed. This parameter is mandatory when using the 'Id' parameter set.
10+
11+
.PARAMETER Name
12+
Specifies the name of the escalation chain to be removed. This parameter is mandatory when using the 'Name' parameter set.
13+
14+
.EXAMPLE
15+
Remove-LMEscalationChain -Id 12345
16+
Removes the LogicMonitor escalation chain with ID 12345.
17+
18+
.EXAMPLE
19+
Remove-LMEscalationChain -Name "Critical-Alerts"
20+
Removes the LogicMonitor escalation chain with the name "Critical-Alerts".
21+
22+
.INPUTS
23+
You can pipe input to this function.
24+
25+
.OUTPUTS
26+
Returns a PSCustomObject containing the ID of the removed escalation chain and a message indicating the success of the removal operation.
27+
#>
28+
function Remove-LMEscalationChain {
29+
30+
[CmdletBinding(DefaultParameterSetName = 'Id', SupportsShouldProcess, ConfirmImpact = 'High')]
31+
param (
32+
[Parameter(Mandatory, ParameterSetName = 'Id', ValueFromPipelineByPropertyName)]
33+
[Int]$Id,
34+
35+
[Parameter(Mandatory, ParameterSetName = 'Name')]
36+
[String]$Name
37+
38+
)
39+
#Check if we are logged in and have valid api creds
40+
begin {}
41+
process {
42+
if ($Script:LMAuth.Valid) {
43+
44+
#Lookup Id if supplying name
45+
if ($Name) {
46+
$LookupResult = (Get-LMEscalationChain -Name $Name).Id
47+
if (Test-LookupResult -Result $LookupResult -LookupString $Name) {
48+
return
49+
}
50+
$Id = $LookupResult
51+
}
52+
53+
if ($PSItem) {
54+
$Message = "Id: $Id | Name: $($PSItem.name)"
55+
}
56+
elseif ($Name) {
57+
$Message = "Id: $Id | Name: $Name"
58+
}
59+
else {
60+
$Message = "Id: $Id"
61+
}
62+
63+
#Build header and uri
64+
$ResourcePath = "/setting/alert/chains/$Id"
65+
66+
67+
if ($PSCmdlet.ShouldProcess($Message, "Remove Escalation Chain")) {
68+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "DELETE" -ResourcePath $ResourcePath
69+
$Uri = "https://$($Script:LMAuth.Portal).$(Get-LMPortalURI)" + $ResourcePath
70+
71+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
72+
73+
#Issue request
74+
Invoke-LMRestMethod -CallerPSCmdlet $PSCmdlet -Uri $Uri -Method "DELETE" -Headers $Headers[0] -WebSession $Headers[1] | Out-Null
75+
76+
$Result = [PSCustomObject]@{
77+
Id = $Id
78+
Message = "Successfully removed ($Message)"
79+
}
80+
81+
return $Result
82+
}
83+
84+
}
85+
else {
86+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
87+
}
88+
}
89+
end {}
90+
}
91+

Public/Remove-LMIntegration.ps1

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<#
2+
.SYNOPSIS
3+
Removes a LogicMonitor integration.
4+
5+
.DESCRIPTION
6+
The Remove-LMIntegration function removes a LogicMonitor integration based on either its ID or name.
7+
8+
.PARAMETER Id
9+
Specifies the ID of the integration to be removed. This parameter is mandatory when using the 'Id' parameter set.
10+
11+
.PARAMETER Name
12+
Specifies the name of the integration to be removed. This parameter is mandatory when using the 'Name' parameter set.
13+
14+
.EXAMPLE
15+
Remove-LMIntegration -Id 12345
16+
Removes the LogicMonitor integration with ID 12345.
17+
18+
.EXAMPLE
19+
Remove-LMIntegration -Name "Slack-Integration"
20+
Removes the LogicMonitor integration with the name "Slack-Integration".
21+
22+
.INPUTS
23+
You can pipe input to this function.
24+
25+
.OUTPUTS
26+
Returns a PSCustomObject containing the ID of the removed integration and a message indicating the success of the removal operation.
27+
#>
28+
function Remove-LMIntegration {
29+
30+
[CmdletBinding(DefaultParameterSetName = 'Id', SupportsShouldProcess, ConfirmImpact = 'High')]
31+
param (
32+
[Parameter(Mandatory, ParameterSetName = 'Id', ValueFromPipelineByPropertyName)]
33+
[Int]$Id,
34+
35+
[Parameter(Mandatory, ParameterSetName = 'Name')]
36+
[String]$Name
37+
38+
)
39+
#Check if we are logged in and have valid api creds
40+
begin {}
41+
process {
42+
if ($Script:LMAuth.Valid) {
43+
44+
#Lookup Id if supplying name
45+
if ($Name) {
46+
$LookupResult = (Get-LMIntegration -Name $Name).Id
47+
if (Test-LookupResult -Result $LookupResult -LookupString $Name) {
48+
return
49+
}
50+
$Id = $LookupResult
51+
}
52+
53+
if ($PSItem) {
54+
$Message = "Id: $Id | Name: $($PSItem.name)"
55+
}
56+
elseif ($Name) {
57+
$Message = "Id: $Id | Name: $Name"
58+
}
59+
else {
60+
$Message = "Id: $Id"
61+
}
62+
63+
#Build header and uri
64+
$ResourcePath = "/setting/integrations/$Id"
65+
66+
67+
if ($PSCmdlet.ShouldProcess($Message, "Remove Integration")) {
68+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "DELETE" -ResourcePath $ResourcePath
69+
$Uri = "https://$($Script:LMAuth.Portal).$(Get-LMPortalURI)" + $ResourcePath
70+
71+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
72+
73+
#Issue request
74+
Invoke-LMRestMethod -CallerPSCmdlet $PSCmdlet -Uri $Uri -Method "DELETE" -Headers $Headers[0] -WebSession $Headers[1] | Out-Null
75+
76+
$Result = [PSCustomObject]@{
77+
Id = $Id
78+
Message = "Successfully removed ($Message)"
79+
}
80+
81+
return $Result
82+
}
83+
84+
}
85+
else {
86+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
87+
}
88+
}
89+
end {}
90+
}
91+

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,23 @@ Connect-LMAccount -UseCachedCredential
7979
- **Get-LMRecentlyDeleted**: Retrieve recycle-bin entries with optional date, resource type, and deleted-by filters.
8080
- **Restore-LMRecentlyDeleted**: Batch restore recycle-bin items by recycle identifier.
8181
- **Remove-LMRecentlyDeleted**: Permanently delete recycle-bin entries in bulk.
82+
- **Get-LMIntegration**: Retrieve integration configurations from LogicMonitor.
83+
- **Remove-LMIntegration**: Remove integrations by ID or name.
84+
- **Remove-LMEscalationChain**: Remove escalation chains by ID or name.
85+
- **Invoke-LMReportExecution**: Trigger on-demand execution of LogicMonitor reports with optional admin impersonation and custom email recipients.
86+
- **Get-LMReportExecutionTask**: Check the status and retrieve results of previously triggered report executions.
8287

8388
### Updated Cmdlets
8489
- **Update-LogicMonitorModule**: Hardened for non-blocking version checks; failures are logged via `Write-Verbose` and never terminate connecting cmdlets.
8590
- **Export-LMDeviceData**: CSV exports now expand datapoints into individual rows and JSON exports capture deeper datapoint structures.
91+
- **Set-LMWebsite**: Added `alertExpr` alias for `SSLAlertThresholds` parameter for improved API compatibility. Updated synopsis to reflect enhanced parameter validation.
92+
- **New-LMWebsite**: Added `alertExpr` alias for `SSLAlertThresholds` parameter for improved API compatibility.
93+
- **Format-LMFilter**: Enhanced filter string escaping to properly handle special characters like parentheses, dollar signs, ampersands, and brackets in filter expressions.
94+
95+
### Bug Fixes
96+
- **Add-ObjectTypeInfo**: Fixed "Cannot bind argument to parameter 'InputObject' because it is null" error by adding `[AllowNull()]` attribute to handle successful but null API responses.
97+
- **Resolve-LMDebugInfo**: Improved HTTP method detection logic to correctly identify request types (GET, POST, PATCH, DELETE) based on cmdlet naming conventions and headers, fixing incorrect debug output.
98+
- **Invoke-LMRestMethod**: Added cleanup of internal `__LMMethod` diagnostic header before dispatching requests to prevent API errors.
8699

87100
### Examples
88101
```powershell
@@ -97,6 +110,19 @@ Get-LMRecentlyDeleted -DeletedAfter (Get-Date).AddMonths(-1) | Select-Object -Ex
97110
98111
# Export device datapoints to CSV with flattened datapoint rows
99112
Export-LMDeviceData -DeviceId 12345 -StartDate (Get-Date).AddHours(-6) -ExportFormat csv -ExportPath "C:\\Exports"
113+
114+
# Retrieve all integrations
115+
Get-LMIntegration
116+
117+
# Remove an integration by name
118+
Remove-LMIntegration -Name "Slack-Integration"
119+
120+
# Remove an escalation chain by ID
121+
Remove-LMEscalationChain -Id 123
122+
123+
# Trigger a report execution and check its status
124+
$task = Invoke-LMReportExecution -Name "Monthly Availability" -WithAdminId 101 -ReceiveEmails "ops@example.com"
125+
Get-LMReportExecutionTask -ReportName "Monthly Availability" -TaskId $task.taskId
100126
```
101127

102128

0 commit comments

Comments
 (0)