From 94586904304dc6d231f00869eb8dbd943fcde6b3 Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:55:14 -0400 Subject: [PATCH 1/9] prep 6.4 release --- EXAMPLES.md | 16 ++++ Logic.Monitor.Format.ps1xml | 53 +++++++++++++ Private/Format-LMFilter.ps1 | 6 +- Private/Resolve-LMException.ps1 | 2 +- Private/Update-LogicMonitorModule.ps1 | 10 +-- Private/Write-LMHost.ps1 | 56 ------------- Public/Connect-LMAccount.ps1 | 40 ++++++---- Public/Disconnect-LMAccount.ps1 | 7 +- Public/Export-LMDeviceConfigBackup.ps1 | 14 ++-- Public/Export-LMDeviceData.ps1 | 14 ++-- Public/Get-LMAlert.ps1 | 2 +- Public/Get-LMAuditLogs.ps1 | 4 +- Public/Get-LMDevice.ps1 | 2 +- Public/Get-LMEventSource.ps1 | 4 +- Public/Get-LMIntegrationLogs.ps1 | 4 +- Public/Import-LMDashboard.ps1 | 16 ++-- Public/Invoke-LMAWSAccountTest.ps1 | 2 +- Public/Invoke-LMActiveDiscovery.ps1 | 2 +- Public/Invoke-LMAzureAccountTest.ps1 | 2 +- Public/Invoke-LMCollectorDebugCommand.ps1 | 2 +- Public/Invoke-LMGCPAccountTest.ps1 | 2 +- Public/New-LMAPIUser.ps1 | 2 +- Public/New-LMAccessGroupMapping.ps1 | 96 +++++++++++++++++++++++ Public/New-LMCachedAccount.ps1 | 6 +- Public/New-LMUser.ps1 | 6 +- Public/Remove-LMCachedAccount.ps1 | 6 +- Public/Set-LMCollectorConfig.ps1 | 8 +- Public/Set-LMUser.ps1 | 2 +- README.md | 26 ++++-- RELEASENOTES.md | 13 +++ Tests/LMAccessGroup.Tests.ps1 | 53 +++++++++++++ Tests/LMAppliesToFunction.Tests.ps1 | 2 +- Tests/LMAppliesToSearch.Tests.ps1 | 37 +++++++++ Tests/LMDevice.Tests.ps1 | 2 +- Tests/LMDeviceGroup.Tests.ps1 | 2 +- Tests/LMNetScanGroup.Tests.ps1 | 56 +++++++++++++ Tests/LMOpsNotes.Tests.ps1 | 2 +- Tests/LMReportGroup.Tests.ps1 | 56 +++++++++++++ Tests/LMSDT.Tests.ps1 | 74 +++++++++++++++++ Tests/LMUser-Role.Tests.ps1 | 2 +- Tests/LMWebsite.Tests.ps1 | 2 +- Tests/LMWebsiteGroup.Tests.ps1 | 2 +- 42 files changed, 567 insertions(+), 148 deletions(-) delete mode 100644 Private/Write-LMHost.ps1 create mode 100644 Public/New-LMAccessGroupMapping.ps1 create mode 100644 Tests/LMAccessGroup.Tests.ps1 create mode 100644 Tests/LMAppliesToSearch.Tests.ps1 create mode 100644 Tests/LMNetScanGroup.Tests.ps1 create mode 100644 Tests/LMReportGroup.Tests.ps1 create mode 100644 Tests/LMSDT.Tests.ps1 diff --git a/EXAMPLES.md b/EXAMPLES.md index b05eba4..9c6363c 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -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 "" -AccessId "" -AccessKey "" + +#Create new collector and download the installer +$Collector = New-LMCollector -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 diff --git a/Logic.Monitor.Format.ps1xml b/Logic.Monitor.Format.ps1xml index 70ecfc3..83d4882 100644 --- a/Logic.Monitor.Format.ps1xml +++ b/Logic.Monitor.Format.ps1xml @@ -2209,6 +2209,59 @@ + + + LogicMonitorEventSource + + LogicMonitor.EventSource + + + + + + + + + + + + + + + + + + + + + + + + + + + id + + + name + + + collector + + + schedule + + + appliesTo + + + description + + + + + + RepositoryLogicModules diff --git a/Private/Format-LMFilter.ps1 b/Private/Format-LMFilter.ps1 index d15f390..d27d62d 100644 --- a/Private/Format-LMFilter.ps1 +++ b/Private/Format-LMFilter.ps1 @@ -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 { @@ -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 } diff --git a/Private/Resolve-LMException.ps1 b/Private/Resolve-LMException.ps1 index 1055c61..7d530f2 100644 --- a/Private/Resolve-LMException.ps1 +++ b/Private/Resolve-LMException.ps1 @@ -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 } diff --git a/Private/Update-LogicMonitorModule.ps1 b/Private/Update-LogicMonitorModule.ps1 index 615c73d..fbe0520 100644 --- a/Private/Update-LogicMonitorModule.ps1 +++ b/Private/Update-LogicMonitorModule.ps1 @@ -63,25 +63,25 @@ 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." } } } \ No newline at end of file diff --git a/Private/Write-LMHost.ps1 b/Private/Write-LMHost.ps1 deleted file mode 100644 index ac50a1f..0000000 --- a/Private/Write-LMHost.ps1 +++ /dev/null @@ -1,56 +0,0 @@ -<# -.SYNOPSIS -Writes a message to the host with optional foreground and background colors. - -.DESCRIPTION -The Write-LMHost function writes a message to the host console. It provides the option to specify the foreground and background colors of the message. - -.PARAMETER Message -The message to be written to the host. - -.PARAMETER ForegroundColor -The foreground color of the message. This parameter accepts a ConsoleColor value. - -.PARAMETER BackgroundColor -The background color of the message. This parameter accepts a ConsoleColor value. - -.NOTES -Only log message content if the switch is set to true during connect-lmaccount. - -.EXAMPLE -Write-LMHost -Message "Hello, World!" -ForegroundColor Green -BackgroundColor Black -Writes the message "Hello, World!" to the host console with green foreground color and black background color. - -.EXAMPLE -Write-LMHost -Message "Error: Something went wrong." -ForegroundColor Red -Writes the error message "Error: Something went wrong." to the host console with red foreground color. - -#> - -Function Write-LMHost { - Param ( - [Object]$Message = $args[0], - - [Nullable[ConsoleColor]]$ForegroundColor, - - [Nullable[ConsoleColor]]$BackgroundColor - ) - #Only log message content if switch is set to true during connect lm account - If ($Script:LMAuth.Logging) { - If ($ForegroundColor -and !$BackgroundColor) { - Write-Host $Message -ForegroundColor $ForegroundColor - } - Elseif (!$ForegroundColor -and $BackgroundColor) { - Write-Host $Message -BackgroundColor $BackgroundColor - } - Elseif ($ForegroundColor -and $BackgroundColor) { - Write-Host $Message -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor - } - Else { - Write-Host $Message - } - } - Else { - Write-Host $Message - } -} \ No newline at end of file diff --git a/Public/Connect-LMAccount.ps1 b/Public/Connect-LMAccount.ps1 index 0c8aecd..e52bfdd 100644 --- a/Public/Connect-LMAccount.ps1 +++ b/Public/Connect-LMAccount.ps1 @@ -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 @@ -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 @@ -77,10 +77,10 @@ Function Connect-LMAccount { [Parameter(ParameterSetName = 'SessionSync')] [Switch]$SessionSync, - [Switch]$AutoUpdateModuleVersion, - [Switch]$DisableConsoleLogging, + [Switch]$AutoUpdateModuleVersion, + [Switch]$SkipVersionCheck, [Switch]$SkipCredValidation @@ -91,22 +91,29 @@ Function Connect-LMAccount { Add-Type -AssemblyName System.Web } + If(!$DisableConsoleLogging.IsPresent) { + $InformationPreference = 'Continue' + } + Else { + $InformationPreference = 'SilentlyContinue' + } + If ($UseCachedCredential -or $CachedAccountName) { Try { $ExistingVault = Get-SecretVault -Name Logic.Monitor -ErrorAction Stop - Write-Host "[INFO]: Existing vault Logic.Monitor already exists, skipping creation" + 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) { @@ -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 @@ -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." } } @@ -231,7 +238,6 @@ Function Connect-LMAccount { BearerToken = $BearerToken Portal = $AccountName Valid = $true - Logging = !$DisableConsoleLogging.IsPresent Type = $Type } @@ -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) { @@ -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 { @@ -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 { @@ -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." } } diff --git a/Public/Disconnect-LMAccount.ps1 b/Public/Disconnect-LMAccount.ps1 index 0beae1b..23965b3 100644 --- a/Public/Disconnect-LMAccount.ps1 +++ b/Public/Disconnect-LMAccount.ps1 @@ -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' } diff --git a/Public/Export-LMDeviceConfigBackup.ps1 b/Public/Export-LMDeviceConfigBackup.ps1 index 4deaaf3..387d151 100644 --- a/Public/Export-LMDeviceConfigBackup.ps1 +++ b/Public/Export-LMDeviceConfigBackup.ps1 @@ -67,12 +67,12 @@ Function Export-LMDeviceConfigBackup { #Loop through Network group devices and pull list of applied ConfigSources $instance_list = @() - Write-LMHost "[INFO]: Found $(($network_devices | Measure-Object).Count) devices." + Write-Information "[INFO]: Found $(($network_devices | Measure-Object).Count) devices." Foreach ($device in $network_devices) { - Write-LMHost "[INFO]: Collecting configurations for: $($device.displayName)" + Write-Information "[INFO]: Collecting configurations for: $($device.displayName)" $device_config_sources = Get-LMDeviceDatasourceList -id $device.id | Where-Object { $_.dataSourceType -eq "CS" -and $_.instanceNumber -gt 0 -and $_.dataSourceName -match $ConfigSourceNameFilter } - Write-LMHost " [INFO]: Found $(($device_config_sources | Measure-Object).Count) configsource(s) with discovered instances using match filter ($ConfigSourceNameFilter)." -ForegroundColor Gray + Write-Information "[INFO]: Found $(($device_config_sources | Measure-Object).Count) configsource(s) with discovered instances using match filter ($ConfigSourceNameFilter)." #Loop through DSes and pull all instances matching running or current and add them to processing list $filtered_config_instance_count = 0 Foreach ($config_source in $device_config_sources) { @@ -94,7 +94,7 @@ Function Export-LMDeviceConfigBackup { } } } - Write-LMHost " [INFO]: Found $filtered_config_instance_count configsource instance(s) using match filter ($InstanceNameFilter)." -ForegroundColor Gray + Write-Information "[INFO]: Found $filtered_config_instance_count configsource instance(s) using match filter ($InstanceNameFilter)." } #Loop through filtered instance list and pull config diff @@ -108,11 +108,11 @@ Function Export-LMDeviceConfigBackup { If ($device_configs) { #Group Configs by device so we can work through each set $config_grouping = $device_configs | Group-Object -Property deviceId - Write-LMHost "[INFO]: Collecting latest device configurations from $(($config_grouping | Measure-Object).Count) devices." + Write-Information "[INFO]: Collecting latest device configurations from $(($config_grouping | Measure-Object).Count) devices." #Loop through each set and built report Foreach ($device in $config_grouping) { $config = $device.Group | Sort-Object -Property pollTimestamp -Descending | Select-Object -First 1 - Write-LMHost " [INFO]: Found $(($device.Group | Measure-Object).Count) configsource instance version(s) for: $($config.deviceDisplayName), selecting latest config dated: $([datetimeoffset]::FromUnixTimeMilliseconds($config.pollTimestamp).DateTime)UTC" -ForegroundColor Gray + Write-Information "[INFO]: Found $(($device.Group | Measure-Object).Count) configsource instance version(s) for: $($config.deviceDisplayName), selecting latest config dated: $([datetimeoffset]::FromUnixTimeMilliseconds($config.pollTimestamp).DateTime)UTC" $output_list += [PSCustomObject]@{ deviceDisplayName = $config.deviceDisplayName deviceInstanceName = $config.instanceName @@ -133,7 +133,7 @@ Function Export-LMDeviceConfigBackup { Return (Add-ObjectTypeInfo -InputObject $output_list -TypeName "LogicMonitor.ConfigBackup" ) } Else { - Write-LMHost "[WARN]: Did not find any configs to output based on selected resource(s), check your parameters and try again." -ForegroundColor Yellow + Write-Warning "[WARN]: Did not find any configs to output based on selected resource(s), check your parameters and try again." } } diff --git a/Public/Export-LMDeviceData.ps1 b/Public/Export-LMDeviceData.ps1 index 07a20c4..1a9b4cc 100644 --- a/Public/Export-LMDeviceData.ps1 +++ b/Public/Export-LMDeviceData.ps1 @@ -95,25 +95,25 @@ Function Export-LMDeviceData { } If ($DeviceList) { - Write-LMHost "[INFO]: $(($DeviceList | Measure-Object).count) resource(s) selected for data export" + Write-Information "[INFO]: $(($DeviceList | Measure-Object).count) resource(s) selected for data export" Foreach ($Device in $DeviceList) { $DatasourceList = @() - Write-LMHost "[INFO]: Starting data collection for resource: $($Device.displayName)" + Write-Information "[INFO]: Starting data collection for resource: $($Device.displayName)" $DatasourceList = Get-LMDeviceDatasourceList -Id $Device.id | Where-Object { $_.monitoringInstanceNumber -gt 0 -and $_.dataSourceName -like $DatasourceIncludeFilter -and $_.datasourceName -notlike $DatasourceExcludeFilter } If ($DatasourceList) { - Write-LMHost "[INFO]: Found ($(($DatasourceList | Measure-Object).count)) datasource(s) with 1 or more active instances for resource: $($Device.displayName) using datasource filter (Include:$DatasourceIncludeFilter | Exclude:$DatasourceExcludeFilter)" + Write-Information "[INFO]: Found ($(($DatasourceList | Measure-Object).count)) datasource(s) with 1 or more active instances for resource: $($Device.displayName) using datasource filter (Include:$DatasourceIncludeFilter | Exclude:$DatasourceExcludeFilter)" Foreach ($Datasource in $DatasourceList) { - Write-LMHost "[INFO]: Starting instance discovery for datasource $($Datasource.dataSourceName) for resource: $($Device.displayName)" + Write-Information "[INFO]: Starting instance discovery for datasource $($Datasource.dataSourceName) for resource: $($Device.displayName)" $InstanceList = @() $InstanceList = Get-LMDeviceDatasourceInstance -Id $Device.id -DatasourceId $Datasource.dataSourceId | Where-Object { $_.stopMonitoring -eq $false } If ($InstanceList) { - Write-LMHost "[INFO]: Found ($(($InstanceList | Measure-Object).count)) instance(s) for resource: $($Device.displayName)" + Write-Information "[INFO]: Found ($(($InstanceList | Measure-Object).count)) instance(s) for resource: $($Device.displayName)" Foreach ($Instance in $InstanceList) { - Write-LMHost "[INFO]: Starting datapoint collection for instance $($Instance.name) for resource: $($Device.displayName)" + Write-Information "[INFO]: Starting datapoint collection for instance $($Instance.name) for resource: $($Device.displayName)" $Datapoints = @() $Datapoints = Get-LMDeviceData -DeviceId $Device.id -DatasourceId $Datasource.dataSourceId -InstanceId $Instance.id -StartDate $StartDate -EndDate $EndDate If ($Datapoints) { - Write-LMHost "[INFO]: Finished datapoint collection for instance $($Instance.name) for resource: $($Device.displayName)" + Write-Information "[INFO]: Finished datapoint collection for instance $($Instance.name) for resource: $($Device.displayName)" $DataExportList += [PSCustomObject]@{ deviceId = $Device.id deviceName = $Device.displayName diff --git a/Public/Get-LMAlert.ps1 b/Public/Get-LMAlert.ps1 index 3713f19..d435f21 100644 --- a/Public/Get-LMAlert.ps1 +++ b/Public/Get-LMAlert.ps1 @@ -162,7 +162,7 @@ Function Get-LMAlert { $Results += $Response.Items If ($Count -ge $QueryLimit) { $Done = $true - Write-LMHost "[WARN]: Reached $QueryLimit record query limitation for this endpoint" -ForegroundColor Yellow + Write-Warning "[WARN]: Reached $QueryLimit record query limitation for this endpoint" } Elseif ($Count -ge $Total -and $Total -ge 0) { $Done = $true diff --git a/Public/Get-LMAuditLogs.ps1 b/Public/Get-LMAuditLogs.ps1 index d143c9e..ce715b6 100644 --- a/Public/Get-LMAuditLogs.ps1 +++ b/Public/Get-LMAuditLogs.ps1 @@ -72,7 +72,7 @@ Function Get-LMAuditLogs { #Convert to epoch, if not set use defaults If (!$StartDate) { If ($PSCmdlet.ParameterSetName -ne "Id") { - Write-LMHost "[WARN]: No start date specified, defaulting to last 30 days" -ForegroundColor Yellow + Write-Warning "[WARN]: No start date specified, defaulting to last 30 days" } [int]$StartDate = ([DateTimeOffset]$(Get-Date).AddDays(-30)).ToUnixTimeSeconds() } @@ -123,7 +123,7 @@ Function Get-LMAuditLogs { $Results += $Response.Items If ($Count -ge $QueryLimit) { $Done = $true - Write-LMHost "[WARN]: Reached $QueryLimit record query limitation for this endpoint" -ForegroundColor Yellow + Write-Warning "[WARN]: Reached $QueryLimit record query limitation for this endpoint" } Elseif ($Count -ge $Total -and $Total -ge 0) { $Done = $true diff --git a/Public/Get-LMDevice.ps1 b/Public/Get-LMDevice.ps1 index ab0e089..b772283 100644 --- a/Public/Get-LMDevice.ps1 +++ b/Public/Get-LMDevice.ps1 @@ -127,7 +127,7 @@ Function Get-LMDevice { #Store delta id if delta switch is present If ($Response.deltaId -and !$DeltaIdResponse) { $DeltaIdResponse = $Response.deltaId - Write-LMHost "[INFO]: Delta switch detected, for further queries you can use deltaId: $DeltaIdResponse to perform additional delta requests. This variable can be accessed by referencing the `$LMDeltaId " -ForegroundColor Yellow + Write-Information "[INFO]: Delta switch detected, for further queries you can use deltaId: $DeltaIdResponse to perform additional delta requests. This variable can be accessed by referencing the `$LMDeltaId " Set-Variable -Name "LMDeltaId" -Value $DeltaIdResponse -Scope global } diff --git a/Public/Get-LMEventSource.ps1 b/Public/Get-LMEventSource.ps1 index 0c9b154..c8a8872 100644 --- a/Public/Get-LMEventSource.ps1 +++ b/Public/Get-LMEventSource.ps1 @@ -54,7 +54,7 @@ Function Get-LMEventSource { #Stop looping if single device, no need to continue If ($PSCmdlet.ParameterSetName -eq "Id") { $Done = $true - Return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.LogicModule") + Return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.EventSource") } #Check result size and if needed loop again Else { @@ -73,7 +73,7 @@ Function Get-LMEventSource { } } } - Return (Add-ObjectTypeInfo -InputObject $Results -TypeName "LogicMonitor.LogicModule") + Return (Add-ObjectTypeInfo -InputObject $Results -TypeName "LogicMonitor.EventSource") } Else { Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again." diff --git a/Public/Get-LMIntegrationLogs.ps1 b/Public/Get-LMIntegrationLogs.ps1 index 7a3a30a..40e5cf0 100644 --- a/Public/Get-LMIntegrationLogs.ps1 +++ b/Public/Get-LMIntegrationLogs.ps1 @@ -36,7 +36,7 @@ Function Get-LMIntegrationLogs { #Convert to epoch, if not set use defaults If (!$StartDate) { If ($PSCmdlet.ParameterSetName -ne "Id") { - Write-LMHost "[WARN]: No start date specified, defaulting to last 30 days" -ForegroundColor Yellow + Write-Warning "[WARN]: No start date specified, defaulting to last 30 days" } [int]$StartDate = ([DateTimeOffset]$(Get-Date).AddDays(-30)).ToUnixTimeSeconds() } @@ -88,7 +88,7 @@ Function Get-LMIntegrationLogs { $Results += $Response.Items If ($Count -ge $QueryLimit) { $Done = $true - Write-LMHost "[WARN]: Reached $QueryLimit record query limitation for this endpoint" -ForegroundColor Yellow + Write-Warning "[WARN]: Reached $QueryLimit record query limitation for this endpoint" } Elseif ($Count -ge $Total -and $Total -ge 0) { $Done = $true diff --git a/Public/Import-LMDashboard.ps1 b/Public/Import-LMDashboard.ps1 index eb33819..b977938 100644 --- a/Public/Import-LMDashboard.ps1 +++ b/Public/Import-LMDashboard.ps1 @@ -140,7 +140,7 @@ Function Import-LMDashboard { $RepoData = (Invoke-RestMethod -Uri $Uri -Headers $Headers[0] -WebSession $Headers[1]).tree | Where-Object { $_.Path -like "*.json" -and $_.Path -notlike "Packages/LogicMonitor_Dashboards*" } | Select-Object path, url If ($RepoData) { $TotalItems = ($RepoData | Measure-Object).Count - Write-LMHost "[INFO]: Found $TotalItems JSON files from Github repo ($GithubUserRepo)" + Write-Information "[INFO]: Found $TotalItems JSON files from Github repo ($GithubUserRepo)" Foreach ($Item in $RepoData) { $EncodedDash = (Invoke-RestMethod -Uri $Item.url -Headers $Headers[0] -WebSession $Headers[1]).content $DashboardList += @{ @@ -150,7 +150,7 @@ Function Import-LMDashboard { parentname = $ParentGroupName } - Write-LMHost "[INFO]: Successfully downloaded dashboard ($($Item.path)) from Github repo ($GithubUserRepo)" + Write-Information "[INFO]: Successfully downloaded dashboard ($($Item.path)) from Github repo ($GithubUserRepo)" } } } @@ -162,20 +162,20 @@ Function Import-LMDashboard { $DashboardAPIUser = Get-LMUser -Name $DashboardAPIUserName If (!$DashboardAPIRole) { $DashboardAPIRole = New-LMRole -Name $DashboardAPIRoleName -ResourcePermission view -DashboardsPermission manage -Description "Auto provisioned for use with dynamic dashboards" - Write-LMHost "[INFO]: Successfully generated required API role ($DashboardAPIRoleName) for dynamic dashboards" + Write-Information "[INFO]: Successfully generated required API role ($DashboardAPIRoleName) for dynamic dashboards" } If (!$DashboardAPIUser) { $DashboardAPIUser = New-LMAPIUser -Username "$DashboardAPIUserName" -note "Auto provisioned for use with dynamic dashboards" -RoleNames @($DashboardAPIRoleName) - Write-LMHost "[INFO]: Successfully generated required API user ($DashboardAPIUserName) for dynamic dashboards" + Write-Information "[INFO]: Successfully generated required API user ($DashboardAPIUserName) for dynamic dashboards" } If ($DashboardAPIRole -and $DashboardAPIUser) { $APIToken = New-LMAPIToken -Username $DashboardAPIUserName -Note "Auto provisioned for use with dynamic dashboards" If ($APIToken) { - Write-LMHost "[INFO]: Successfully generated required API token for dynamic dashboards for user: $DashboardAPIUserName" + Write-Information "[INFO]: Successfully generated required API token for dynamic dashboards for user: $DashboardAPIUserName" } } Else { - Write-LMHost "[WARN]: Unable to generate required API token for dynamic dashboards, manually update the required tokens to use dynamic dashboards" -ForegroundColor Yellow + Write-Warning "[WARN]: Unable to generate required API token for dynamic dashboards, manually update the required tokens to use dynamic dashboards" } } @@ -204,7 +204,7 @@ Function Import-LMDashboard { $DashboardGroup = Get-LMDashboardGroup -ParentGroupId $ParentGroupId | Where-Object { $_.Name -eq $SubFolders[$Index] } If (!$DashboardGroup) { - Write-LMHost "[INFO]: Existing dashboard group not found for $($Subfolders[$Index]) creating new resource group under root group ($ParentGroupName)" + Write-Information "[INFO]: Existing dashboard group not found for $($Subfolders[$Index]) creating new resource group under root group ($ParentGroupName)" $NewDashboardGroup = New-LMDashboardGroup -Name $SubFolders[$Index] -ParentGroupId $ParentGroupId $Dashboard.parentid = $NewDashboardGroup.id $Dashboard.parentname = $NewDashboardGroup.name @@ -221,7 +221,7 @@ Function Import-LMDashboard { If (!$DashboardGroup) { $NewDashboardParentGroup = Get-LMDashboardGroup -Name $Subfolders[$Index - 1] | Where-Object { $_.fullPath -like "$ParentGroupName*" -or $_.fullPath -eq $Subfolders[$Index - 1] } - Write-LMHost "[INFO]: Existing dashboard group not found for $($Subfolders[$Index]) creating new resource group under group ($($NewDashboardParentGroup.Name))" + Write-Information "[INFO]: Existing dashboard group not found for $($Subfolders[$Index]) creating new resource group under group ($($NewDashboardParentGroup.Name))" $NewDashboardGroup = New-LMDashboardGroup -Name $SubFolders[$Index] -ParentGroupId $NewDashboardParentGroup.id $Dashboard.parentid = $NewDashboardGroup.id diff --git a/Public/Invoke-LMAWSAccountTest.ps1 b/Public/Invoke-LMAWSAccountTest.ps1 index 9868417..71c8e43 100644 --- a/Public/Invoke-LMAWSAccountTest.ps1 +++ b/Public/Invoke-LMAWSAccountTest.ps1 @@ -78,7 +78,7 @@ Function Invoke-LMAWSAccountTest { #Issue request $Response = Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Data - Write-LMHost "All services have been tested successfully" -ForegroundColor Green + Write-Information "All services have been tested successfully" Return } Catch [Exception] { diff --git a/Public/Invoke-LMActiveDiscovery.ps1 b/Public/Invoke-LMActiveDiscovery.ps1 index a25ffbf..ed4a461 100644 --- a/Public/Invoke-LMActiveDiscovery.ps1 +++ b/Public/Invoke-LMActiveDiscovery.ps1 @@ -110,7 +110,7 @@ Function Invoke-LMActiveDiscovery { #Issue request $Response = Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] - Write-Host "Scheduled Active Discovery task for device id: $device." + Write-Information "[INFO]: Scheduled Active Discovery task for device id: $device." } Catch [Exception] { $Proceed = Resolve-LMException -LMException $PSItem diff --git a/Public/Invoke-LMAzureAccountTest.ps1 b/Public/Invoke-LMAzureAccountTest.ps1 index 6d1b723..ef6b9ac 100644 --- a/Public/Invoke-LMAzureAccountTest.ps1 +++ b/Public/Invoke-LMAzureAccountTest.ps1 @@ -84,7 +84,7 @@ Function Invoke-LMAzureAccountTest { #Issue request $Response = Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Data - Write-LMHost "All services have been tested successfully" -ForegroundColor Green + Write-Information "All services have been tested successfully" Return } Catch [Exception] { diff --git a/Public/Invoke-LMCollectorDebugCommand.ps1 b/Public/Invoke-LMCollectorDebugCommand.ps1 index 7130480..cf396a4 100644 --- a/Public/Invoke-LMCollectorDebugCommand.ps1 +++ b/Public/Invoke-LMCollectorDebugCommand.ps1 @@ -143,7 +143,7 @@ $PoshCommand While (!$CommandCompleted) { $CommandResult = Get-LMCollectorDebugResult -SessionId $Response.sessionId -Id $Id If ($CommandResult.errorMessage -eq "Agent has fetched the task, waiting for response") { - Write-LMHost "[INFO]: Agent has fetched the task, waiting for response..." -ForegroundColor green + Write-Information "[INFO]: Agent has fetched the task, waiting for response..." Start-Sleep -Seconds 5 } Else { diff --git a/Public/Invoke-LMGCPAccountTest.ps1 b/Public/Invoke-LMGCPAccountTest.ps1 index 6694317..bc2ec1f 100644 --- a/Public/Invoke-LMGCPAccountTest.ps1 +++ b/Public/Invoke-LMGCPAccountTest.ps1 @@ -65,7 +65,7 @@ Function Invoke-LMGCPAccountTest { #Issue request $Response = Invoke-RestMethod -Uri $Uri -Method "POST" -Headers $Headers[0] -WebSession $Headers[1] -Body $Data - Write-LMHost "All services have been tested successfully" -ForegroundColor Green + Write-Information "All services have been tested successfully" Return } Catch [Exception] { diff --git a/Public/New-LMAPIUser.ps1 b/Public/New-LMAPIUser.ps1 index d83c41e..d43a941 100644 --- a/Public/New-LMAPIUser.ps1 +++ b/Public/New-LMAPIUser.ps1 @@ -55,7 +55,7 @@ Function New-LMAPIUser { $Roles += @{id = $RoleId } } Else { - Write-LMHost "[WARN]: Unable to locate user role named $Role, it will be skipped" -ForegroundColor Yellow + Write-Warning "[WARN]: Unable to locate user role named $Role, it will be skipped" } } diff --git a/Public/New-LMAccessGroupMapping.ps1 b/Public/New-LMAccessGroupMapping.ps1 new file mode 100644 index 0000000..035f37a --- /dev/null +++ b/Public/New-LMAccessGroupMapping.ps1 @@ -0,0 +1,96 @@ +<# +.SYNOPSIS +Creates a new LogicMonitor access group mapping between an access group and an logicmodule. + +.DESCRIPTION +The New-LMAccessGroupMapping function is used to create a new access group mapping in LogicMonitor. + +.PARAMETER AccessGroupIds +The IDs of the access group. This parameter is mandatory. + +.PARAMETER LogicModuleType +The type of logic module. This parameter is mandatory. + +.PARAMETER LogicModuleId +The ID of the logic module. This parameter is mandatory. + +.EXAMPLE +New-LMAccessGroupMapping -AccessGroupIds "12345" -LogicModuleType "DATASOURCE" -LogicModuleId "67890" + +This example creates a new access group mapping for the access group with ID "12345" and the logic module with ID "67890". + +.NOTES +For this function to work, you need to be logged in and have valid API credentials. Use the Connect-LMAccount function to log in before running any commands. +#> +Function New-LMAccessGroupMapping { + + [CmdletBinding()] + Param ( + + [Parameter(Mandatory)] + [String[]]$AccessGroupIds, + + [Parameter(Mandatory)] + [ValidateSet("DATASOURCE", "EVENTSOURCE", "BATCHJOB", "JOBMONITOR", "LOGSOURCE", "TOPOLOGYSOURCE", "PROPERTYSOURCE", "APPLIESTO_FUNCTION", "SNMP_SYSOID_MAP")] + [String]$LogicModuleType, + + [Parameter(Mandatory)] + [Int]$LogicModuleId + + ) + #Check if we are logged in and have valid api creds + Begin {} + Process { + If ($Script:LMAuth.Valid) { + + #Build header and uri + $ResourcePath = "/setting/accessgroup/mapunmap/modules" + + $MappingDetailsArray = New-Object -TypeName System.Collections.ArrayList + + $MappingDetailsArray.Add([PSCustomObject]@{ + moduletype = $LogicModuleType + moduleid = $LogicModuleId + accessgroups = $AccessGroupIds + }) | Out-Null + + Try { + $Data = [PSCustomObject]@{ + mappingDetails = $MappingDetailsArray + } + + $Data = ($Data | ConvertTo-Json -Depth 10) + $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 + + If($Response.failure) { + Foreach($Failure in $Response.failure) { + Write-Warning "$Failure" + } + } + If($Response.success) { + Foreach($Success in $Response.success) { + Write-Information "[INFO]: Successfully mapped ($LogicModuleType/$LogicModuleId) to accessgroup(s): $($AccessGroupIds -join ',')" + } + } + + Return $Response.mappingDetails + } + 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 {} +} diff --git a/Public/New-LMCachedAccount.ps1 b/Public/New-LMCachedAccount.ps1 index e975146..45ad56d 100644 --- a/Public/New-LMCachedAccount.ps1 +++ b/Public/New-LMCachedAccount.ps1 @@ -41,11 +41,11 @@ Function New-LMCachedAccount { Try { $ExistingVault = Get-SecretInfo -Name Logic.Monitor -WarningAction Stop - Write-Host "[INFO]: Existing vault Logic.Monitor already exists, skipping creation" + Write-Information "[INFO]: Existing vault Logic.Monitor already exists, skipping creation" } Catch { If ($_.Exception.Message -like "*There are currently no extension vaults registered*") { - 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 } @@ -73,7 +73,7 @@ Function New-LMCachedAccount { } Try { Set-Secret -Name $CachedAccountName -Secret $Secret -Vault Logic.Monitor -Metadata $Metadata -NoClobber:$(!$OverwriteExisting) - Write-Host "[INFO]: Successfully created cached account ($CachedAccountName) secret for portal: $AccountName" + Write-Information "[INFO]: Successfully created cached account ($CachedAccountName) secret for portal: $AccountName" } Catch { Write-Error $_.Exception.Message diff --git a/Public/New-LMUser.ps1 b/Public/New-LMUser.ps1 index 503b10e..4c59dad 100644 --- a/Public/New-LMUser.ps1 +++ b/Public/New-LMUser.ps1 @@ -119,7 +119,7 @@ Function New-LMUser { $Roles += @{id = $RoleId } } Else { - Write-LMHost "[WARN]: Unable to locate user role named $Role, it will be skipped" -ForegroundColor Yellow + Write-Warning "[WARN]: Unable to locate user role named $Role, it will be skipped" } } @@ -218,8 +218,8 @@ Function New-LMUser { $global:LMUserData.Add([PSCustomObject]@{"Username" = $Username; "Temp_Password" = $Password }) | Out-Null } - Write-LMHost "[INFO]: Auto generated password assigned to $Username`: $Password" -ForegroundColor Yellow - Write-LMHost "[INFO]: Auto generated passwords are also stored in a reference variable called `$LMUserData" -ForegroundColor Yellow + Write-Information "[INFO]: Auto generated password assigned to $Username`: $Password" + Write-Information "[INFO]: Auto generated passwords are also stored in a reference variable called `$LMUserData" } Return (Add-ObjectTypeInfo -InputObject $Response -TypeName "LogicMonitor.User" ) diff --git a/Public/Remove-LMCachedAccount.ps1 b/Public/Remove-LMCachedAccount.ps1 index 261fb1a..6e0fce6 100644 --- a/Public/Remove-LMCachedAccount.ps1 +++ b/Public/Remove-LMCachedAccount.ps1 @@ -41,20 +41,20 @@ Function Remove-LMCachedAccount { Foreach ($Account in $CachedAccounts.Name) { Try { Remove-Secret -Name $Account -Vault Logic.Monitor -Confirm:$false -ErrorAction Stop - Write-Host "[INFO]: Removed cached account secret for: $Account" + Write-Information "[INFO]: Removed cached account secret for: $Account" } Catch { Write-Error $_.Exception.Message } } - Write-Host "[INFO]: Processed all entries from credential cache" + Write-Information "[INFO]: Processed all entries from credential cache" } } Else { If ($PSCmdlet.ShouldProcess($CachedAccountName, "Remove Cached Account")) { Try { Remove-Secret -Name $CachedAccountName -Vault Logic.Monitor -Confirm:$false -ErrorAction Stop - Write-Host "[INFO]: Removed cached account secret for: $CachedAccountName" + Write-Information "[INFO]: Removed cached account secret for: $CachedAccountName" } Catch { Write-Error $_.Exception.Message diff --git a/Public/Set-LMCollectorConfig.ps1 b/Public/Set-LMCollectorConfig.ps1 index c703de4..e31858a 100644 --- a/Public/Set-LMCollectorConfig.ps1 +++ b/Public/Set-LMCollectorConfig.ps1 @@ -106,11 +106,11 @@ Function Set-LMCollectorConfig { $ConfigArray = $Config.Split([Environment]::NewLine) [int[]]$Index = [Linq.Enumerable]::Range(0, $ConfigArray.Count).Where({ Param($i) $ConfigArray[$i] -match $ConfLine }) If (($Index | Measure-Object).Count -eq 1) { - Write-LMHost "[INFO]: Updating config parameter $ConfLine to value $Value." + Write-Information "[INFO]: Updating config parameter $ConfLine to value $Value." $ConfigArray[$Index[0]] = "$ConfLine=$Value" } Else { - Write-LMHost "[WARN]: Multiple matches found for config parameter $ConfLine, skipping processing." -ForegroundColor Yellow + Write-Warning "[WARN]: Multiple matches found for config parameter $ConfLine, skipping processing." } Return ([string]::Join([Environment]::NewLine, $ConfigArray)) @@ -197,7 +197,7 @@ Function Set-LMCollectorConfig { $Data = ($Data | ConvertTo-Json) If ($PSCmdlet.ShouldProcess($Message, "Set Collector Config ")) { - Write-LMHost "[WARN]: This command will restart the targeted collector on update of the configuration" -ForegroundColor Yellow + Write-Warning "[WARN]: This command will restart the targeted collector on update of the configuration" $Headers = New-LMHeader -Auth $Script:LMAuth -Method "POST" -ResourcePath $ResourcePath -Data $Data $Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath @@ -217,7 +217,7 @@ Function Set-LMCollectorConfig { $SubmitResponse = Invoke-RestMethod -Uri $Uri -Method "GET" -Headers $Headers[0] -WebSession $Headers[1] If ($SubmitResponse.errorMessage -eq "The task is still running") { - Write-LMHost "[INFO]: The task is still running..." + Write-Information "[INFO]: The task is still running..." Start-Sleep -Seconds 2 $Tries++ } diff --git a/Public/Set-LMUser.ps1 b/Public/Set-LMUser.ps1 index 315892a..7a1bae5 100644 --- a/Public/Set-LMUser.ps1 +++ b/Public/Set-LMUser.ps1 @@ -89,7 +89,7 @@ Function Set-LMUser { $Roles += @{id = $RoleId } } Else { - Write-LMHost "[WARN]: Unable to locate user role named $Role, it will be skipped" -ForegroundColor Yellow + Write-Warning "[WARN]: Unable to locate user role named $Role, it will be skipped" } } diff --git a/README.md b/README.md index 730a302..575a1d5 100644 --- a/README.md +++ b/README.md @@ -426,18 +426,28 @@ This change aims to enhance visibility within the community and to foster a more We appreciate your continued support and enthusiasm for the Logic.Monitor PowerShell module. Your contributions and feedback are vital to the success of this project, and we look forward to seeing how the module evolves with your participation. -## 6.3 +## 6.4 +### Module Updates/Changes + - **Write-LMHost** has been removed entirely starting in this version and replaced with native Write-Information,Warning and Error cmdlets. If you would like to suppress the output of these cmdlets you can use the *\$InformationPreference*, *\$DebugPreference* and *\$WarningPreference* variables. Additionally you can use the *-DisableConsoleLogging* switch on Connect-LMAccount to suppress Write-Information output. + - New/Updated Pester tests have been added to validate the module builds and ensure functionality for the following cmdlets: + - AccessGroup + - AppliesToFunction + - AppliesToSearch + - Device + - DeviceGroup + - NetScanGroup + - OpsNotes + - ReportGroup + - SDT + - Users/Roles + - Website + - WebsiteGroup + ### New Cmdlets: - - **Get-LMLogSource**: This cmdlet will retrieve data for specified LogSources. - - **Remove-LMLogSource**: This cmdlet will remove a specified LogSource. - - **Test-LMAppliesToQuery**: This cmdlet will retrieve the results for a specified AppliesToQuery string, similar to the Test AppliesTo button in the portal UI. - + - **New-LMAccessGroupMapping**: This cmdlet will create a new access group mapping/unmapping based on specified module and accessgroups. ### Updated Cmdlets: - **Export-LMLogicModule**: Added support for LogSources. - - **Get-LMAlert**: Fixed incorrect type filter for EventSources. Issue #11 - - **New-LMOpsNote**: Fixed bug causing device and website ID scopes to not be properly set. Issue #10 - - **Set-LMDeviceDatasourceInstanceAlertSetting**: Fixed bug causing instance id lookup to fail when specifying instance name. [Previous Release Notes](RELEASENOTES.md) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 851bb67..c1538a6 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,4 +1,17 @@ # Previous module release notes +## 6.3 +### New Cmdlets: + - **Get-LMLogSource**: This cmdlet will retrieve data for specified LogSources. + - **Remove-LMLogSource**: This cmdlet will remove a specified LogSource. + - **Test-LMAppliesToQuery**: This cmdlet will retrieve the results for a specified AppliesToQuery string, similar to the Test AppliesTo button in the portal UI. + + +### Updated Cmdlets: + - **Export-LMLogicModule**: Added support for LogSources. + - **Get-LMAlert**: Fixed incorrect type filter for EventSources. Issue #11 + - **New-LMOpsNote**: Fixed bug causing device and website ID scopes to not be properly set. Issue #10 + - **Set-LMDeviceDatasourceInstanceAlertSetting**: Fixed bug causing instance id lookup to fail when specifying instance name. + ## 6.2 ### New Cmdlets: - **Get-LMAccessGroup**: This cmdlet will retrieve data for specified LogicMonitor access groups. You can retrieve all access groups or limit the results using *-Id*, *-Name* or *-Filter* parameters. diff --git a/Tests/LMAccessGroup.Tests.ps1 b/Tests/LMAccessGroup.Tests.ps1 new file mode 100644 index 0000000..77dd755 --- /dev/null +++ b/Tests/LMAccessGroup.Tests.ps1 @@ -0,0 +1,53 @@ +Describe 'AccessGroup Testing New/Get/Set/Remove' { + BeforeAll { + Import-Module $Module -Force + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation + } + + Describe 'New-LMAccessGroup' { + It 'When given mandatory parameters, returns a created access group with matching values' { + $Script:NewAccessGroup = New-LMAccessGroup -Name "AccessGroup.Build.Test" -Description "BuildTest" + $Script:NewAccessGroup | Should -Not -BeNullOrEmpty + $Script:NewAccessGroup.Name | Should -Be "AccessGroup.Build.Test" + $Script:NewAccessGroup.Description | Should -Be "BuildTest" + } + } + + Describe 'Get-LMAccessGroup' { + It 'When given no parameters, returns all access groups' { + $AccessGroup = Get-LMAccessGroup + ($AccessGroup | Measure-Object).Count | Should -BeGreaterThan 0 + } + It 'When given an id should return that access group' { + $AccessGroup = Get-LMAccessGroup -Id $Script:NewAccessGroup.Id + ($AccessGroup | Measure-Object).Count | Should -BeExactly 1 + } + It 'When given a name should return specified access group matching that name' { + $AccessGroup = Get-LMAccessGroup -Name $Script:NewAccessGroup.Name + ($AccessGroup | Measure-Object).Count | Should -BeExactly 1 + } + It 'When given a wildcard name should return all access groups matching that wildcard value' { + $AccessGroup = Get-LMAccessGroup -Name "$(($Script:NewAccessGroup.Name.Split(".")[0]))*" + ($AccessGroup | Measure-Object).Count | Should -BeGreaterThan 0 + } + } + + Describe 'Set-LMAccessGroup' { + It 'When given a set of parameters, returns an updated access group with matching values' { + { $AccessGroup = Set-LMAccessGroup -Id $Script:NewAccessGroup.Id -Description "Updated" -NewName "AccessGroup.Build.Test.Updated" -ErrorAction Stop + $AccessGroup.Description | Should -Be "Updated" + $AccessGroup.Name | Should -Be "AccessGroup.Build.Test.Updated" + } | Should -Not -Throw + } + } + + Describe 'Remove-LMAccessGroup' { + It 'When given an id, remove the access group from logic monitor' { + { Remove-LMAccessGroup -Id $Script:NewAccessGroup.Id -ErrorAction Stop -Confirm:$false } | Should -Not -Throw + } + } + + AfterAll { + Disconnect-LMAccount + } +} \ No newline at end of file diff --git a/Tests/LMAppliesToFunction.Tests.ps1 b/Tests/LMAppliesToFunction.Tests.ps1 index 4c2dd5b..94fc4e4 100644 --- a/Tests/LMAppliesToFunction.Tests.ps1 +++ b/Tests/LMAppliesToFunction.Tests.ps1 @@ -1,7 +1,7 @@ Describe 'AppliesToFunction Testing New/Get/Set/Remove' { BeforeAll { Import-Module $Module -Force - Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation } Describe 'New-LMAppliesToFunction' { diff --git a/Tests/LMAppliesToSearch.Tests.ps1 b/Tests/LMAppliesToSearch.Tests.ps1 new file mode 100644 index 0000000..4456223 --- /dev/null +++ b/Tests/LMAppliesToSearch.Tests.ps1 @@ -0,0 +1,37 @@ +Describe 'AppliesToQuery Testing' { + BeforeAll { + Import-Module $Module -Force + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation + } + + Describe 'Test-LMAppliesToQuery' { + It 'When given a valid query, returns matching devices' { + $Query = 'system.hostname =~ "lm*"' + $Result = Test-LMAppliesToQuery -Query $Query + $Result | Should -Not -BeNullOrEmpty + $Result.Count | Should -BeGreaterThan 0 + } + + It 'When given an invalid query, throws an error' { + $Query = 'invalid_property ~= "value"' + { Test-LMAppliesToQuery -Query $Query -ErrorAction Stop } | Should -Throw + } + + It 'When given a query that matches no devices, returns an empty result' { + $Query = 'system.hostname == "non_existent_hostname"' + $Result = Test-LMAppliesToQuery -Query $Query + $Result | Should -BeNullOrEmpty + } + + It 'When given a complex query, returns correct results' { + $Query = 'system.hostname =~ "^lm" && system.displayname =~ "^lm"' + $Result = Test-LMAppliesToQuery -Query $Query + $Result | Should -Not -BeNullOrEmpty + $Result | ForEach-Object { $_.name | Should -BeLike 'lm*' } + } + } + + AfterAll { + Disconnect-LMAccount + } +} \ No newline at end of file diff --git a/Tests/LMDevice.Tests.ps1 b/Tests/LMDevice.Tests.ps1 index 877f962..e02030f 100644 --- a/Tests/LMDevice.Tests.ps1 +++ b/Tests/LMDevice.Tests.ps1 @@ -1,7 +1,7 @@ Describe 'Device Testing New/Get/Set/Remove' { BeforeAll { Import-Module $Module -Force - Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation } Describe 'New-LMDevice' { diff --git a/Tests/LMDeviceGroup.Tests.ps1 b/Tests/LMDeviceGroup.Tests.ps1 index 60ea492..36e3604 100644 --- a/Tests/LMDeviceGroup.Tests.ps1 +++ b/Tests/LMDeviceGroup.Tests.ps1 @@ -1,7 +1,7 @@ Describe 'DeviceGroup Testing New/Get/Set/Remove' { BeforeAll { Import-Module $Module -Force - Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation } Describe 'New-LMDeviceGroup' { diff --git a/Tests/LMNetScanGroup.Tests.ps1 b/Tests/LMNetScanGroup.Tests.ps1 new file mode 100644 index 0000000..3ff994a --- /dev/null +++ b/Tests/LMNetScanGroup.Tests.ps1 @@ -0,0 +1,56 @@ +Describe 'NetScanGroup Testing New/Get/Set/Remove' { + BeforeAll { + Import-Module $Module -Force + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation + } + + Describe 'New-LMNetScanGroup' { + It 'When given mandatory parameters, returns a created NetScan group with matching values' { + $Script:NewNetScanGroup = New-LMNetScanGroup -Name "NetScanGroup.Build.Test" -Description "BuildTest" + $Script:NewNetScanGroup | Should -Not -BeNullOrEmpty + $Script:NewNetScanGroup.Name | Should -Be "NetScanGroup.Build.Test" + $Script:NewNetScanGroup.Description | Should -Be "BuildTest" + } + } + + Describe 'Get-LMNetScanGroup' { + It 'When given no parameters, returns all NetScan groups' { + $NetScanGroup = Get-LMNetScanGroup + ($NetScanGroup | Measure-Object).Count | Should -BeGreaterThan 0 + } + It 'When given an id should return that NetScan group' { + $NetScanGroup = Get-LMNetScanGroup -Id $Script:NewNetScanGroup.Id + ($NetScanGroup | Measure-Object).Count | Should -BeExactly 1 + } + It 'When given a name should return specified NetScan group matching that name' { + $NetScanGroup = Get-LMNetScanGroup -Name $Script:NewNetScanGroup.Name + ($NetScanGroup | Measure-Object).Count | Should -BeExactly 1 + } + It 'When given a wildcard name should return all NetScan groups matching that wildcard value' { + $NetScanGroup = Get-LMNetScanGroup -Name "$(($Script:NewNetScanGroup.Name.Split(".")[0]))*" + ($NetScanGroup | Measure-Object).Count | Should -BeGreaterThan 0 + } + It 'When given an invalid id, should throw an error' { + { Get-LMNetScanGroup -Id 0 -ErrorAction Stop } | Should -Throw + } + } + + Describe 'Set-LMNetScanGroup' { + It 'When given a set of parameters, returns an updated NetScan group with matching values' { + { $NetScanGroup = Set-LMNetScanGroup -Id $Script:NewNetScanGroup.Id -Description "Updated" -NewName "NetScanGroup.Build.Test.Updated" -ErrorAction Stop + $NetScanGroup.Description | Should -Be "Updated" + $NetScanGroup.Name | Should -Be "NetScanGroup.Build.Test.Updated" + } | Should -Not -Throw + } + } + + Describe 'Remove-LMNetScanGroup' { + It 'When given an id, remove the NetScan group from logic monitor' { + { Remove-LMNetScanGroup -Id $Script:NewNetScanGroup.Id -ErrorAction Stop -Confirm:$false } | Should -Not -Throw + } + } + + AfterAll { + Disconnect-LMAccount + } +} \ No newline at end of file diff --git a/Tests/LMOpsNotes.Tests.ps1 b/Tests/LMOpsNotes.Tests.ps1 index 6be19ab..2c3346d 100644 --- a/Tests/LMOpsNotes.Tests.ps1 +++ b/Tests/LMOpsNotes.Tests.ps1 @@ -1,7 +1,7 @@ Describe 'OpsNotes Testing New/Get/Set/Remove' { BeforeAll { Import-Module $Module -Force - Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation } Describe 'New-LMOpsNote' { diff --git a/Tests/LMReportGroup.Tests.ps1 b/Tests/LMReportGroup.Tests.ps1 new file mode 100644 index 0000000..a4e0cff --- /dev/null +++ b/Tests/LMReportGroup.Tests.ps1 @@ -0,0 +1,56 @@ +Describe 'ReportGroup Testing New/Get/Set/Remove' { + BeforeAll { + Import-Module $Module -Force + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation + } + + Describe 'New-LMReportGroup' { + It 'When given mandatory parameters, returns a created Report group with matching values' { + $Script:NewReportGroup = New-LMReportGroup -Name "ReportGroup.Build.Test" -Description "BuildTest" + $Script:NewReportGroup | Should -Not -BeNullOrEmpty + $Script:NewReportGroup.Name | Should -Be "ReportGroup.Build.Test" + $Script:NewReportGroup.Description | Should -Be "BuildTest" + } + } + + Describe 'Get-LMReportGroup' { + It 'When given no parameters, returns all Report groups' { + $ReportGroup = Get-LMReportGroup + ($ReportGroup | Measure-Object).Count | Should -BeGreaterThan 0 + } + It 'When given an id should return that Report group' { + $ReportGroup = Get-LMReportGroup -Id $Script:NewReportGroup.Id + ($ReportGroup | Measure-Object).Count | Should -BeExactly 1 + } + It 'When given a name should return specified Report group matching that name' { + $ReportGroup = Get-LMReportGroup -Name $Script:NewReportGroup.Name + ($ReportGroup | Measure-Object).Count | Should -BeExactly 1 + } + It 'When given a wildcard name should return all Report groups matching that wildcard value' { + $ReportGroup = Get-LMReportGroup -Name "$(($Script:NewReportGroup.Name.Split(".")[0]))*" + ($ReportGroup | Measure-Object).Count | Should -BeGreaterThan 0 + } + It 'When given an invalid id, should throw an error' { + { Get-LMReportGroup -Id -1 -ErrorAction Stop } | Should -Throw + } + } + + Describe 'Set-LMReportGroup' { + It 'When given a set of parameters, returns an updated Report group with matching values' { + { $ReportGroup = Set-LMReportGroup -Id $Script:NewReportGroup.Id -Description "Updated" -NewName "ReportGroup.Build.Test.Updated" -ErrorAction Stop + $ReportGroup.Description | Should -Be "Updated" + $ReportGroup.Name | Should -Be "ReportGroup.Build.Test.Updated" + } | Should -Not -Throw + } + } + + Describe 'Remove-LMReportGroup' { + It 'When given an id, remove the Report group from logic monitor' { + { Remove-LMReportGroup -Id $Script:NewReportGroup.Id -ErrorAction Stop -Confirm:$false } | Should -Not -Throw + } + } + + AfterAll { + Disconnect-LMAccount + } +} \ No newline at end of file diff --git a/Tests/LMSDT.Tests.ps1 b/Tests/LMSDT.Tests.ps1 new file mode 100644 index 0000000..09f0a87 --- /dev/null +++ b/Tests/LMSDT.Tests.ps1 @@ -0,0 +1,74 @@ +Describe 'SDT Testing' { + BeforeAll { + Import-Module $Module -Force + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation + } + + Describe 'New-LMDeviceGroupSDT' { + It 'When given mandatory parameters, returns a created DeviceGroup SDT with matching values' { + $StartDate = (Get-Date).AddMinutes(5) + $EndDate = $StartDate.AddHours(1) + $Script:NewDeviceGroupSDT = New-LMDeviceGroupSDT -DeviceGroupId 1 -StartDate $StartDate -EndDate $EndDate -Comment "DeviceGroupSDT.Build.Test" + $Script:NewDeviceGroupSDT | Should -Not -BeNullOrEmpty + $Script:NewDeviceGroupSDT.Comment | Should -Be "DeviceGroupSDT.Build.Test" + $Script:NewDeviceGroupSDT.Type | Should -Be "ResourceGroupSDT" + } + } + + Describe 'New-LMDeviceSDT' { + It 'When given mandatory parameters, returns a created Device SDT with matching values' { + $StartDate = (Get-Date).AddMinutes(5) + $EndDate = $StartDate.AddHours(1) + $Script:NewDeviceSDT = New-LMDeviceSDT -DeviceId 123 -StartDate $StartDate -EndDate $EndDate -Comment "DeviceSDT.Build.Test" + $Script:NewDeviceSDT | Should -Not -BeNullOrEmpty + $Script:NewDeviceSDT.Comment | Should -Be "DeviceSDT.Build.Test" + $Script:NewDeviceSDT.Type | Should -Be "ResourceSDT" + } + } + + Describe 'Get-LMDeviceGroupSDT' { + It 'When given a DeviceGroupId, returns SDTs for that group' { + $SDTs = Get-LMDeviceGroupSDT -Id 1 + $SDTs | Should -Not -BeNullOrEmpty + $SDTs.Count | Should -BeGreaterThan 0 + } + } + + Describe 'Get-LMDeviceSDT' { + It 'When given a DeviceId, returns SDTs for that device' { + $SDTs = Get-LMDeviceSDT -Id 123 + $SDTs | Should -Not -BeNullOrEmpty + $SDTs.Count | Should -BeGreaterThan 0 + } + } + + Describe 'Get-LMSDT' { + It 'When given no parameters, returns all SDTs' { + $SDT = Get-LMSDT + $SDT | Should -Not -BeNullOrEmpty + $SDT.Count | Should -BeGreaterThan 0 + } + It 'When given an id should return that SDT' { + $SDT = Get-LMSDT -Id $Script:NewDeviceGroupSDT.Id + $SDT | Should -Not -BeNullOrEmpty + $SDT.Count | Should -BeExactly 1 + } + It 'When given an invalid id, should empty response' { + $SDT = Get-LMSDT -Id 0 + $SDT | Should -BeNullOrEmpty + } + } + + Describe 'Remove-LMSDT' { + It 'When given a DeviceGroup SDT id, remove the SDT from logic monitor' { + { Remove-LMSDT -Id $Script:NewDeviceGroupSDT.Id -ErrorAction Stop -Confirm:$false } | Should -Not -Throw + } + It 'When given a Device SDT id, remove the SDT from logic monitor' { + { Remove-LMSDT -Id $Script:NewDeviceSDT.Id -ErrorAction Stop -Confirm:$false } | Should -Not -Throw + } + } + + AfterAll { + Disconnect-LMAccount + } +} \ No newline at end of file diff --git a/Tests/LMUser-Role.Tests.ps1 b/Tests/LMUser-Role.Tests.ps1 index 5c2a983..9945c87 100644 --- a/Tests/LMUser-Role.Tests.ps1 +++ b/Tests/LMUser-Role.Tests.ps1 @@ -1,7 +1,7 @@ Describe 'User & Role Testing New/Get/Set/Remove' { BeforeAll { Import-Module $Module -Force - Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation } Describe 'New-LMApiUser' { diff --git a/Tests/LMWebsite.Tests.ps1 b/Tests/LMWebsite.Tests.ps1 index 0170e1a..1c50204 100644 --- a/Tests/LMWebsite.Tests.ps1 +++ b/Tests/LMWebsite.Tests.ps1 @@ -1,7 +1,7 @@ Describe 'Website Testing New/Get/Set/Remove' { BeforeAll { Import-Module $Module -Force - Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation } Describe 'New-LMWebsite' { diff --git a/Tests/LMWebsiteGroup.Tests.ps1 b/Tests/LMWebsiteGroup.Tests.ps1 index 8b171ee..88138c0 100644 --- a/Tests/LMWebsiteGroup.Tests.ps1 +++ b/Tests/LMWebsiteGroup.Tests.ps1 @@ -1,7 +1,7 @@ Describe 'WebsiteGroup Testing New/Get/Set/Remove' { BeforeAll { Import-Module $Module -Force - Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging + Connect-LMAccount -AccessId $AccessId -AccessKey $AccessKey -AccountName $AccountName -DisableConsoleLogging -SkipCredValidation } Describe 'New-LMWebsiteGroup' { From 5557b06669295ea2f36b49d679207abbd22bfaf2 Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:00:17 -0400 Subject: [PATCH 2/9] Update github actions to run for non master branches --- .github/workflows/test-win.yml | 2 +- .github/workflows/test.yml | 2 +- README.md | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-win.yml b/.github/workflows/test-win.yml index 969deed..4ded6d5 100644 --- a/.github/workflows/test-win.yml +++ b/.github/workflows/test-win.yml @@ -2,7 +2,7 @@ name: Test Current Build on Windows Powershell 5.1 on: push: - branches: [ main ] + branches: [ !master ] paths-ignore: - '**.md' - '**.yml' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c0ac2c..540c643 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: Test Current Build on PowerShell Core on: push: - branches: [ main ] + branches: [ !master ] paths-ignore: - '**.md' - '**.yml' diff --git a/README.md b/README.md index 575a1d5..322120f 100644 --- a/README.md +++ b/README.md @@ -446,9 +446,6 @@ We appreciate your continued support and enthusiasm for the Logic.Monitor PowerS ### New Cmdlets: - **New-LMAccessGroupMapping**: This cmdlet will create a new access group mapping/unmapping based on specified module and accessgroups. -### Updated Cmdlets: - - **Export-LMLogicModule**: Added support for LogSources. - [Previous Release Notes](RELEASENOTES.md) From 2e7f22f3ffb83b64e0a982e60183fe38c40f6788 Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:02:09 -0400 Subject: [PATCH 3/9] Update Connect-LMAccount.ps1 --- Public/Connect-LMAccount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Public/Connect-LMAccount.ps1 b/Public/Connect-LMAccount.ps1 index e52bfdd..c02fb2f 100644 --- a/Public/Connect-LMAccount.ps1 +++ b/Public/Connect-LMAccount.ps1 @@ -101,7 +101,7 @@ Function Connect-LMAccount { If ($UseCachedCredential -or $CachedAccountName) { Try { - $ExistingVault = Get-SecretVault -Name Logic.Monitor -ErrorAction Stop + Get-SecretVault -Name Logic.Monitor -ErrorAction Stop | Out-Null Write-Information "[INFO]: Existing vault Logic.Monitor already exists, skipping creation" } Catch { From 543d0eab6b3174adefa9abdb9c632f777fdd34a9 Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:03:34 -0400 Subject: [PATCH 4/9] update actions --- .github/workflows/test-win.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-win.yml b/.github/workflows/test-win.yml index 4ded6d5..53d4f8e 100644 --- a/.github/workflows/test-win.yml +++ b/.github/workflows/test-win.yml @@ -2,7 +2,7 @@ name: Test Current Build on Windows Powershell 5.1 on: push: - branches: [ !master ] + branches: [ '!master'] paths-ignore: - '**.md' - '**.yml' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 540c643..9b8434e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: Test Current Build on PowerShell Core on: push: - branches: [ !master ] + branches: [ '!master'] paths-ignore: - '**.md' - '**.yml' From 569bd4091dd366b30bb35223072d1576a01e0d48 Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:10:47 -0400 Subject: [PATCH 5/9] Update Get-LMAlert.ps1 --- Public/Get-LMAlert.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Public/Get-LMAlert.ps1 b/Public/Get-LMAlert.ps1 index d435f21..b65a4bd 100644 --- a/Public/Get-LMAlert.ps1 +++ b/Public/Get-LMAlert.ps1 @@ -144,8 +144,6 @@ Function Get-LMAlert { $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 From 03c216690fd6c67f604a2559e70873819325f0de Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:12:03 -0400 Subject: [PATCH 6/9] update tests --- .github/workflows/test-win.yml | 3 ++- .github/workflows/test.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-win.yml b/.github/workflows/test-win.yml index 53d4f8e..834cdd6 100644 --- a/.github/workflows/test-win.yml +++ b/.github/workflows/test-win.yml @@ -2,7 +2,8 @@ name: Test Current Build on Windows Powershell 5.1 on: push: - branches: [ '!master'] + branches: + - '!master' paths-ignore: - '**.md' - '**.yml' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b8434e..daf52cc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,8 @@ name: Test Current Build on PowerShell Core on: push: - branches: [ '!master'] + branches: + - '!master' paths-ignore: - '**.md' - '**.yml' From d2081822d94645f1ce30ba497fa17592c9031b2f Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:15:22 -0400 Subject: [PATCH 7/9] test updates --- .github/workflows/test-win.yml | 2 +- .github/workflows/test.yml | 2 +- Private/Update-LogicMonitorModule.ps1 | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-win.yml b/.github/workflows/test-win.yml index 834cdd6..f635228 100644 --- a/.github/workflows/test-win.yml +++ b/.github/workflows/test-win.yml @@ -3,7 +3,7 @@ name: Test Current Build on Windows Powershell 5.1 on: push: branches: - - '!master' + - '**' paths-ignore: - '**.md' - '**.yml' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index daf52cc..f5c127d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test Current Build on PowerShell Core on: push: branches: - - '!master' + - '**' paths-ignore: - '**.md' - '**.yml' diff --git a/Private/Update-LogicMonitorModule.ps1 b/Private/Update-LogicMonitorModule.ps1 index fbe0520..4c5b2bd 100644 --- a/Private/Update-LogicMonitorModule.ps1 +++ b/Private/Update-LogicMonitorModule.ps1 @@ -78,7 +78,6 @@ Function Update-LogicMonitorModule { Install-Module -Name $Module -Force -AllowClobber -Verbose:$False -MinimumVersion $OnlineVersion Update-LogicMonitorModule -CheckOnly -Modules @($Module) } - } Else { Write-Information "[INFO]: Module $Module version $InstalledVersion is the latest version." From dd0634b0d2ac435fda78d7cf3199a01a010de705 Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:25:28 -0400 Subject: [PATCH 8/9] Update LMSDT.Tests.ps1 update sdt tests --- Tests/LMSDT.Tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/LMSDT.Tests.ps1 b/Tests/LMSDT.Tests.ps1 index 09f0a87..3e90552 100644 --- a/Tests/LMSDT.Tests.ps1 +++ b/Tests/LMSDT.Tests.ps1 @@ -28,17 +28,17 @@ Describe 'SDT Testing' { Describe 'Get-LMDeviceGroupSDT' { It 'When given a DeviceGroupId, returns SDTs for that group' { - $SDTs = Get-LMDeviceGroupSDT -Id 1 - $SDTs | Should -Not -BeNullOrEmpty - $SDTs.Count | Should -BeGreaterThan 0 + $SDT = Get-LMDeviceGroupSDT -Id 1 + $SDT | Should -Not -BeNullOrEmpty + ($SDT | Measure-Object).Count | Should -BeGreaterThan 0 } } Describe 'Get-LMDeviceSDT' { It 'When given a DeviceId, returns SDTs for that device' { - $SDTs = Get-LMDeviceSDT -Id 123 - $SDTs | Should -Not -BeNullOrEmpty - $SDTs.Count | Should -BeGreaterThan 0 + $SDT = Get-LMDeviceSDT -Id 123 + $SDT | Should -Not -BeNullOrEmpty + ($SDT | Measure-Object).Count | Should -BeGreaterThan 0 } } @@ -46,12 +46,12 @@ Describe 'SDT Testing' { It 'When given no parameters, returns all SDTs' { $SDT = Get-LMSDT $SDT | Should -Not -BeNullOrEmpty - $SDT.Count | Should -BeGreaterThan 0 + ($SDT | Measure-Object).Count | Should -BeGreaterThan 0 } It 'When given an id should return that SDT' { $SDT = Get-LMSDT -Id $Script:NewDeviceGroupSDT.Id $SDT | Should -Not -BeNullOrEmpty - $SDT.Count | Should -BeExactly 1 + ($SDT | Measure-Object).Count | Should -BeExactly 1 } It 'When given an invalid id, should empty response' { $SDT = Get-LMSDT -Id 0 From d20dbf47f5afcb1b994981e4abf8b7b60626c6ff Mon Sep 17 00:00:00 2001 From: Steve Villardi <42367049+stevevillardi@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:05:26 -0400 Subject: [PATCH 9/9] Update Connect-LMAccount.ps1 --- Public/Connect-LMAccount.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Public/Connect-LMAccount.ps1 b/Public/Connect-LMAccount.ps1 index c02fb2f..c94c482 100644 --- a/Public/Connect-LMAccount.ps1 +++ b/Public/Connect-LMAccount.ps1 @@ -92,10 +92,10 @@ Function Connect-LMAccount { } If(!$DisableConsoleLogging.IsPresent) { - $InformationPreference = 'Continue' + $InformationPreference = 'SilentlyContinue' } Else { - $InformationPreference = 'SilentlyContinue' + $InformationPreference = 'Continue' } If ($UseCachedCredential -or $CachedAccountName) {