Skip to content

Commit

Permalink
Merge pull request #12 from logicmonitor/pre-release
Browse files Browse the repository at this point in the history
6.3 pre release
  • Loading branch information
stevevillardi authored Aug 20, 2024
2 parents f5aeb1a + 04bc126 commit 5bd69c7
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 36 deletions.
47 changes: 47 additions & 0 deletions Logic.Monitor.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,53 @@
</TableRowEntries>
</TableControl>
</View>
<!-- New View LogicMonitor.Logsource-->
<View>
<Name>LogicMonitorLogsource</Name>
<ViewSelectedBy>
<TypeName>LogicMonitor.Logsource</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>id</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>logFields</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>resourceMapping</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>description</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>logFields</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>resourceMapping</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>description</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<!-- New View LogicMonitor.Propertysource-->
<View>
<Name>LogicMonitorPropertysource</Name>
Expand Down
12 changes: 11 additions & 1 deletion Public/Export-LMLogicModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Function Export-LMLogicModule {
[String]$LogicModuleName,

[Parameter(Mandatory)]
[ValidateSet("datasources", "propertyrules", "eventsources", "topologysources", "configsources")]
[ValidateSet("datasources", "propertyrules", "eventsources", "topologysources", "configsources","logsources")]
[String]$Type,

[String]$DownloadPath = (Get-Location).Path
Expand Down Expand Up @@ -91,6 +91,11 @@ Function Export-LMLogicModule {
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
$QueryParams = "?format=xml&v=3"
}
"logsources" {
$LogicModuleInfo = Get-LMLogSource -Name $LogicModuleName
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
$QueryParams = "?format=xml&v=3"
}
}
#Verify our query only returned one result
If (Test-LookupResult -Result $LogicModuleInfo.Id -LookupString $LogicModuleName) {
Expand Down Expand Up @@ -126,6 +131,11 @@ Function Export-LMLogicModule {
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
$QueryParams = "?format=xml&v=3"
}
"logsources" {
$LogicModuleInfo = Get-LMLogSource -Id $LogicModuleId
$ExportPath = $DownloadPath + "\$($LogicModuleInfo.name).xml"
$QueryParams = "?format=xml&v=3"
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Public/Get-LMAlert.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Function Get-LMAlert {
[ValidateSet("*", "Warning", "Error", "Critical")]
[String]$Severity = "*",

[ValidateSet("*", "websiteAlert", "dataSourceAlert", "eventSourceAlert", "logAlert")]
[ValidateSet("*", "websiteAlert", "dataSourceAlert", "eventAlert", "logAlert")]
[String]$Type = "*",

[Boolean]$ClearedAlerts = $false,
Expand Down
81 changes: 81 additions & 0 deletions Public/Get-LMLogSource.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Function Get-LMLogSource {

[CmdletBinding(DefaultParameterSetName = 'All')]
Param (
[Parameter(ParameterSetName = 'Id')]
[Int]$Id,

[Parameter(ParameterSetName = 'Name')]
[String]$Name,

[Parameter(ParameterSetName = 'Filter')]
[Object]$Filter,

[ValidateRange(1, 1000)]
[Int]$BatchSize = 1000
)
#Check if we are logged in and have valid api creds
If ($Script:LMAuth.Valid) {

#Build header and uri
$ResourcePath = "/setting/logsources"

#Initalize vars
$QueryParams = ""
$Count = 0
$Done = $false
$Results = @()

#Loop through requests
While (!$Done) {
#Build query params
Switch ($PSCmdlet.ParameterSetName) {
"All" { $QueryParams = "?size=$BatchSize&offset=$Count&sort=+id" }
"Id" { $resourcePath += "/$Id" }
"Name" { $QueryParams = "?filter=name:`"$Name`"&size=$BatchSize&offset=$Count&sort=+id" }
"Filter" {
#List of allowed filter props
$PropList = @()
$ValidFilter = Format-LMFilter -Filter $Filter -PropList $PropList
$QueryParams = "?filter=$ValidFilter&size=$BatchSize&offset=$Count&sort=+id"
}
}
Try {
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "GET" -ResourcePath $ResourcePath
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath + $QueryParams



Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation

#Issue request
$Response = Invoke-RestMethod -Uri $Uri -Method "GET" -Headers $Headers[0] -WebSession $Headers[1]

#Stop looping if single device, no need to continue
If ($PSCmdlet.ParameterSetName -eq "Id") {
$Done = $true
Return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.Logsource")
}
#Check result size and if needed loop again
Else {
[Int]$Total = $Response.Total
[Int]$Count += ($Response.Items | Measure-Object).Count
$Results += $Response.Items
If ($Count -ge $Total) {
$Done = $true
}
}
}
Catch [Exception] {
$Proceed = Resolve-LMException -LMException $PSItem
If (!$Proceed) {
Return
}
}
}
Return (Add-ObjectTypeInfo -InputObject $Results -TypeName "LogicMonitor.Logsource")
}
Else {
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
}
}
2 changes: 1 addition & 1 deletion Public/Import-LMLogicModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Function Import-LMLogicModule {
[Parameter(Mandatory, ParameterSetName = 'File')]
[Object]$File,

[ValidateSet("datasource", "propertyrules", "eventsource", "topologysource", "configsource")]
[ValidateSet("datasource", "propertyrules", "eventsource", "topologysource", "configsource","logsource")]
[String]$Type = "datasource",

[Boolean]$ForceOverwrite = $false
Expand Down
4 changes: 2 additions & 2 deletions Public/New-LMOpsNote.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Function New-LMOpsNote {
}

$Scope = @()
If ($ResourceIds -or $WebsiteIds -or $DeviceGroupIds) {
If ($DeviceIds -or $WebsiteIds -or $DeviceGroupIds) {
Foreach ($id in $DeviceIds) {
$Scope += [PSCustomObject]@{
type = "device"
Expand Down Expand Up @@ -101,7 +101,7 @@ Function New-LMOpsNote {
}

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

$Data = ($Data | ConvertTo-Json)

Expand Down
71 changes: 71 additions & 0 deletions Public/Remove-LMLogsource.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Function Remove-LMLogsource {

[CmdletBinding(DefaultParameterSetName = 'Id', SupportsShouldProcess, ConfirmImpact = 'High')]
Param (
[Parameter(Mandatory, ParameterSetName = 'Id', ValueFromPipelineByPropertyName)]
[Int]$Id,

[Parameter(Mandatory, ParameterSetName = 'Name')]
[String]$Name

)

Begin {}
Process {
#Check if we are logged in and have valid api creds
If ($Script:LMAuth.Valid) {

#Lookup Id if supplying username
If ($Name) {
$LookupResult = (Get-LMLogSource -Name $Name).Id
If (Test-LookupResult -Result $LookupResult -LookupString $Name) {
return
}
$Id = $LookupResult
}


#Build header and uri
$ResourcePath = "/setting/logsources/$Id"

If ($PSItem) {
$Message = "Id: $Id | Name: $($PSItem.name)"
}
Elseif ($Name) {
$Message = "Id: $Id | Name: $Name"
}
Else {
$Message = "Id: $Id"
}

Try {
If ($PSCmdlet.ShouldProcess($Message, "Remove Logsource")) {
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "DELETE" -ResourcePath $ResourcePath
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath

Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation

#Issue request
$Response = Invoke-RestMethod -Uri $Uri -Method "DELETE" -Headers $Headers[0] -WebSession $Headers[1]

$Result = [PSCustomObject]@{
Id = $Id
Message = "Successfully removed ($Message)"
}

Return $Result
}
}
Catch [Exception] {
$Proceed = Resolve-LMException -LMException $PSItem
If (!$Proceed) {
Return
}
}
}
Else {
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
}
}
End {}
}
18 changes: 8 additions & 10 deletions Public/Set-LMDeviceDatasourceInstanceAlertSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,32 @@ Function Set-LMDeviceDatasourceInstanceAlertSetting {

#Replace brakets in instance name
$InstanceName = $InstanceName -replace "[\[\]]", "?"

#Lookup HdsiId
If ($DatasourceName) {
$LookupResult = (Get-LMDeviceDatasourceInstance -DatasourceName $DatasourceName -DeviceId $Id | Where-Object { $_.name -like "*$InstanceName" }).Id
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
If (Test-LookupResult -Result $LookupResult -LookupString $DatasourceName) {
return
}
$HdsiId = $LookupResult
}
Else {
$LookupResult = (Get-LMDeviceDatasourceInstance -DatasourceId $DatasourceId -DeviceId $Id | Where-Object { $_.name -like "*$InstanceName" }).Id
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
If (Test-LookupResult -Result $LookupResult -LookupString $DatasourceId) {
return
}
$HdsiId = $LookupResult
}

#Lookup HdsiId
If ($DatapointName) {
#Lookup DatapointId
If ($DatasourceName) {
$LookupResult = (Get-LMDeviceDatasourceInstanceAlertSetting -DatasourceName $DatasourceName -Id $Id -InstanceName $InstanceName | Where-Object { $_.dataPointName -eq $DatapointName }).Id
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
If (Test-LookupResult -Result $LookupResult -LookupString $DatapointName) {
return
}
$DatapointId = $LookupResult
}
Else {
$LookupResult = (Get-LMDeviceDatasourceInstance -DatasourceId $DatasourceId -Id $Id -InstanceName $InstanceName | Where-Object { $_.dataPointName -eq $DatapointName }).Id
If (Test-LookupResult -Result $LookupResult -LookupString $InstanceName) {
$LookupResult = (Get-LMDeviceDatasourceInstanceAlertSetting -DatasourceId $DatasourceId -Id $Id -InstanceName $InstanceName | Where-Object { $_.dataPointName -eq $DatapointName }).Id
If (Test-LookupResult -Result $LookupResult -LookupString $DatasourceId) {
return
}
$DatapointId = $LookupResult
Expand All @@ -108,7 +106,7 @@ Function Set-LMDeviceDatasourceInstanceAlertSetting {
#Build header and uri
$ResourcePath = "/device/devices/$Id/devicedatasources/$HdsId/instances/$HdsiId/alertsettings/$DatapointId"

$Message = "Id: $Id | hostDatasourceId: $HdsId | datapointId: $DatapointId"
$Message = "Id: $Id | hostDatasourceId: $HdsId | instanceId: $HdsiId | datapointId: $DatapointId"

Try {
$Data = @{
Expand Down
61 changes: 61 additions & 0 deletions Public/Test-LMAppliesToQuery.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<#
.SYNOPSIS
Tests the applies to query against the LogicMonitor API.
.DESCRIPTION
The Test-LMAppliesToQuery function is used to test the applies to query against the LogicMonitor API.
.PARAMETER Query
The applies to query to be tested.
.EXAMPLE
Test-LMAppliesToQuery -Query "system.hostname == 'server01'"
This example tests the applies to query "system.hostname == 'server01'" against the LogicMonitor API and returns a list of matching devices.
#>
Function Test-LMAppliesToQuery {

[CmdletBinding()]
Param (
[Parameter(Mandatory)]
[String]$Query

)
#Check if we are logged in and have valid api creds
If ($Script:LMAuth.Valid) {


#Build header and uri
$ResourcePath = "/functions"

Try {
$Data = @{
currentAppliesTo = $Query
originalAppliesTo = $Query
needInheritProps = $true
type = "testAppliesTo"
}

$Data = ($Data | ConvertTo-Json)

$Headers = New-LMHeader -Auth $Script:LMAuth -Method "POST" -ResourcePath $ResourcePath -Data $Data
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath

Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation -Payload $Data

#Issue request
$Response = (Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Data).currentMatches

Return $Response
}
Catch [Exception] {
$Proceed = Resolve-LMException -LMException $PSItem
If (!$Proceed) {
Return
}
}
}
Else {
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
}
}
Loading

0 comments on commit 5bd69c7

Please sign in to comment.