Skip to content

Commit

Permalink
Merge pull request #13 from logicmonitor/develop-6.4
Browse files Browse the repository at this point in the history
prep 6.4 release
  • Loading branch information
stevevillardi authored Oct 16, 2024
2 parents 5bd69c7 + d20dbf4 commit eb15486
Show file tree
Hide file tree
Showing 44 changed files with 572 additions and 157 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Test Current Build on Windows Powershell 5.1

on:
push:
branches: [ main ]
branches:
- '**'
paths-ignore:
- '**.md'
- '**.yml'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Test Current Build on PowerShell Core

on:
push:
branches: [ main ]
branches:
- '**'
paths-ignore:
- '**.md'
- '**.yml'
Expand Down
16 changes: 16 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
```powershell
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
```
#### Create a new collector, download the installer and silent install

```powershell
#Connect to LogicMonitor account
Connect-LMAccount -AccountName "<account name>" -AccessId "<access id>" -AccessKey "<access key>"
#Create new collector and download the installer
$Collector = New-LMCollector -Description "<enter description>"
$FilePath = Get-LMCollectorInstaller -Id $Collector.Id -Size "medium" -OSandArch "Win64" -DownloadPath "C:\temp"
#Install the collector silently
.\$FilePath /q /a:administrator /p:'password'
#Disconnect from LogicMonitor account
Disconnect-LMAccount
```

