Skip to content

Commit 5bd69c7

Browse files
Merge pull request #12 from logicmonitor/pre-release
6.3 pre release
2 parents f5aeb1a + 04bc126 commit 5bd69c7

11 files changed

+334
-36
lines changed

Logic.Monitor.Format.ps1xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,53 @@
14671467
</TableRowEntries>
14681468
</TableControl>
14691469
</View>
1470+
<!-- New View LogicMonitor.Logsource-->
1471+
<View>
1472+
<Name>LogicMonitorLogsource</Name>
1473+
<ViewSelectedBy>
1474+
<TypeName>LogicMonitor.Logsource</TypeName>
1475+
</ViewSelectedBy>
1476+
<TableControl>
1477+
<TableHeaders>
1478+
<TableColumnHeader>
1479+
<Label>id</Label>
1480+
</TableColumnHeader>
1481+
<TableColumnHeader>
1482+
<Label>name</Label>
1483+
</TableColumnHeader>
1484+
<TableColumnHeader>
1485+
<Label>logFields</Label>
1486+
</TableColumnHeader>
1487+
<TableColumnHeader>
1488+
<Label>resourceMapping</Label>
1489+
</TableColumnHeader>
1490+
<TableColumnHeader>
1491+
<Label>description</Label>
1492+
</TableColumnHeader>
1493+
</TableHeaders>
1494+
<TableRowEntries>
1495+
<TableRowEntry>
1496+
<TableColumnItems>
1497+
<TableColumnItem>
1498+
<PropertyName>id</PropertyName>
1499+
</TableColumnItem>
1500+
<TableColumnItem>
1501+
<PropertyName>name</PropertyName>
1502+
</TableColumnItem>
1503+
<TableColumnItem>
1504+
<PropertyName>logFields</PropertyName>
1505+
</TableColumnItem>
1506+
<TableColumnItem>
1507+
<PropertyName>resourceMapping</PropertyName>
1508+
</TableColumnItem>
1509+
<TableColumnItem>
1510+
<PropertyName>description</PropertyName>
1511+
</TableColumnItem>
1512+
</TableColumnItems>
1513+
</TableRowEntry>
1514+
</TableRowEntries>
1515+
</TableControl>
1516+
</View>
14701517
<!-- New View LogicMonitor.Propertysource-->
14711518
<View>
14721519
<Name>LogicMonitorPropertysource</Name>

Public/Export-LMLogicModule.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Function Export-LMLogicModule {
4747
[String]$LogicModuleName,
4848

4949
[Parameter(Mandatory)]
50-
[ValidateSet("datasources", "propertyrules", "eventsources", "topologysources", "configsources")]
50+
[ValidateSet("datasources", "propertyrules", "eventsources", "topologysources", "configsources","logsources")]
5151
[String]$Type,
5252

5353
[String]$DownloadPath = (Get-Location).Path
@@ -91,6 +91,11 @@ Function Export-LMLogicModule {
9191
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
9292
$QueryParams = "?format=xml&v=3"
9393
}
94+
"logsources" {
95+
$LogicModuleInfo = Get-LMLogSource -Name $LogicModuleName
96+
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
97+
$QueryParams = "?format=xml&v=3"
98+
}
9499
}
95100
#Verify our query only returned one result
96101
If (Test-LookupResult -Result $LogicModuleInfo.Id -LookupString $LogicModuleName) {
@@ -126,6 +131,11 @@ Function Export-LMLogicModule {
126131
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
127132
$QueryParams = "?format=xml&v=3"
128133
}
134+
"logsources" {
135+
$LogicModuleInfo = Get-LMLogSource -Id $LogicModuleId
136+
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
137+
$QueryParams = "?format=xml&v=3"
138+
}
129139
}
130140
}
131141

