Skip to content

Commit 1350a38

Browse files
committed
Fix diagnostic sources
- Fix endpoint bug with diagnostic sources - Add new Get-LMDeviceLogSourceList cmdlet
1 parent 9d0f49e commit 1350a38

6 files changed

Lines changed: 258 additions & 4 deletions
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
external help file: Logic.Monitor-help.xml
3+
Module Name: Logic.Monitor
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Get-LMDeviceLogSourceList
9+
10+
## SYNOPSIS
11+
Retrieves a list of log sources for a LogicMonitor device.
12+
13+
## SYNTAX
14+
15+
### Id (Default)
16+
```
17+
Get-LMDeviceLogSourceList -Id <Int32> [-Filter <Object>] [-BatchSize <Int32>]
18+
[-ProgressAction <ActionPreference>] [<CommonParameters>]
19+
```
20+
21+
### Name
22+
```
23+
Get-LMDeviceLogSourceList [-Name <String>] [-Filter <Object>] [-BatchSize <Int32>]
24+
[-ProgressAction <ActionPreference>] [<CommonParameters>]
25+
```
26+
27+
## DESCRIPTION
28+
The Get-LMDeviceLogSourceList function retrieves all log sources associated with a specific device.
29+
The device can be identified by either ID or name, and the results can be filtered.
30+
31+
## EXAMPLES
32+
33+
### EXAMPLE 1
34+
```
35+
#Retrieve log sources by device ID
36+
Get-LMDeviceLogSourceList -Id 123
37+
```
38+
39+
### EXAMPLE 2
40+
```
41+
#Retrieve log sources by device name with filter
42+
Get-LMDeviceLogSourceList -Name "MyDevice" -Filter $filterObject
43+
```
44+
45+
## PARAMETERS
46+
47+
### -Id
48+
The ID of the device.
49+
Required for Id parameter set.
50+
51+
```yaml
52+
Type: Int32
53+
Parameter Sets: Id
54+
Aliases:
55+
56+
Required: True
57+
Position: Named
58+
Default value: 0
59+
Accept pipeline input: False
60+
Accept wildcard characters: False
61+
```
62+
63+
### -Name
64+
The name of the device.
65+
Required for Name parameter set.
66+
67+
```yaml
68+
Type: String
69+
Parameter Sets: Name
70+
Aliases:
71+
72+
Required: False
73+
Position: Named
74+
Default value: None
75+
Accept pipeline input: False
76+
Accept wildcard characters: False
77+
```
78+
79+
### -Filter
80+
A filter object to apply when retrieving log sources.
81+
This parameter is optional.
82+
83+
```yaml
84+
Type: Object
85+
Parameter Sets: (All)
86+
Aliases:
87+
88+
Required: False
89+
Position: Named
90+
Default value: None
91+
Accept pipeline input: False
92+
Accept wildcard characters: False
93+
```
94+
95+
### -BatchSize
96+
The number of results to return per request.
97+
Must be between 1 and 1000.
98+
Defaults to 1000.
99+
100+
```yaml
101+
Type: Int32
102+
Parameter Sets: (All)
103+
Aliases:
104+
105+
Required: False
106+
Position: Named
107+
Default value: 1000
108+
Accept pipeline input: False
109+
Accept wildcard characters: False
110+
```
111+
112+
### -ProgressAction
113+
{{ Fill ProgressAction Description }}
114+
115+
```yaml
116+
Type: ActionPreference
117+
Parameter Sets: (All)
118+
Aliases: proga
119+
120+
Required: False
121+
Position: Named
122+
Default value: None
123+
Accept pipeline input: False
124+
Accept wildcard characters: False
125+
```
126+
127+
### CommonParameters
128+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
129+
130+
## INPUTS
131+
132+
### None. You cannot pipe objects to this command.
133+
## OUTPUTS
134+
135+
### Returns log source objects.
136+
## NOTES
137+
You must run Connect-LMAccount before running this command.
138+
139+
## RELATED LINKS
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<#
2+
.SYNOPSIS
3+
Retrieves a list of log sources for a LogicMonitor device.
4+
5+
.DESCRIPTION
6+
The Get-LMDeviceLogSourceList function retrieves all log sources associated with a specific device. The device can be identified by either ID or name, and the results can be filtered.
7+
8+
.PARAMETER Id
9+
The ID of the device. Required for Id parameter set.
10+
11+
.PARAMETER Name
12+
The name of the device. Required for Name parameter set.
13+
14+
.PARAMETER Filter
15+
A filter object to apply when retrieving log sources. This parameter is optional.
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 log sources by device ID
22+
Get-LMDeviceLogSourceList -Id 123
23+
24+
.EXAMPLE
25+
#Retrieve log sources by device name with filter
26+
Get-LMDeviceLogSourceList -Name "MyDevice" -Filter $filterObject
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 log source objects.
36+
#>
37+
38+
function Get-LMDeviceLogSourceList {
39+
40+
[CmdletBinding(DefaultParameterSetName = 'Id')]
41+
param (
42+
[Parameter(Mandatory, ParameterSetName = 'Id')]
43+
[Int]$Id,
44+
45+
[Parameter(ParameterSetName = 'Name')]
46+
[String]$Name,
47+
48+
[Object]$Filter,
49+
50+
[ValidateRange(1, 1000)]
51+
[Int]$BatchSize = 1000
52+
)
53+
#Check if we are logged in and have valid api creds
54+
if ($Script:LMAuth.Valid) {
55+
56+
if ($Name) {
57+
$LookupResult = (Get-LMDevice -Name $Name).Id
58+
if (Test-LookupResult -Result $LookupResult -LookupString $Name) {
59+
return
60+
}
61+
$Id = $LookupResult
62+
}
63+
64+
#Build header and uri
65+
$ResourcePath = "/device/devices/$Id/devicelogsources"
66+
67+
#Initalize vars
68+
$QueryParams = ""
69+
$Count = 0
70+
$Done = $false
71+
$Results = @()
72+
73+
#Loop through requests
74+
while (!$Done) {
75+
#Build query params
76+
$QueryParams = "?size=$BatchSize&offset=$Count&sort=+id"
77+
78+
if ($Filter) {
79+
$ValidFilter = Format-LMFilter -Filter $Filter -ResourcePath $ResourcePath
80+
$QueryParams = "?filter=$ValidFilter&size=$BatchSize&offset=$Count&sort=+id"
81+
}
82+
83+
84+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "GET" -ResourcePath $ResourcePath
85+
$Uri = "https://$($Script:LMAuth.Portal).$(Get-LMPortalURI)" + $ResourcePath + $QueryParams
86+
87+
88+
89+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
90+
91+
#Issue request
92+
$Response = Invoke-LMRestMethod -CallerPSCmdlet $PSCmdlet -Uri $Uri -Method "GET" -Headers $Headers[0] -WebSession $Headers[1]
93+
94+
#Stop looping if single device, no need to continue
95+
if (![bool]$Response.psobject.Properties["total"]) {
96+
$Done = $true
97+
return $Response
98+
}
99+
#Check result size and if needed loop again
100+
else {
101+
[Int]$Total = $Response.Total
102+
[Int]$Count += ($Response.Items | Measure-Object).Count
103+
$Results += $Response.Items
104+
if ($Count -ge $Total) {
105+
$Done = $true
106+
}
107+
}
108+
109+
}
110+
return $Results
111+
}
112+
else {
113+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
114+
}
115+
}

