Skip to content

Commit 12a1203

Browse files
committed
6.5 pre release
1 parent e4daa0c commit 12a1203

File tree

8 files changed

+108
-15
lines changed

8 files changed

+108
-15
lines changed

.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

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+
}

Public/Connect-LMAccount.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Function Connect-LMAccount {
240240
Valid = $true
241241
Type = $Type
242242
}
243-
243+
244244
#Check for newer version of Logic.Monitor module
245245
Try {
246246
If ($AutoUpdateModuleVersion -and !$SkipVersionCheck) {

Public/Copy-LMDashboard.ps1

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ The name of the dashboard to be copied. This parameter is mandatory when using t
1717
.PARAMETER Description
1818
An optional description for the new dashboard.
1919
20+
.PARAMETER DashboardTokens
21+
A hashtable of tokens to be replaced in the dashboard. The key is the token name and the value is the new value. If not provided, the tokens from the source dashboard will be used.
22+
2023
.PARAMETER ParentGroupId
2124
The ID of the parent group for the new dashboard. This parameter is mandatory when using the 'GroupId-Id' or 'GroupId-Name' parameter sets.
2225
@@ -31,6 +34,10 @@ Copies the dashboard with ID 12345 to a new dashboard named "New Dashboard" in t
3134
Copy-LMDashboard -Name "New Dashboard" -DashboardName "Old Dashboard" -ParentGroupName "Group A"
3235
Copies the dashboard named "Old Dashboard" to a new dashboard named "New Dashboard" in the group named "Group A".
3336
37+
.EXAMPLE
38+
Copy-LMDashboard -Name "New Dashboard" -DashboardName "Old Dashboard" -ParentGroupName "Group A" -DashboardTokens @{ "defaultResourceName" = "Value1"; "defaultResourceGroup" = "Value2" }
39+
Copies the dashboard named "Old Dashboard" to a new dashboard named "New Dashboard" in the group named "Group A", replacing the tokens "defaultResourceName" with "Value1" and "defaultResourceGroup" with "Value2".
40+
3441
.NOTES
3542
Ensure that you are logged in before running any commands by using the Connect-LMAccount cmdlet.
3643
#>
@@ -51,6 +58,8 @@ Function Copy-LMDashboard {
5158

5259
[String]$Description,
5360

61+
[Hashtable]$DashboardTokens,
62+
5463
[Parameter(Mandatory, ParameterSetName = 'GroupId-Id')]
5564
[Parameter(Mandatory, ParameterSetName = 'GroupId-Name')]
5665
[Int]$ParentGroupId,
@@ -86,6 +95,24 @@ Function Copy-LMDashboard {
8695

8796
#Get existing dashboard config
8897
$SourceDashboard = Get-LMDashboard -Id $DashboardId
98+
99+
#Replace tokens
100+
If ($DashboardTokens) {
101+
$WidgetTokens = New-Object -TypeName System.Collections.ArrayList
102+
103+
#Build widget tokens
104+
$DashboardTokens.GetEnumerator() | ForEach-Object {
105+
$WidgetTokens.Add( [PSCustomObject]@{
106+
type = "owned"
107+
name = $_.Key
108+
value = $_.Value
109+
inheritList = @()
110+
}
111+
) | Out-Null
112+
}
113+
#Replace widget tokens
114+
$SourceDashboard.widgetTokens = $WidgetTokens
115+
}
89116

90117
#Build header and uri
91118
$ResourcePath = "/dashboard/dashboards/$DashboardId/clone"
@@ -101,7 +128,7 @@ Function Copy-LMDashboard {
101128
sharable = $SourceDashboard.sharable
102129
}
103130

104-
$Data = ($Data | ConvertTo-Json)
131+
$Data = ($Data | ConvertTo-Json -Depth 10)
105132

106133
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "POST" -ResourcePath $ResourcePath -Data $Data
107134
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath

Public/Copy-LMReport.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ The description of the report.
1919
The ID of the parent group.
2020
2121
.PARAMETER ReportObject
22-
The report object to be copied.
22+
The report object to be copied. This can be retrieved using Get-LMReport. Any changes to the report object will be reflected in the new report.
2323
2424
.EXAMPLE
2525
Copy-LMReport -Name "Report1" -Description "This is a sample report" -ParentGroupId "12345" -ReportObject $reportObject
26-
2726
This example copies the report specified by the ReportObject parameter and sets the name, description, and parent group ID.
2827
2928
.NOTES

Public/Get-LMDevice.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ Function Get-LMDevice {
117117
$Headers = New-LMHeader -Auth $Script:LMAuth -Method "GET" -ResourcePath $ResourcePath
118118
$Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath + $QueryParams
119119

120-
121-
122120
Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation
123121

124122
#Issue request

Public/New-LMNetscan.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Function New-LMNetScan {
7474

7575
[String]$NetScanGroupId = "1",
7676

77+
[PSCustomObject]$Schedule,
78+
7779
[Parameter(Mandatory)]
7880
[String]$SubnetRange,
7981

@@ -123,12 +125,16 @@ Function New-LMNetScan {
123125
value = "21,22,23,25,53,69,80,81,110,123,135,143,389,443,445,631,993,1433,1521,3306,3389,5432,5672,6081,7199,8000,8080,8081,9100,10000,11211,27017"
124126
}
125127

126-
$Schedule = @{
127-
cron = ""
128-
notify = $false
129-
recipients = @()
130-
timezone = "America/New_York"
131-
type = "manual"
128+
If(!$Schedule){
129+
$Schedule = @{
130+
cron = ""
131+
notify = $false
132+
recipients = @()
133+
timezone = "America/New_York"
134+
type = "manual"
135+
}
136+
} Else {
137+
Test-LMScheduleSchema -Schedule $Schedule
132138
}
133139

134140
Try {

Public/Set-LMNetScan.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Function Set-LMNetscan {
3030

3131
[String]$CredentialGroupName,
3232

33+
[PSCustomObject]$Schedule,
34+
3335
[String]$ChangeNameToken,
3436

3537
[String]$PortList
@@ -86,8 +88,6 @@ Function Set-LMNetscan {
8688
}
8789
}
8890

89-
$Schedule = $null
90-
9191
Try {
9292
$Data = @{
9393
id = $Id
@@ -104,7 +104,7 @@ Function Set-LMNetscan {
104104
ddr = $DDR
105105
credentials = $Creds
106106
ports = $Ports
107-
schedule = $Schedule
107+
schedule = If($Schedule){$Schedule}Else{$null}
108108
}
109109

110110

0 commit comments

Comments
 (0)