Skip to content

Commit efca4e0

Browse files
committed
bug fix connect-lmaccount
1 parent 5fa42a3 commit efca4e0

File tree

4 files changed

+121
-8
lines changed

4 files changed

+121
-8
lines changed

Public/Connect-LMAccount.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Function Connect-LMAccount {
9191
Add-Type -AssemblyName System.Web
9292
}
9393

94-
If(!$DisableConsoleLogging.IsPresent) {
94+
If($DisableConsoleLogging.IsPresent) {
9595
$InformationPreference = 'SilentlyContinue'
9696
}
9797
Else {

Public/Invoke-LMAWSAccountTest.ps1

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ The external ID of the AWS account.
1111
.PARAMETER AccountId
1212
The account ID of the AWS account.
1313
14-
.PARAMETER AccessId
15-
The access ID of the AWS account.
16-
17-
.PARAMETER AccessKey
18-
The access key of the AWS account.
19-
2014
.PARAMETER AssumedRoleARN
2115
The assumed role ARN of the AWS account.
2216
@@ -27,7 +21,7 @@ The list of services to be checked during the test. Default value is a comma-sep
2721
The device group ID to which the AWS account belongs. Default value is -1 for no group.
2822
2923
.EXAMPLE
30-
Invoke-LMAWSAccountTest -ExternalId "123456" -AccountId "987654" -AccessId "AKI123" -AccessKey "abc123" -AssumedRoleARN "arn:aws:iam::123456789012:role/MyRole" -CheckedServices "EC2,S3,RDS" -GroupId 123
24+
Invoke-LMAWSAccountTest -ExternalId "123456" -AccountId "987654" -AssumedRoleARN "arn:aws:iam::123456789012:role/MyRole" -CheckedServices "EC2,S3,RDS" -GroupId 123
3125
3226
This example invokes a test for an AWS account with the specified parameters.
3327

Public/New-LMDatasource.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Function New-LMDatasource {
2+
3+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'None')]
4+
Param (
5+
[Parameter(Mandatory)]
6+
[PSCustomObject]$Datasource #follow the schema model listed here: https://www.logicmonitor.com/swagger-ui-master/api-v3/dist/#/Datasources/addDatasourceById
7+
)
8+
#Check if we are logged in and have valid api creds
9+
Begin {}
10+
Process {
11+
If ($Script:LMAuth.Valid) {
12+
13+
#Build header and uri
14+
$ResourcePath = "/setting/datasources"
15+
16+
$Message = "LogicModule Name: $($Datasource.name)"
17+
18+
Try {
19+
$Data = $Datasource
20+
21+
$Data = ($Data | ConvertTo-Json -Depth 10)
22+
23+
If ($PSCmdlet.ShouldProcess($Message, "New Datasource")) {
24+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "POST" -ResourcePath $ResourcePath -Data $Data
25+
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath
26+
27+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation -Payload $Data
28+
29+
#Issue request
30+
$Response = Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Data
31+
32+
Return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.Datasource" )
33+
}
34+
}
35+
Catch [Exception] {
36+
$Proceed = Resolve-LMException -LMException $PSItem
37+
If (!$Proceed) {
38+
Return
39+
}
40+
}
41+
}
42+
Else {
43+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
44+
}
45+
}
46+
End {}
47+
}

Public/New-LMLogicModule.ps1

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Function New-LMLogicModule {
2+
3+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'None')]
4+
Param (
5+
[Parameter(Mandatory)]
6+
[PSCustomObject]$LogicModule, #follow the schema model listed here: https://www.logicmonitor.com/swagger-ui-master/api-v3/dist/#/Datasources/addDatasourceById,
7+
8+
[Parameter(Mandatory)]
9+
[ValidateSet("datasources", "propertyrules", "topologysources", "eventsources","logsources","configsources")]
10+
[String]$Type
11+
)
12+
#Check if we are logged in and have valid api creds
13+
Begin {}
14+
Process {
15+
If ($Script:LMAuth.Valid) {
16+
17+
#Build header and uri
18+
$ResourcePath = "/setting/$Type"
19+
20+
$Message = "LogicModule Name: $($LogicModule.name) | Type: $Type"
21+
22+
Switch ($Type) {
23+
"datasources" {
24+
$ObjectType = "LogicMonitor.Datasource"
25+
}
26+
"propertyrules" {
27+
$ObjectType = "LogicMonitor.PropertySource"
28+
}
29+
"topologysources" {
30+
$ObjectType = "LogicMonitor.Topologysource"
31+
}
32+
"eventsources" {
33+
$ObjectType = "LogicMonitor.EventSource"
34+
}
35+
"logsources" {
36+
$ObjectType = "LogicMonitor.Logsource"
37+
}
38+
"configsources" {
39+
$ObjectType = "LogicMonitor.ConfigSource"
40+
}
41+
}
42+
43+
Try {
44+
$Data = $LogicModule
45+
46+
$Data = ($Data | ConvertTo-Json -Depth 10)
47+
48+
If ($PSCmdlet.ShouldProcess($Message, "New LogicModule")) {
49+
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "POST" -ResourcePath $ResourcePath -Data $Data
50+
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath
51+
52+
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation -Payload $Data
53+
54+
#Issue request
55+
$Response = Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Data
56+
57+
Return (Add-ObjectTypeInfo -InputObject $Response -TypeName $ObjectType )
58+
}
59+
}
60+
Catch [Exception] {
61+
$Proceed = Resolve-LMException -LMException $PSItem
62+
If (!$Proceed) {
63+
Return
64+
}
65+
}
66+
}
67+
Else {
68+
Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again."
69+
}
70+
}
71+
End {}
72+
}

0 commit comments

Comments
 (0)