Skip to content

Commit 4a8c128

Browse files
Merge pull request #22 from logicmonitor/main
rebase main
2 parents 57d93b7 + 12a1203 commit 4a8c128

Some content is hidden

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

61 files changed

+3245
-4395
lines changed

.github/workflows/test-win.yml

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

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

1012
workflow_dispatch:
1113

.github/workflows/test.yml

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

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

1012
workflow_dispatch:
1113

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Dev.Logic.Monitor.psd1
44
.DS_Store
55

66
/.vscode
7+
Public/Test-LMDeviceRateLimit.ps1

Documentation/Connect-LMAccount.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ Connect to a specified LM portal to run commands against
1414

1515
### LMv1 (Default)
1616
```
17-
Connect-LMAccount -AccessId <String> -AccessKey <String> -AccountName <String> [-AutoUpdateModuleVersion]
18-
[-DisableConsoleLogging] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
17+
Connect-LMAccount -AccessId <String> -AccessKey <String> -AccountName <String> [-DisableConsoleLogging]
18+
[-AutoUpdateModuleVersion] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
1919
[<CommonParameters>]
2020
```
2121

2222
### Bearer
2323
```
24-
Connect-LMAccount -BearerToken <String> -AccountName <String> [-AutoUpdateModuleVersion]
25-
[-DisableConsoleLogging] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
24+
Connect-LMAccount -BearerToken <String> -AccountName <String> [-DisableConsoleLogging]
25+
[-AutoUpdateModuleVersion] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
2626
[<CommonParameters>]
2727
```
2828

2929
### SessionSync
3030
```
31-
Connect-LMAccount -AccountName <String> [-SessionSync] [-AutoUpdateModuleVersion] [-DisableConsoleLogging]
31+
Connect-LMAccount -AccountName <String> [-SessionSync] [-DisableConsoleLogging] [-AutoUpdateModuleVersion]
3232
[-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>] [<CommonParameters>]
3333
```
3434

3535
### Cached
3636
```
37-
Connect-LMAccount [-UseCachedCredential] [-CachedAccountName <String>] [-AutoUpdateModuleVersion]
38-
[-DisableConsoleLogging] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
37+
Connect-LMAccount [-UseCachedCredential] [-CachedAccountName <String>] [-DisableConsoleLogging]
38+
[-AutoUpdateModuleVersion] [-SkipVersionCheck] [-SkipCredValidation] [-ProgressAction <ActionPreference>]
3939
[<CommonParameters>]
4040
```
4141

@@ -170,8 +170,10 @@ Accept pipeline input: False
170170
Accept wildcard characters: False
171171
```
172172
173-
### -AutoUpdateModuleVersion
174-
{{ Fill AutoUpdateModuleVersion Description }}
173+
### -DisableConsoleLogging
174+
Disables on stdout messages from displaying for any subsequent commands are run.
175+
Useful when building scripted logicmodules and you want to suppress unwanted output.
176+
Console logging is enabled by default.
175177
176178
```yaml
177179
Type: SwitchParameter
@@ -185,10 +187,8 @@ Accept pipeline input: False
185187
Accept wildcard characters: False
186188
```
187189
188-
### -DisableConsoleLogging
189-
Disables on stdout messages from displaying for any subsequent commands are run.
190-
Useful when building scripted logicmodules and you want to suppress unwanted output.
191-
Console logging is enabled by default.
190+
### -AutoUpdateModuleVersion
191+
{{ Fill AutoUpdateModuleVersion Description }}
192192
193193
```yaml
194194
Type: SwitchParameter

EXAMPLES.md

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

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