Public/Get-LMDiagnosticSource.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Get-LMDiagnosticSource {
5858
#Check if we are logged in and have valid api creds
5959
if ($Script:LMAuth.Valid) {
6060

61-
$ResourcePath = "/setting/diagnosticssources"
61+
$ResourcePath = "/setting/diagnosticsources"
6262

6363
$QueryParams = ""
6464
$Count = 0

Public/New-LMDiagnosticSource.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function New-LMDiagnosticSource {
3535
begin {}
3636
process {
3737
if ($Script:LMAuth.Valid) {
38-
$ResourcePath = "/setting/diagnosticssources"
38+
$ResourcePath = "/setting/diagnosticsources"
3939
$Message = "DiagnosticSource Name: $($DiagnosticSource.name)"
4040
$Data = $DiagnosticSource
4141
$Data = ($Data | ConvertTo-Json -Depth 10)

Public/Remove-LMDiagnosticSource.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Remove-LMDiagnosticSource {
4242
if (Test-LookupResult -Result $LookupResult -LookupString $Name) { return }
4343
$Id = $LookupResult
4444
}
45-
$ResourcePath = "/setting/diagnosticssources/$Id"
45+
$ResourcePath = "/setting/diagnosticsources/$Id"
4646
$Message = "Id: $Id | Name: $Name"
4747

4848
if ($PSCmdlet.ShouldProcess($Message, "Remove DiagnosticSource")) {

Public/Set-LMDiagnosticSource.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function Set-LMDiagnosticSource {
7070
if (Test-LookupResult -Result $LookupResult -LookupString $Name) { return }
7171
$Id = $LookupResult
7272
}
73-
$ResourcePath = "/setting/diagnosticssources/$Id"
73+
$ResourcePath = "/setting/diagnosticsources/$Id"
7474
$Message = "Id: $Id | Name: $Name"
7575
$Data = @{
7676
name = $NewName

0 commit comments

Comments
 (0)