Skip to content

Commit eb15486

Browse files
Merge pull request #13 from logicmonitor/develop-6.4
prep 6.4 release
2 parents 5bd69c7 + d20dbf4 commit eb15486

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+572
-157
lines changed

.github/workflows/test-win.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Test Current Build on Windows Powershell 5.1
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches:
6+
- '**'
67
paths-ignore:
78
- '**.md'
89
- '**.yml'

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Test Current Build on PowerShell Core
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches:
6+
- '**'
67
paths-ignore:
78
- '**.md'
89
- '**.yml'

EXAMPLES.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
```powershell
66
Get-LMAlert -StartDate $(Get-Date).AddDays(-1) -EndDate $(Get-Date) -ClearedAlerts $true | Group-Object -Property resourceTemplateName,datapointName | select count, @{N='Name';E={$_.Name.Split(",")[0]}}, @{N='Datapoint';E={$_.Name.Split(",")[1]}} | Sort-Object -Property count -Descending
77
```
8+
#### Create a new collector, download the installer and silent install
9+
10+
```powershell
11+
#Connect to LogicMonitor account
12+
Connect-LMAccount -AccountName "<account name>" -AccessId "<access id>" -AccessKey "<access key>"
13+
14+
#Create new collector and download the installer
15+
$Collector = New-LMCollector -Description "<enter description>"
16+
$FilePath = Get-LMCollectorInstaller -Id $Collector.Id -Size "medium" -OSandArch "Win64" -DownloadPath "C:\temp"
17+
18+
#Install the collector silently
19+
.\$FilePath /q /a:administrator /p:'password'
20+
21+
#Disconnect from LogicMonitor account
22+
Disconnect-LMAccount
23+
```
824