Public/Get-LMAlert.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Function Get-LMAlert {
6262
[ValidateSet("*", "Warning", "Error", "Critical")]
6363
[String]$Severity = "*",
6464

65-
[ValidateSet("*", "websiteAlert", "dataSourceAlert", "eventSourceAlert", "logAlert")]
65+
[ValidateSet("*", "websiteAlert", "dataSourceAlert", "eventAlert", "logAlert")]
6666
[String]$Type = "*",
6767

6868
[Boolean]$ClearedAlerts = $false,

Public/Get-LMLogSource.ps1

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Function Get-LMLogSource {
2+
3+
[CmdletBinding(DefaultParameterSetName = 'All')]
4+
Param (
5+
[Parameter(ParameterSetName = 'Id')]
6+
[Int]$Id,
7+
8+
[Parameter(ParameterSetName = 'Name')]
9+
[String]$Name,
10+
11+
[Parameter(ParameterSetName = 'Filter')]
12+
[Object]$Filter,
13+
14+
[ValidateRange(1, 1000)]
15+
[Int]$BatchSize = 1000
16+
)
17+
#Check if we are logged in and have valid api creds
18+
If ($Script:LMAuth.Valid) {
19+
20+
#Build header and uri
21+
$ResourcePath = "/setting/logsources"
22+
23+
#Initalize vars
24+
$QueryParams = ""
25+
$Count = 0
26+
$Done = $false
27+
$Results = @()
28+
29+
#Loop through requests
30+
While (!$Done) {
31+
#Build query params
32+
Switch ($PSCmdlet.ParameterSetName) {
33+
"All" { $QueryParams = "?size=$BatchSize&offset=$Count&sort=+id" }
34+
"Id" { $resourcePath += "/$Id" }
35+
"Name" { $QueryParams = "?filter=name:`"$Name`"&size=$BatchSize&offset=$Count&sort=+id" }
36+
"Filter" {
37+
#List of allowed filter props
38+
$PropList = @()
39+
$ValidFilter = Format-LMFilter -Filter $Filter -PropList $PropList
40+
$QueryParams = "?filter=$ValidFilter&size=$BatchSize&offset=$Count&sort=+id"
41+
}
42+
}
43+
Try {
44+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "GET" -ResourcePath $ResourcePath
45+
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath + $QueryParams
46+
47+
48+
49+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
50+
51+
#Issue request
52+
$Response = Invoke-RestMethod -Uri $Uri -Method "GET" -Headers $Headers[0] -WebSession $Headers[1]
53+
54+
#Stop looping if single device, no need to continue
55+
If ($PSCmdlet.ParameterSetName -eq "Id") {
56+
$Done = $true
57+
Return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.Logsource")
58+
}
59+
#Check result size and if needed loop again
60+
Else {
61+
[Int]$Total = $Response.Total
62+
[Int]$Count += ($Response.Items | Measure-Object).Count
63+
$Results += $Response.Items
64+
If ($Count -ge $Total) {
65+
$Done = $true
66+
}
67+
}
68+
}
69+
Catch [Exception] {
70+
$Proceed = Resolve-LMException -LMException $PSItem
71+
If (!$Proceed) {
72+
Return
73+
}
74+
}
75+
}
76+
Return (Add-ObjectTypeInfo -InputObject $Results -TypeName "LogicMonitor.Logsource")
77+
}
78+
Else {
79+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
80+
}
81+
}

Public/Import-LMLogicModule.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Function Import-LMLogicModule {
3737
[Parameter(Mandatory, ParameterSetName = 'File')]
3838
[Object]$File,
3939

40-
[ValidateSet("datasource", "propertyrules", "eventsource", "topologysource", "configsource")]
40+
[ValidateSet("datasource", "propertyrules", "eventsource", "topologysource", "configsource","logsource")]
4141
[String]$Type = "datasource",
4242

4343
[Boolean]$ForceOverwrite = $false

Public/New-LMOpsNote.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Function New-LMOpsNote {
6060
}
6161

6262
$Scope = @()
63-
If ($ResourceIds -or $WebsiteIds -or $DeviceGroupIds) {
63+
If ($DeviceIds -or $WebsiteIds -or $DeviceGroupIds) {
6464
Foreach ($id in $DeviceIds) {
6565
$Scope += [PSCustomObject]@{
6666
type = "device"
@@ -101,7 +101,7 @@ Function New-LMOpsNote {
101101
}
102102

103103
#Remove empty keys so we dont overwrite them
104-
@($Data.keys) | ForEach-Object { If ([string]::IsNullOrEmpty($Data[$_])) { $Data.Remove($_) } }
104+
@($Data.keys) | ForEach-Object { If ([string]::IsNullOrEmpty($Data[$_]) -and $_ -ne "scopes" -and $_ -ne "tags") { $Data.Remove($_) } }
105105

106106
$Data = ($Data | ConvertTo-Json)
107107

Public/Remove-LMLogsource.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Function Remove-LMLogsource {
2+
3+
[CmdletBinding(DefaultParameterSetName = 'Id', SupportsShouldProcess, ConfirmImpact = 'High')]
4+
Param (
5+
[Parameter(Mandatory, ParameterSetName = 'Id', ValueFromPipelineByPropertyName)]
6+
[Int]$Id,
7+
8+
[Parameter(Mandatory, ParameterSetName = 'Name')]
9+
[String]$Name
10+
11+
)
12+
13+
Begin {}
14+
Process {
15+
#Check if we are logged in and have valid api creds
16+
If ($Script:LMAuth.Valid) {
17+
18+
#Lookup Id if supplying username
19+
If ($Name) {
20+
$LookupResult = (Get-LMLogSource -Name $Name).Id
21+
If (Test-LookupResult -Result $LookupResult -LookupString $Name) {
22+
return
23+
}
24+
$Id = $LookupResult
25+
}
26+
27+
28+
#Build header and uri
29+
$ResourcePath = "/setting/logsources/$Id"
30+
31+
If ($PSItem) {
32+
$Message = "Id: $Id | Name: $($PSItem.name)"
33+
}
34+
Elseif ($Name) {
35+
$Message = "Id: $Id | Name: $Name"
36+
}
37+
Else {
38+
$Message = "Id: $Id"
39+
}
40+
41+
Try {
42+
If ($PSCmdlet.ShouldProcess($Message, "Remove Logsource")) {
43+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "DELETE" -ResourcePath $ResourcePath
44+
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath
45+
46+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
47+
48+
#Issue request
49+
$Response = Invoke-RestMethod -Uri $Uri -Method "DELETE" -Headers $Headers[0] -WebSession $Headers[1]
50+
51+
$Result = [PSCustomObject]@{
52+
Id = $Id
53+
Message = "Successfully removed ($Message)"
54+
}
55+
56+
Return $Result
57+
}
58+
}
59+
Catch [Exception] {
60+
$Proceed = Resolve-LMException -LMException $PSItem
61+
If (!$Proceed) {
62+
Return
63+
}
64+
}
65+
}
66+
Else {
67+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
68+
}
69+
}
70+
End {}
71+
}

Public/Set-LMDeviceDatasourceInstanceAlertSetting.ps1

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,32 @@ Function Set-LMDeviceDatasourceInstanceAlertSetting {
7272

7373
#Replace brakets in instance name
7474
$InstanceName = $InstanceName -replace "[\[\]]", "?"
75-
7675
#Lookup HdsiId
7776
If ($DatasourceName) {
7877
$LookupResult = (Get-LMDeviceDatasourceInstance -DatasourceName $DatasourceName -DeviceId $Id | Where-Object { $_.name -like "*$InstanceName" }).Id
79-
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
78+
If (Test-LookupResult -Result $LookupResult -LookupString $DatasourceName) {
8079
return
8180
}
8281
$HdsiId = $LookupResult
8382
}
8483
Else {
8584
$LookupResult = (Get-LMDeviceDatasourceInstance -DatasourceId $DatasourceId -DeviceId $Id | Where-Object { $_.name -like "*$InstanceName" }).Id
86-
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
85+
If (Test-LookupResult -Result $LookupResult -LookupString $DatasourceId) {
8786
return
8887
}
8988
$HdsiId = $LookupResult
9089
}
91-
92-
#Lookup HdsiId
93-
If ($DatapointName) {
90+
#Lookup DatapointId
91+
If ($DatasourceName) {
9492
$LookupResult = (Get-LMDeviceDatasourceInstanceAlertSetting -DatasourceName $DatasourceName -Id $Id -InstanceName $InstanceName | Where-Object { $_.dataPointName -eq $DatapointName }).Id
95-
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
93+
If (Test-LookupResult -Result $LookupResult -LookupString $DatapointName) {
9694
return
9795
}
9896
$DatapointId = $LookupResult
9997
}
10098
Else {
101-
$LookupResult = (Get-LMDeviceDatasourceInstance -DatasourceId $DatasourceId -Id $Id -InstanceName $InstanceName | Where-Object { $_.dataPointName -eq $DatapointName }).Id
102-
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
99+
$LookupResult = (Get-LMDeviceDatasourceInstanceAlertSetting -DatasourceId $DatasourceId -Id $Id -InstanceName $InstanceName | Where-Object { $_.dataPointName -eq $DatapointName }).Id
100+
If (Test-LookupResult -Result $LookupResult -LookupString $DatasourceId) {
103101
return
104102
}
105103
$DatapointId = $LookupResult
@@ -108,7 +106,7 @@ Function Set-LMDeviceDatasourceInstanceAlertSetting {
108106
#Build header and uri
109107
$ResourcePath = "/device/devices/$Id/devicedatasources/$HdsId/instances/$HdsiId/alertsettings/$DatapointId"
110108

111-
$Message = "Id: $Id | hostDatasourceId: $HdsId | datapointId: $DatapointId"
109+
$Message = "Id: $Id | hostDatasourceId: $HdsId | instanceId: $HdsiId | datapointId: $DatapointId"
112110

113111
Try {
114112
$Data = @{

Public/Test-LMAppliesToQuery.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<#
2+
.SYNOPSIS
3+
Tests the applies to query against the LogicMonitor API.
4+
5+
.DESCRIPTION
6+
The Test-LMAppliesToQuery function is used to test the applies to query against the LogicMonitor API.
7+
8+
.PARAMETER Query
9+
The applies to query to be tested.
10+
11+
.EXAMPLE
12+
Test-LMAppliesToQuery -Query "system.hostname == 'server01'"
13+
14+
This example tests the applies to query "system.hostname == 'server01'" against the LogicMonitor API and returns a list of matching devices.
15+
#>
16+
Function Test-LMAppliesToQuery {
17+
18+
[CmdletBinding()]
19+
Param (
20+
[Parameter(Mandatory)]
21+
[String]$Query
22+
23+
)
24+
#Check if we are logged in and have valid api creds
25+
If ($Script:LMAuth.Valid) {
26+
27+
28+
#Build header and uri
29+
$ResourcePath = "/functions"
30+
31+
Try {
32+
$Data = @{
33+
currentAppliesTo = $Query
34+
originalAppliesTo = $Query
35+
needInheritProps = $true
36+
type = "testAppliesTo"
37+
}
38+
39+
$Data = ($Data | ConvertTo-Json)
40+
41+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "POST" -ResourcePath $ResourcePath -Data $Data
42+
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath
43+
44+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation -Payload $Data
45+
46+
#Issue request
47+
$Response = (Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Data).currentMatches
48+
49+
Return $Response
50+
}
51+
Catch [Exception] {
52+
$Proceed = Resolve-LMException -LMException $PSItem
53+
If (!$Proceed) {
54+
Return
55+
}
56+
}
57+
}
58+
Else {
59+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
60+
}
61+
}

0 commit comments

Comments
 (0)