Skip to content

Commit

Permalink
Alert Config - Allow NULL Blackout Period Start/End Date
Browse files Browse the repository at this point in the history
Allow blackout period start/end dates to be NULL.  This makes it easier to configure recurring blackout periods.
#1186
  • Loading branch information
DavidWiseman committed Jan 28, 2025
1 parent aa44d02 commit 8baf11c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions DBADashDB/Alert/Functions/IsBlackoutPeriod.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ SELECT CASE WHEN EXISTS(
FROM Alert.BlackoutPeriod BP
OUTER APPLY(SELECT SYSDATETIMEOFFSET() AT TIME ZONE TimeZone AS CurrentTime) AS TZ
WHERE BP.ApplyToInstanceID = -1
AND BP.StartDate < SYSUTCDATETIME()
AND BP.EndDate > SYSUTCDATETIME()
AND (BP.StartDate < SYSUTCDATETIME() OR BP.StartDate IS NULL)
AND (BP.EndDate > SYSUTCDATETIME() OR BP.EndDate IS NULL)
AND @AlertKey LIKE BP.AlertKey
AND CHOOSE(DATEPART(dw,TZ.CurrentTime),BP.Monday,BP.Tuesday,BP.Wednesday,BP.Thursday,BP.Friday,BP.Saturday,BP.Sunday) = CAST(1 AS BIT)
AND (CAST(TZ.CurrentTime AS TIME) >= BP.TimeFrom OR BP.TimeFrom IS NULL)
Expand Down Expand Up @@ -47,8 +47,8 @@ SELECT CASE WHEN EXISTS(
OUTER APPLY(SELECT SYSDATETIMEOFFSET() AT TIME ZONE TimeZone AS CurrentTime) AS TZ
WHERE BP.ApplyToInstanceID = @InstanceID
AND BP.ApplyToTagID = -1
AND BP.StartDate < SYSUTCDATETIME()
AND BP.EndDate > SYSUTCDATETIME()
AND (BP.StartDate < SYSUTCDATETIME() OR BP.StartDate IS NULL)
AND (BP.EndDate > SYSUTCDATETIME() OR BP.EndDate IS NULL)
AND @AlertKey LIKE BP.AlertKey
AND CHOOSE(DATEPART(dw,TZ.CurrentTime),BP.Monday,BP.Tuesday,BP.Wednesday,BP.Thursday,BP.Friday,BP.Saturday,BP.Sunday) = CAST(1 AS BIT)
AND (CAST(TZ.CurrentTime AS TIME) >= BP.TimeFrom OR BP.TimeFrom IS NULL)
Expand Down
2 changes: 1 addition & 1 deletion DBADashDB/Alert/Procedures/Config_Get.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SELECT BP.BlackoutPeriodID,
' and ',CONVERT(CHAR(5),ISNULL(BP.TimeTo,'00:00'),114),' (' + BP.TimeZone + ')',
IIF(DATEDIFF(d,GETUTCDATE(),BP.EndDate)>365,'',', (Ends in ' + HDEndsIn.HumanDuration + ')')
)
ELSE 'Active' + IIF(DATEDIFF(d,GETUTCDATE(),BP.EndDate)>365,'',' (Ends in ' + HDEndsIn.HumanDuration + ')') END AS CurrentStatus,
ELSE 'Active' + IIF(DATEDIFF(d,GETUTCDATE(),BP.EndDate)>365 OR BP.EndDate IS NULL,'',' (Ends in ' + HDEndsIn.HumanDuration + ')') END AS CurrentStatus,
HDStartsIn.HumanDuration AS StartsIn,
HDEndsIn.HumanDuration AS EndsIn,
BP.Notes
Expand Down
4 changes: 2 additions & 2 deletions DBADashDB/Alert/Tables/BackoutPeriod.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
BlackoutPeriodID INT IDENTITY(1,1) CONSTRAINT PK_BlackoutPeriod PRIMARY KEY,
ApplyToTagID INT NOT NULL CONSTRAINT DF_Alert_BlackoutPeriod_ApplyToTagID DEFAULT(-1),
ApplyToInstanceID INT NULL CONSTRAINT DF_Alert_BlackoutPeriod_ApplyToInstanceID DEFAULT(-1),
StartDate DATETIME2 NOT NULL,
EndDate DATETIME2 NOT NULL CONSTRAINT CK_Alert_BlackoutPeriod_EndDate CHECK(EndDate>StartDate),
StartDate DATETIME2 NULL,
EndDate DATETIME2 NULL CONSTRAINT CK_Alert_BlackoutPeriod_EndDate CHECK(EndDate>StartDate),
AlertKey NVARCHAR(128) NOT NULL CONSTRAINT DF_Alert_BlackoutPeriod_AlertKey DEFAULT('%'),
TimeFrom TIME NULL,
TimeTo TIME NULL,
Expand Down
4 changes: 2 additions & 2 deletions DBADashGUI/DBADashAlerts/AlertConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ private async void BlackoutGrid_CellContentClick(object sender, DataGridViewCell
ApplyToInstance = (string)row.Cells["ConnectionID"].Value.DBNullToNull(),
ApplyToInstanceID = (int)row.Cells["ApplyToInstanceID"].Value,
ApplyToTag = DBADashTag.GetTag(Common.ConnectionString, (int)row.Cells["ApplyToTagID"].Value),
StartDate = (DateTime)row.Cells["StartDate"].Value,
EndDate = (DateTime)row.Cells["EndDate"].Value,
StartDate = (DateTime?)row.Cells["StartDate"].Value.DBNullToNull(),
EndDate = (DateTime?)row.Cells["EndDate"].Value.DBNullToNull(),
BlackoutPeriodID = (int)row.Cells["BlackoutPeriodId"].Value,
TimeZone = ScheduleBase.TimeZoneFromString((string)row.Cells["TimeZone"].Value),
Monday = (bool)row.Cells["Monday"].Value,
Expand Down
20 changes: 10 additions & 10 deletions DBADashGUI/DBADashAlerts/BlackoutPeriod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ public string ApplyToInstance
public string AlertKey { get; set; } = "%";

[Category("Effective Period")]
[DisplayName("1. Start Date")]
public DateTime StartDate { get; set; }
[DisplayName("1. Start Date"),Description("Option to start blackout period at a future date/time. To start now, set to current date or leave blank.")]
public DateTime? StartDate { get; set; }

[Category("Effective Period")]
[DisplayName("2. End Date")]
public DateTime EndDate { get; set; }
[DisplayName("2. End Date"), Description("Date/Time the blackout period should end. For recurring blackouts, leave blank or set to a date in the distant future.")]
public DateTime? EndDate { get; set; }

[Description("Add notes. Markdown is supported")]
[Editor(typeof(MarkdownEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string Notes { get; set; }

public void AdjustDatesToUtc()
{
StartDate = StartDate.AppTimeZoneToUtc();
EndDate = EndDate.AppTimeZoneToUtc();
StartDate = StartDate?.AppTimeZoneToUtc();
EndDate = EndDate?.AppTimeZoneToUtc();
}

public void AdjustDatesToAppTimeZone()
{
StartDate = StartDate.ToAppTimeZone();
EndDate = EndDate.ToAppTimeZone();
StartDate = StartDate?.ToAppTimeZone();
EndDate = EndDate?.ToAppTimeZone();
}

public async Task Save()
Expand All @@ -99,8 +99,8 @@ public async Task Save()
cmd.Parameters.AddWithValue("ApplyToInstanceID", ApplyToInstanceID);
cmd.Parameters.AddWithValue("ApplyToTagID", ApplyToTag.TagID);
cmd.Parameters.AddWithValue("AlertKey", string.IsNullOrEmpty(AlertKey) ? "%" : AlertKey);
cmd.Parameters.AddWithValue("StartDate", StartDate);
cmd.Parameters.AddWithValue("EndDate", EndDate);
cmd.Parameters.AddWithValue("StartDate", StartDate.HasValue ? StartDate : DBNull.Value);
cmd.Parameters.AddWithValue("EndDate", EndDate.HasValue ? EndDate : DBNull.Value);
cmd.Parameters.AddWithValue("Monday", Monday);
cmd.Parameters.AddWithValue("Tuesday", Tuesday);
cmd.Parameters.AddWithValue("Wednesday", Wednesday);
Expand Down

0 comments on commit 8baf11c

Please sign in to comment.