Skip to content

Commit 8d78e01

Browse files
Merge fix/loghunter-custom-only-and-canary-dates into dev
2 parents 85cc60e + f594e12 commit 8d78e01

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

sp_LogHunter/sp_LogHunter.sql

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,21 @@ BEGIN
241241
@custom_message_only = 0;
242242
END;
243243

244+
/*
245+
@custom_message_only = 1 means "skip the canned search strings and
246+
look only for the user-supplied @custom_message". Without a message
247+
to search for, every insert branch below would skip (the custom
248+
insert is gated on @custom_message LIKE N'_%', which is NULL/false
249+
for NULL or empty input), leaving #search empty and the whole
250+
outer loop a no-op. Reject the combination up front.
251+
*/
252+
IF @custom_message_only = 1
253+
AND (@custom_message IS NULL OR LEN(@custom_message) = 0)
254+
BEGIN
255+
RAISERROR(N'@custom_message_only = 1 requires a non-empty @custom_message. Provide a search string or set @custom_message_only = 0.', 11, 1) WITH NOWAIT;
256+
RETURN;
257+
END;
258+
244259
/*Fix @end_date*/
245260
IF @start_date IS NOT NULL
246261
AND @end_date IS NULL
@@ -412,8 +427,24 @@ BEGIN
412427
CROSS JOIN
413428
(
414429
SELECT
430+
/*
431+
Canary floor is normally "at least 90 days back" so these
432+
server-identity strings are found regardless of how recent
433+
the caller is interested in. When the caller supplied
434+
@start_date/@end_date, @days_back is NULL at this point —
435+
the previous CASE collapsed to NULL, produced a NULL
436+
days_back literal, and xp_readerrorlog received NULL as a
437+
date argument and errored. Fall back to @start_date in
438+
date-range mode so the canary has a concrete floor.
439+
*/
415440
days_back =
416-
N'"' + CONVERT(nvarchar(10), DATEADD(DAY, CASE WHEN @days_back > -90 THEN -90 ELSE @days_back END, SYSDATETIME()), 112) + N'"',
441+
N'"' +
442+
CASE
443+
WHEN @days_back IS NOT NULL
444+
THEN CONVERT(nvarchar(10), DATEADD(DAY, CASE WHEN @days_back > -90 THEN -90 ELSE @days_back END, SYSDATETIME()), 112)
445+
ELSE CONVERT(nvarchar(10), @start_date, 112)
446+
END +
447+
N'"',
417448
start_date =
418449
N'"' + CONVERT(nvarchar(30), @start_date) + N'"',
419450
end_date =

0 commit comments

Comments
 (0)