925
#### Generate Website inventory report with specific properties
1026
```powershell

Logic.Monitor.Format.ps1xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,59 @@
22092209
</TableRowEntries>
22102210
</TableControl>
22112211
</View>
2212+
<!-- New View LogicMonitor.EventSource-->
2213+
<View>
2214+
<Name>LogicMonitorEventSource</Name>
2215+
<ViewSelectedBy>
2216+
<TypeName>LogicMonitor.EventSource</TypeName>
2217+
</ViewSelectedBy>
2218+
<TableControl>
2219+
<TableHeaders>
2220+
<TableColumnHeader>
2221+
<Label>id</Label>
2222+
</TableColumnHeader>
2223+
<TableColumnHeader>
2224+
<Label>name</Label>
2225+
</TableColumnHeader>
2226+
<TableColumnHeader>
2227+
<Label>collector</Label>
2228+
</TableColumnHeader>
2229+
<TableColumnHeader>
2230+
<Label>schedule</Label>
2231+
</TableColumnHeader>
2232+
<TableColumnHeader>
2233+
<Label>appliesTo</Label>
2234+
</TableColumnHeader>
2235+
<TableColumnHeader>
2236+
<Label>description</Label>
2237+
</TableColumnHeader>
2238+
</TableHeaders>
2239+
<TableRowEntries>
2240+
<TableRowEntry>
2241+
<TableColumnItems>
2242+
<TableColumnItem>
2243+
<PropertyName>id</PropertyName>
2244+
</TableColumnItem>
2245+
<TableColumnItem>
2246+
<PropertyName>name</PropertyName>
2247+
</TableColumnItem>
2248+
<TableColumnItem>
2249+
<PropertyName>collector</PropertyName>
2250+
</TableColumnItem>
2251+
<TableColumnItem>
2252+
<PropertyName>schedule</PropertyName>
2253+
</TableColumnItem>
2254+
<TableColumnItem>
2255+
<PropertyName>appliesTo</PropertyName>
2256+
</TableColumnItem>
2257+
<TableColumnItem>
2258+
<PropertyName>description</PropertyName>
2259+
</TableColumnItem>
2260+
</TableColumnItems>
2261+
</TableRowEntry>
2262+
</TableRowEntries>
2263+
</TableControl>
2264+
</View>
22122265
<!-- New View LogicMonitor.RepositoryLogicModules-->
22132266
<View>
22142267
<Name>RepositoryLogicModules</Name>

Private/Format-LMFilter.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Function Format-LMFilter {
6969
'\s+-le\s+' { $FormatedFilter += "<:" }
7070
'\s+-contains\s+' { $FormatedFilter += "~" }
7171
'\s+-notcontains\s+' { $FormatedFilter += "!~" }
72-
default { Write-LMHost "[ERROR]: Invalid filter syntax: $Filter" -ForegroundColor Red }
72+
default { throw "[ERROR]: Invalid filter syntax: $Filter" }
7373
}
7474
}
7575
Else {
@@ -78,10 +78,12 @@ Function Format-LMFilter {
7878
}
7979
}
8080
Else {
81-
Write-LMHost "[ERROR]: Invalid filter syntax: $SingleFilterArray" -ForegroundColor Red
81+
throw "[ERROR]: Invalid filter syntax: $SingleFilterArray"
82+
8283
}
8384
}
8485
}
86+
#$FormatedFilter = $FormatedFilter.Replace("\", "\\")
8587
Write-Debug "Constructed Filter-v2: $FormatedFilter"
8688
Return $FormatedFilter
8789
}

Private/Resolve-LMException.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Function Resolve-LMException {
2121
$RateLimitSize = $LMException.Exception.Response.Headers.Value[$LMException.Exception.Response.Headers.Key.IndexOf("x-rate-limit-limit")]
2222
#$RateLimitRemaining = $LMException.Exception.Response.Headers.Value[$LMException.Exception.Response.Headers.Key.IndexOf("x-rate-limit-remaining")]
2323

24-
Write-LMHost "Request exceeded rate limit window of $RateLimitSize requests over $RateLimitWindow seconds, retrying operation in $RateLimitWindow seconds" -ForegroundColor Yellow
24+
Write-Warning "Request exceeded rate limit window of $RateLimitSize requests over $RateLimitWindow seconds, retrying operation in $RateLimitWindow seconds"
2525
Start-Sleep -Seconds $RateLimitWindow
2626
return $true
2727
}

Private/Update-LogicMonitorModule.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,24 @@ Function Update-LogicMonitorModule {
6363

6464
# Uninstall the old version
6565
If ($CheckOnly) {
66-
Write-LMHost "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module, please consider upgrading to the latest version ($OnlineVersion) as soon as possible. Use the -AutoUpdateModule switch next time you connect to auto upgrade to the latest version." -ForegroundColor Yellow
66+
Write-Information "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module, please consider upgrading to the latest version ($OnlineVersion) as soon as possible. Use the -AutoUpdateModule switch next time you connect to auto upgrade to the latest version."
6767
}
6868
Elseif ($UninstallFirst -eq $true) {
69-
Write-LMHost "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module, uninstalling prior Module $Module version $InstalledVersion" -ForegroundColor Yellow
69+
Write-Information "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module, uninstalling prior Module $Module version $InstalledVersion"
7070
Uninstall-Module -Name $Module -Force -Verbose:$False
7171

72-
Write-LMHost "[INFO]: Installing newer Module $Module version $OnlineVersion."
72+
Write-Information "[INFO]: Installing newer Module $Module version $OnlineVersion."
7373
Install-Module -Name $Module -Force -AllowClobber -Verbose:$False -MinimumVersion $OnlineVersion
7474
Update-LogicMonitorModule -CheckOnly -Modules @($Module)
7575
}
7676
Else {
77-
Write-LMHost "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module. Installing newer Module $Module version $OnlineVersion." -ForegroundColor Yellow
77+
Write-Information "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module. Installing newer Module $Module version $OnlineVersion."
7878
Install-Module -Name $Module -Force -AllowClobber -Verbose:$False -MinimumVersion $OnlineVersion
7979
Update-LogicMonitorModule -CheckOnly -Modules @($Module)
8080
}
81-
8281
}
8382
Else {
84-
Write-LMHost "[INFO]: Module $Module version $InstalledVersion is the latest version."
83+
Write-Information "[INFO]: Module $Module version $InstalledVersion is the latest version."
8584
}
8685
}
8786
}

Private/Write-LMHost.ps1

Lines changed: 0 additions & 56 deletions
This file was deleted.

Public/Connect-LMAccount.ps1

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Bearer token from your API credential acquired from the LM Portal. For use in pl
1717
.PARAMETER AccountName
1818
The subdomain for your LM portal, the name before ".logicmonitor.com" (subdomain.logicmonitor.com)
1919
20+
.PARAMETER DisableConsoleLogging
21+
Disables on info messages from displaying for any subsequent commands are run. Useful when building scripted logicmodules and you want to suppress unwanted output. Console logging is enabled by default.
22+
2023
.PARAMETER UseCachedCredential
2124
This will list all cached account for you to pick from. This parameter is optional
2225
@@ -26,9 +29,6 @@ Name of cached account you wish to connect to. This parameter is optional and ca
2629
.PARAMETER SessionSync
2730
Use session sync capability instead of api key
2831
29-
.PARAMETER DisableConsoleLogging
30-
Disables on stdout messages from displaying for any subsequent commands are run. Useful when building scripted logicmodules and you want to suppress unwanted output. Console logging is enabled by default.
31-
3232
.EXAMPLE
3333
Connect-LMAccount -AccessId xxxxxx -AccessKey xxxxxx -AccountName subdomain
3434
@@ -77,10 +77,10 @@ Function Connect-LMAccount {
7777
[Parameter(ParameterSetName = 'SessionSync')]
7878
[Switch]$SessionSync,
7979

80-
[Switch]$AutoUpdateModuleVersion,
81-
8280
[Switch]$DisableConsoleLogging,
8381

82+
[Switch]$AutoUpdateModuleVersion,
83+
8484
[Switch]$SkipVersionCheck,
8585

8686
[Switch]$SkipCredValidation
@@ -91,22 +91,29 @@ Function Connect-LMAccount {
9191
Add-Type -AssemblyName System.Web
9292
}
9393

94+
If(!$DisableConsoleLogging.IsPresent) {
95+
$InformationPreference = 'SilentlyContinue'
96+
}
97+
Else {
98+
$InformationPreference = 'Continue'
99+
}
100+
94101
If ($UseCachedCredential -or $CachedAccountName) {
95102

96103
Try {
97-
$ExistingVault = Get-SecretVault -Name Logic.Monitor -ErrorAction Stop
98-
Write-Host "[INFO]: Existing vault Logic.Monitor already exists, skipping creation"
104+
Get-SecretVault -Name Logic.Monitor -ErrorAction Stop | Out-Null
105+
Write-Information "[INFO]: Existing vault Logic.Monitor already exists, skipping creation"
99106
}
100107
Catch {
101108
If ($_.Exception.Message -like "*Vault Logic.Monitor does not exist in registry*") {
102-
Write-Host "[INFO]: Credential vault for cached accounts does not currently exist, creating credential vault: Logic.Monitor"
109+
Write-Information "[INFO]: Credential vault for cached accounts does not currently exist, creating credential vault: Logic.Monitor"
103110
Register-SecretVault -Name Logic.Monitor -ModuleName Microsoft.PowerShell.SecretStore
104111
Get-SecretStoreConfiguration | Out-Null
105112
}
106113
}
107114
$CredentialPath = Join-Path -Path $Home -ChildPath "Logic.Monitor.json"
108115
If ((Test-Path -Path $CredentialPath)) {
109-
Write-Host "[INFO]: Previous version of cached accounts detected, migrating to secret store..."
116+
Write-Information "[INFO]: Previous version of cached accounts detected, migrating to secret store..."
110117
$CredentialFile = Get-Content -Path $CredentialPath | ConvertFrom-Json | Sort-Object -Property Modified -Descending
111118
$MigrationComplete = $true
112119
Foreach ($Credential in $CredentialFile) {
@@ -118,7 +125,7 @@ Function Connect-LMAccount {
118125
}
119126
Try {
120127
Set-Secret -Name $Credential.Portal -Secret $Credential.Key -Vault Logic.Monitor -Metadata $Metadata -NoClobber
121-
Write-Host "[INFO]: Successfully migrated cached account secret for portal: $($Credential.Portal)"
128+
Write-Information "[INFO]: Successfully migrated cached account secret for portal: $($Credential.Portal)"
122129
}
123130
Catch {
124131
Write-Error $_.Exception.Message
@@ -127,12 +134,12 @@ Function Connect-LMAccount {
127134
}
128135
If ($MigrationComplete) {
129136
Remove-Item -Path $CredentialPath -Confirm:$false
130-
Write-Host "[INFO]: Successfully migrated cached accounts into secret store, your legacy account cache hes been removed."
137+
Write-Information "[INFO]: Successfully migrated cached accounts into secret store, your legacy account cache hes been removed."
131138
}
132139
Else {
133140
$NewName = Join-Path -Path $Home -ChildPath "Logic.Monitor-Migrated.json"
134141
Rename-Item -Path $CredentialPath -Confirm:$false -NewName $NewName
135-
Write-Host "[ERROR]: Unable to fully migrate cached accounts into secret store, your legacy account cache has been archived at: $NewName. No other attemps will be made to migrate any failed accounts." -ForegroundColor Red
142+
Write-Error "[ERROR]: Unable to fully migrate cached accounts into secret store, your legacy account cache has been archived at: $NewName. No other attemps will be made to migrate any failed accounts."
136143
}
137144
}
138145

@@ -231,7 +238,6 @@ Function Connect-LMAccount {
231238
BearerToken = $BearerToken
232239
Portal = $AccountName
233240
Valid = $true
234-
Logging = !$DisableConsoleLogging.IsPresent
235241
Type = $Type
236242
}
237243

@@ -245,7 +251,7 @@ Function Connect-LMAccount {
245251
}
246252
}
247253
Catch {
248-
Write-Host "[ERROR]: Unable to check for newer version of Logic.Monitor module: $($_.Exception.Message)" -ForegroundColor Red
254+
Write-Error "[ERROR]: Unable to check for newer version of Logic.Monitor module: $($_.Exception.Message)"
249255
}
250256

251257
If (!$SkipCredValidation) {
@@ -261,13 +267,13 @@ Function Connect-LMAccount {
261267

262268
If ($ApiInfo) {
263269
$PortalInfo = Get-LMPortalInfo -ErrorAction Stop
264-
Write-LMHost "[INFO]: Connected to LM portal $($PortalInfo.companyDisplayName) using account ($($ApiInfo.adminName) via $Type Token) with assigned roles: $($ApiInfo.roles -join ",") - ($($PortalInfo.numberOfDevices) devices | $($PortalInfo.numOfWebsites) websites)." -ForegroundColor Green
270+
Write-Information "[INFO]: Connected to LM portal $($PortalInfo.companyDisplayName) using account ($($ApiInfo.adminName) via $Type Token) with assigned roles: $($ApiInfo.roles -join ",") - ($($PortalInfo.numberOfDevices) devices | $($PortalInfo.numOfWebsites) websites)."
265271
Return
266272
}
267273
Else {
268274
Try {
269275
$PortalInfo = Get-LMPortalInfo -ErrorAction Stop
270-
Write-LMHost "[INFO]: Connected to LM portal $($PortalInfo.companyDisplayName) via $Type Token - ($($PortalInfo.numberOfDevices) devices | $($PortalInfo.numOfWebsites) websites)." -ForegroundColor Green
276+
Write-Information "[INFO]: Connected to LM portal $($PortalInfo.companyDisplayName) via $Type Token - ($($PortalInfo.numberOfDevices) devices | $($PortalInfo.numOfWebsites) websites)."
271277
Return
272278
}
273279
Catch {
@@ -280,7 +286,7 @@ Function Connect-LMAccount {
280286
$DeviceInfo = Get-LMDevice -ErrorAction Stop
281287

282288
If ($DeviceInfo) {
283-
Write-LMHost "[INFO]: Connected to LM portal $AccountName via $Type Token with limited permissions, ensure your api token has the necessary rights needed to run desired commands." -ForegroundColor Yellow
289+
Write-Information "[INFO]: Connected to LM portal $AccountName via $Type Token with limited permissions, ensure your api token has the necessary rights needed to run desired commands."
284290
Return
285291
}
286292
Else {
@@ -297,6 +303,6 @@ Function Connect-LMAccount {
297303
}
298304
}
299305
Else {
300-
Write-LMHost "[INFO]: Skipping validation of credentials, connected to LM portal $AccountName via $Type, ensure your api token has the necessary rights needed to run desired commands." -ForegroundColor Yellow
306+
Write-Information "[INFO]: Skipping validation of credentials, connected to LM portal $AccountName via $Type, ensure your api token has the necessary rights needed to run desired commands."
301307
}
302308
}

Public/Disconnect-LMAccount.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ PSGallery: https://www.powershellgallery.com/packages/Logic.Monitor
2323
Function Disconnect-LMAccount {
2424
#Clear credential object from environment
2525
If ($Script:LMAuth) {
26-
Write-LMHost "[INFO]: Successfully cleared login credentials for LM account." -ForegroundColor Green
26+
Write-Information "[INFO]: Successfully cleared login credentials for LM account."
2727
Remove-Variable -Name LMAuth -Scope Script -ErrorAction SilentlyContinue
2828
Remove-Variable -Name LMUserData -Scope Global -ErrorAction SilentlyContinue
2929
Remove-Variable -Name LMDeltaId -Scope Global -ErrorAction SilentlyContinue
3030
}
3131
Else {
32-
Write-Host "[INFO]: Not currently connected to any LM account." -ForegroundColor Gray
32+
Write-Information "[INFO]: Not currently connected to any LM account."
3333
}
34+
35+
#Reset information preference
36+
$InformationPreference = 'SilentlyContinue'
3437
}

0 commit comments

Comments
 (0)