-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from logicmonitor/pre-release
6.3 pre release
- Loading branch information
Showing
11 changed files
with
334 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} |
Oops, something went wrong.