Skip to content

Commit

Permalink
Merge pull request #22 from logicmonitor/main
Browse files Browse the repository at this point in the history
rebase main
  • Loading branch information
stevevillardi authored Dec 12, 2024
2 parents 57d93b7 + 12a1203 commit 4a8c128
Show file tree
Hide file tree
Showing 61 changed files with 3,245 additions and 4,395 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: Test Current Build on Windows Powershell 5.1

on:
push:
branches: [ main ]
branches:
- '**'
paths-ignore:
- '**.md'
- '**.yml'
- '**.xml'

workflow_dispatch:

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: Test Current Build on PowerShell Core

on:
push:
branches: [ main ]
branches:
- '**'
paths-ignore:
- '**.md'
- '**.yml'
- '**.xml'

workflow_dispatch:

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Dev.Logic.Monitor.psd1
.DS_Store

/.vscode
Public/Test-LMDeviceRateLimit.ps1
26 changes: 13 additions & 13 deletions Documentation/Connect-LMAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ Connect to a specified LM portal to run commands against

### LMv1 (Default)
```
Connect-LMAccount -AccessId <String> -AccessKey <String> -AccountName <String> [-AutoUpdateModuleVersion]
[-DisableConsoleLogging] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
Connect-LMAccount -AccessId <String> -AccessKey <String> -AccountName <String> [-DisableConsoleLogging]
[-AutoUpdateModuleVersion] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
```

### Bearer
```
Connect-LMAccount -BearerToken <String> -AccountName <String> [-AutoUpdateModuleVersion]
[-DisableConsoleLogging] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
Connect-LMAccount -BearerToken <String> -AccountName <String> [-DisableConsoleLogging]
[-AutoUpdateModuleVersion] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
```

### SessionSync
```
Connect-LMAccount -AccountName <String> [-SessionSync] [-AutoUpdateModuleVersion] [-DisableConsoleLogging]
Connect-LMAccount -AccountName <String> [-SessionSync] [-DisableConsoleLogging] [-AutoUpdateModuleVersion]
[-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### Cached
```
Connect-LMAccount [-UseCachedCredential] [-CachedAccountName <String>] [-AutoUpdateModuleVersion]
[-DisableConsoleLogging] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
Connect-LMAccount [-UseCachedCredential] [-CachedAccountName <String>] [-DisableConsoleLogging]
[-AutoUpdateModuleVersion] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
```

Expand Down Expand Up @@ -170,8 +170,10 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -AutoUpdateModuleVersion
{{ Fill AutoUpdateModuleVersion Description }}
### -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.
```yaml
Type: SwitchParameter
Expand All @@ -185,10 +187,8 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -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.
### -AutoUpdateModuleVersion
{{ Fill AutoUpdateModuleVersion Description }}
```yaml
Type: SwitchParameter
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
100 changes: 100 additions & 0 deletions Logic.Monitor.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,53 @@
</TableRowEntries>
</TableControl>
</View>
<!-- New View LogicMonitor.Logsource-->
<View>
<Name>LogicMonitorLogsource</Name>
<ViewSelectedBy>
<TypeName>LogicMonitor.Logsource</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>id</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>logFields</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>resourceMapping</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>description</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>logFields</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>resourceMapping</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>description</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<!-- New View LogicMonitor.Propertysource-->
<View>
<Name>LogicMonitorPropertysource</Name>
Expand Down Expand Up @@ -2162,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
62 changes: 62 additions & 0 deletions Private/Test-LMSchedulaSchema.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function Test-LMScheduleSchema {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[PSCustomObject]$Schedule
)

# Required properties
$requiredProps = @('notify', 'type', 'recipients', 'cron', 'timezone')

# Valid schedule types
$validTypes = @('manual', 'monthly', 'weekly', 'daily', 'hourly')

# Validate all required properties exist
foreach ($prop in $requiredProps) {
if (-not $Schedule.PSObject.Properties.Name.Contains($prop)) {
throw "Schedule object is missing required property: $prop"
}
}

# Validate property types
if ($Schedule.notify -isnot [bool]) {
throw "notify must be a boolean value"
}

if ($Schedule.type -isnot [string] -or $validTypes -notcontains $Schedule.type) {
throw "type must be one of: $($validTypes -join ', ')"
}

if ($Schedule.recipients -isnot [array]) {
throw "recipients must be an array"
}

if ($Schedule.cron -isnot [string]) {
throw "cron must be a string"
}

if ($Schedule.timezone -isnot [string]) {
throw "timezone must be a string"
}

# If recipients are provided, validate they are email addresses
if ($Schedule.recipients.Count -gt 0) {
$emailRegex = "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"
foreach ($recipient in $Schedule.recipients) {
if ($recipient -notmatch $emailRegex) {
throw "Invalid email address format: $recipient"
}
}
}

# Validate cron format based on type
switch ($Schedule.type) {
'monthly' { if ($Schedule.cron -notmatch '^\d{2}\s\d{2}\s\*\s\d{1,2}\s\d{1,2}$') { throw "Invalid monthly cron format" } }
'weekly' { if ($Schedule.cron -notmatch '^\d{2}\s\d{2}\s\*\s\*\s\d{1}$') { throw "Invalid weekly cron format" } }
'daily' { if ($Schedule.cron -notmatch '^\d{2}\s\d{2}\s\*\s\*\s\*$') { throw "Invalid daily cron format" } }
'hourly' { if ($Schedule.cron -notmatch '^\d{2}\s\*\s\*\s\*\s\*$') { throw "Invalid hourly cron format" } }
'manual' { if ($Schedule.cron -ne '') { throw "Cron should be empty for manual type" } }
}

Write-Information "Supplied schedule, meets schema requirements."
}
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."
}
}
}
Loading

0 comments on commit 4a8c128

Please sign in to comment.