#### Generate Website inventory report with specific properties
```powershell
Expand Down
53 changes: 53 additions & 0 deletions Logic.Monitor.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,59 @@
</TableRowEntries>
</TableControl>
</View>
<!-- New View LogicMonitor.EventSource-->
<View>
<Name>LogicMonitorEventSource</Name>
<ViewSelectedBy>
<TypeName>LogicMonitor.EventSource</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>id</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>collector</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>schedule</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>appliesTo</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>description</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>collector</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>schedule</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>appliesTo</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>description</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<!-- New View LogicMonitor.RepositoryLogicModules-->
<View>
<Name>RepositoryLogicModules</Name>
Expand Down
6 changes: 4 additions & 2 deletions Private/Format-LMFilter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Function Format-LMFilter {
'\s+-le\s+' { $FormatedFilter += "<:" }
'\s+-contains\s+' { $FormatedFilter += "~" }
'\s+-notcontains\s+' { $FormatedFilter += "!~" }
default { Write-LMHost "[ERROR]: Invalid filter syntax: $Filter" -ForegroundColor Red }
default { throw "[ERROR]: Invalid filter syntax: $Filter" }
}
}
Else {
Expand All @@ -78,10 +78,12 @@ Function Format-LMFilter {
}
}
Else {
Write-LMHost "[ERROR]: Invalid filter syntax: $SingleFilterArray" -ForegroundColor Red
throw "[ERROR]: Invalid filter syntax: $SingleFilterArray"

}
}
}
#$FormatedFilter = $FormatedFilter.Replace("\", "\\")
Write-Debug "Constructed Filter-v2: $FormatedFilter"
Return $FormatedFilter
}
Expand Down
2 changes: 1 addition & 1 deletion Private/Resolve-LMException.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Function Resolve-LMException {
$RateLimitSize = $LMException.Exception.Response.Headers.Value[$LMException.Exception.Response.Headers.Key.IndexOf("x-rate-limit-limit")]
#$RateLimitRemaining = $LMException.Exception.Response.Headers.Value[$LMException.Exception.Response.Headers.Key.IndexOf("x-rate-limit-remaining")]

Write-LMHost "Request exceeded rate limit window of $RateLimitSize requests over $RateLimitWindow seconds, retrying operation in $RateLimitWindow seconds" -ForegroundColor Yellow
Write-Warning "Request exceeded rate limit window of $RateLimitSize requests over $RateLimitWindow seconds, retrying operation in $RateLimitWindow seconds"
Start-Sleep -Seconds $RateLimitWindow
return $true
}
Expand Down
11 changes: 5 additions & 6 deletions Private/Update-LogicMonitorModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,24 @@ Function Update-LogicMonitorModule {

# Uninstall the old version
If ($CheckOnly) {
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
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."
}
Elseif ($UninstallFirst -eq $true) {
Write-LMHost "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module, uninstalling prior Module $Module version $InstalledVersion" -ForegroundColor Yellow
Write-Information "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module, uninstalling prior Module $Module version $InstalledVersion"
Uninstall-Module -Name $Module -Force -Verbose:$False

Write-LMHost "[INFO]: Installing newer Module $Module version $OnlineVersion."
Write-Information "[INFO]: Installing newer Module $Module version $OnlineVersion."
Install-Module -Name $Module -Force -AllowClobber -Verbose:$False -MinimumVersion $OnlineVersion
Update-LogicMonitorModule -CheckOnly -Modules @($Module)
}
Else {
Write-LMHost "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module. Installing newer Module $Module version $OnlineVersion." -ForegroundColor Yellow
Write-Information "[INFO]: You are currently using an outdated version ($InstalledVersion) of $Module. Installing newer Module $Module version $OnlineVersion."
Install-Module -Name $Module -Force -AllowClobber -Verbose:$False -MinimumVersion $OnlineVersion
Update-LogicMonitorModule -CheckOnly -Modules @($Module)
}

}
Else {
Write-LMHost "[INFO]: Module $Module version $InstalledVersion is the latest version."
Write-Information "[INFO]: Module $Module version $InstalledVersion is the latest version."
}
}
}
56 changes: 0 additions & 56 deletions Private/Write-LMHost.ps1

This file was deleted.

42 changes: 24 additions & 18 deletions Public/Connect-LMAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Bearer token from your API credential acquired from the LM Portal. For use in pl
.PARAMETER AccountName
The subdomain for your LM portal, the name before ".logicmonitor.com" (subdomain.logicmonitor.com)
.PARAMETER DisableConsoleLogging
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.
.PARAMETER UseCachedCredential
This will list all cached account for you to pick from. This parameter is optional
Expand All @@ -26,9 +29,6 @@ Name of cached account you wish to connect to. This parameter is optional and ca
.PARAMETER SessionSync
Use session sync capability instead of api key
.PARAMETER DisableConsoleLogging
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.
.EXAMPLE
Connect-LMAccount -AccessId xxxxxx -AccessKey xxxxxx -AccountName subdomain
Expand Down Expand Up @@ -77,10 +77,10 @@ Function Connect-LMAccount {
[Parameter(ParameterSetName = 'SessionSync')]
[Switch]$SessionSync,

[Switch]$AutoUpdateModuleVersion,

[Switch]$DisableConsoleLogging,

[Switch]$AutoUpdateModuleVersion,

[Switch]$SkipVersionCheck,

[Switch]$SkipCredValidation
Expand All @@ -91,22 +91,29 @@ Function Connect-LMAccount {
Add-Type -AssemblyName System.Web
}

If(!$DisableConsoleLogging.IsPresent) {
$InformationPreference = 'SilentlyContinue'
}
Else {
$InformationPreference = 'Continue'
}

If ($UseCachedCredential -or $CachedAccountName) {

Try {
$ExistingVault = Get-SecretVault -Name Logic.Monitor -ErrorAction Stop
Write-Host "[INFO]: Existing vault Logic.Monitor already exists, skipping creation"
Get-SecretVault -Name Logic.Monitor -ErrorAction Stop | Out-Null
Write-Information "[INFO]: Existing vault Logic.Monitor already exists, skipping creation"
}
Catch {
If ($_.Exception.Message -like "*Vault Logic.Monitor does not exist in registry*") {
Write-Host "[INFO]: Credential vault for cached accounts does not currently exist, creating credential vault: Logic.Monitor"
Write-Information "[INFO]: Credential vault for cached accounts does not currently exist, creating credential vault: Logic.Monitor"
Register-SecretVault -Name Logic.Monitor -ModuleName Microsoft.PowerShell.SecretStore
Get-SecretStoreConfiguration | Out-Null
}
}
$CredentialPath = Join-Path -Path $Home -ChildPath "Logic.Monitor.json"
If ((Test-Path -Path $CredentialPath)) {
Write-Host "[INFO]: Previous version of cached accounts detected, migrating to secret store..."
Write-Information "[INFO]: Previous version of cached accounts detected, migrating to secret store..."
$CredentialFile = Get-Content -Path $CredentialPath | ConvertFrom-Json | Sort-Object -Property Modified -Descending
$MigrationComplete = $true
Foreach ($Credential in $CredentialFile) {
Expand All @@ -118,7 +125,7 @@ Function Connect-LMAccount {
}
Try {
Set-Secret -Name $Credential.Portal -Secret $Credential.Key -Vault Logic.Monitor -Metadata $Metadata -NoClobber
Write-Host "[INFO]: Successfully migrated cached account secret for portal: $($Credential.Portal)"
Write-Information "[INFO]: Successfully migrated cached account secret for portal: $($Credential.Portal)"
}
Catch {
Write-Error $_.Exception.Message
Expand All @@ -127,12 +134,12 @@ Function Connect-LMAccount {
}
If ($MigrationComplete) {
Remove-Item -Path $CredentialPath -Confirm:$false
Write-Host "[INFO]: Successfully migrated cached accounts into secret store, your legacy account cache hes been removed."
Write-Information "[INFO]: Successfully migrated cached accounts into secret store, your legacy account cache hes been removed."
}
Else {
$NewName = Join-Path -Path $Home -ChildPath "Logic.Monitor-Migrated.json"
Rename-Item -Path $CredentialPath -Confirm:$false -NewName $NewName
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
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."
}
}

Expand Down Expand Up @@ -231,7 +238,6 @@ Function Connect-LMAccount {
BearerToken = $BearerToken
Portal = $AccountName
Valid = $true
Logging = !$DisableConsoleLogging.IsPresent
Type = $Type
}

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

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

If ($ApiInfo) {
$PortalInfo = Get-LMPortalInfo -ErrorAction Stop
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
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)."
Return
}
Else {
Try {
$PortalInfo = Get-LMPortalInfo -ErrorAction Stop
Write-LMHost "[INFO]: Connected to LM portal $($PortalInfo.companyDisplayName) via $Type Token - ($($PortalInfo.numberOfDevices) devices | $($PortalInfo.numOfWebsites) websites)." -ForegroundColor Green
Write-Information "[INFO]: Connected to LM portal $($PortalInfo.companyDisplayName) via $Type Token - ($($PortalInfo.numberOfDevices) devices | $($PortalInfo.numOfWebsites) websites)."
Return
}
Catch {
Expand All @@ -280,7 +286,7 @@ Function Connect-LMAccount {
$DeviceInfo = Get-LMDevice -ErrorAction Stop

If ($DeviceInfo) {
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
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."
Return
}
Else {
Expand All @@ -297,6 +303,6 @@ Function Connect-LMAccount {
}
}
Else {
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
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."
}
}
7 changes: 5 additions & 2 deletions Public/Disconnect-LMAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ PSGallery: https://www.powershellgallery.com/packages/Logic.Monitor
Function Disconnect-LMAccount {
#Clear credential object from environment
If ($Script:LMAuth) {
Write-LMHost "[INFO]: Successfully cleared login credentials for LM account." -ForegroundColor Green
Write-Information "[INFO]: Successfully cleared login credentials for LM account."
Remove-Variable -Name LMAuth -Scope Script -ErrorAction SilentlyContinue
Remove-Variable -Name LMUserData -Scope Global -ErrorAction SilentlyContinue
Remove-Variable -Name LMDeltaId -Scope Global -ErrorAction SilentlyContinue
}
Else {
Write-Host "[INFO]: Not currently connected to any LM account." -ForegroundColor Gray
Write-Information "[INFO]: Not currently connected to any LM account."
}

#Reset information preference
$InformationPreference = 'SilentlyContinue'
}
Loading

0 comments on commit eb15486

Please sign in to comment.