Logic.Monitor.Format.ps1xml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,53 @@
14671467
</TableRowEntries>
14681468
</TableControl>
14691469
</View>
1470+
<!-- New View LogicMonitor.Logsource-->
1471+
<View>
1472+
<Name>LogicMonitorLogsource</Name>
1473+
<ViewSelectedBy>
1474+
<TypeName>LogicMonitor.Logsource</TypeName>
1475+
</ViewSelectedBy>
1476+
<TableControl>
1477+
<TableHeaders>
1478+
<TableColumnHeader>
1479+
<Label>id</Label>
1480+
</TableColumnHeader>
1481+
<TableColumnHeader>
1482+
<Label>name</Label>
1483+
</TableColumnHeader>
1484+
<TableColumnHeader>
1485+
<Label>logFields</Label>
1486+
</TableColumnHeader>
1487+
<TableColumnHeader>
1488+
<Label>resourceMapping</Label>
1489+
</TableColumnHeader>
1490+
<TableColumnHeader>
1491+
<Label>description</Label>
1492+
</TableColumnHeader>
1493+
</TableHeaders>
1494+
<TableRowEntries>
1495+
<TableRowEntry>
1496+
<TableColumnItems>
1497+
<TableColumnItem>
1498+
<PropertyName>id</PropertyName>
1499+
</TableColumnItem>
1500+
<TableColumnItem>
1501+
<PropertyName>name</PropertyName>
1502+
</TableColumnItem>
1503+
<TableColumnItem>
1504+
<PropertyName>logFields</PropertyName>
1505+
</TableColumnItem>
1506+
<TableColumnItem>
1507+
<PropertyName>resourceMapping</PropertyName>
1508+
</TableColumnItem>
1509+
<TableColumnItem>
1510+
<PropertyName>description</PropertyName>
1511+
</TableColumnItem>
1512+
</TableColumnItems>
1513+
</TableRowEntry>
1514+
</TableRowEntries>
1515+
</TableControl>
1516+
</View>
14701517
<!-- New View LogicMonitor.Propertysource-->
14711518
<View>
14721519
<Name>LogicMonitorPropertysource</Name>
@@ -2162,6 +2209,59 @@
21622209
</TableRowEntries>
21632210
</TableControl>
21642211
</View>
2212+
<!-- New View LogicMonitor.EventSource-->
2213+
<View>
2214+
<Name>LogicMonitorEventSource</Name>
2215+
<ViewSelectedBy>
2216+
<TypeName>LogicMonitor.EventSource</TypeName>
2217+
</ViewSelectedBy>
2218+
<TableControl>
2219+
<TableHeaders>
2220+
<TableColumnHeader>
2221+
<Label>id</Label>
2222+
</TableColumnHeader>
2223+
<TableColumnHeader>
2224+
<Label>name</Label>
2225+
</TableColumnHeader>
2226+
<TableColumnHeader>
2227+
<Label>collector</Label>
2228+
</TableColumnHeader>
2229+
<TableColumnHeader>
2230+
<Label>schedule</Label>
2231+
</TableColumnHeader>
2232+
<TableColumnHeader>
2233+
<Label>appliesTo</Label>
2234+
</TableColumnHeader>
2235+
<TableColumnHeader>
2236+
<Label>description</Label>
2237+
</TableColumnHeader>
2238+
</TableHeaders>
2239+
<TableRowEntries>
2240+
<TableRowEntry>
2241+
<TableColumnItems>
2242+
<TableColumnItem>
2243+
<PropertyName>id</PropertyName>
2244+
</TableColumnItem>
2245+
<TableColumnItem>
2246+
<PropertyName>name</PropertyName>
2247+
</TableColumnItem>
2248+
<TableColumnItem>
2249+
<PropertyName>collector</PropertyName>
2250+
</TableColumnItem>
2251+
<TableColumnItem>
2252+
<PropertyName>schedule</PropertyName>
2253+
</TableColumnItem>
2254+
<TableColumnItem>
2255+
<PropertyName>appliesTo</PropertyName>
2256+
</TableColumnItem>
2257+
<TableColumnItem>
2258+
<PropertyName>description</PropertyName>
2259+
</TableColumnItem>
2260+
</TableColumnItems>
2261+
</TableRowEntry>
2262+
</TableRowEntries>
2263+
</TableControl>
2264+
</View>
21652265
<!-- New View LogicMonitor.RepositoryLogicModules-->
21662266
<View>
21672267
<Name>RepositoryLogicModules</Name>

Private/Format-LMFilter.ps1

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

Private/Resolve-LMException.ps1

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

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

Private/Test-LMSchedulaSchema.ps1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
function Test-LMScheduleSchema {
2+
[CmdletBinding()]
3+
param (
4+
[Parameter(Mandatory)]
5+
[PSCustomObject]$Schedule
6+
)
7+
8+
# Required properties
9+
$requiredProps = @('notify', 'type', 'recipients', 'cron', 'timezone')
10+
11+
# Valid schedule types
12+
$validTypes = @('manual', 'monthly', 'weekly', 'daily', 'hourly')
13+
14+
# Validate all required properties exist
15+
foreach ($prop in $requiredProps) {
16+
if (-not $Schedule.PSObject.Properties.Name.Contains($prop)) {
17+
throw "Schedule object is missing required property: $prop"
18+
}
19+
}
20+
21+
# Validate property types
22+
if ($Schedule.notify -isnot [bool]) {
23+
throw "notify must be a boolean value"
24+
}
25+
26+
if ($Schedule.type -isnot [string] -or $validTypes -notcontains $Schedule.type) {
27+
throw "type must be one of: $($validTypes -join ', ')"
28+
}
29+
30+
if ($Schedule.recipients -isnot [array]) {
31+
throw "recipients must be an array"
32+
}
33+
34+
if ($Schedule.cron -isnot [string]) {
35+
throw "cron must be a string"
36+
}
37+
38+
if ($Schedule.timezone -isnot [string]) {
39+
throw "timezone must be a string"
40+
}
41+
42+
# If recipients are provided, validate they are email addresses
43+
if ($Schedule.recipients.Count -gt 0) {
44+
$emailRegex = "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"
45+
foreach ($recipient in $Schedule.recipients) {
46+
if ($recipient -notmatch $emailRegex) {
47+
throw "Invalid email address format: $recipient"
48+
}
49+
}
50+
}
51+
52+
# Validate cron format based on type
53+
switch ($Schedule.type) {
54+
'monthly' { if ($Schedule.cron -notmatch '^\d{2}\s\d{2}\s\*\s\d{1,2}\s\d{1,2}$') { throw "Invalid monthly cron format" } }
55+
'weekly' { if ($Schedule.cron -notmatch '^\d{2}\s\d{2}\s\*\s\*\s\d{1}$') { throw "Invalid weekly cron format" } }
56+
'daily' { if ($Schedule.cron -notmatch '^\d{2}\s\d{2}\s\*\s\*\s\*$') { throw "Invalid daily cron format" } }
57+
'hourly' { if ($Schedule.cron -notmatch '^\d{2}\s\*\s\*\s\*\s\*$') { throw "Invalid hourly cron format" } }
58+
'manual' { if ($Schedule.cron -ne '') { throw "Cron should be empty for manual type" } }
59+
}
60+
61+
Write-Information "Supplied schedule, meets schema requirements."
62+
}

Private/Update-LogicMonitorModule.ps1

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

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

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

0 commit comments

Comments
 (0)