Skip to content

Commit

Permalink
Merge pull request #197 from erikdarlingdata/dev
Browse files Browse the repository at this point in the history
I'm going through changes
  • Loading branch information
erikdarlingdata authored Nov 29, 2022
2 parents c18643f + 4eb160e commit 6d0ed0a
Show file tree
Hide file tree
Showing 34 changed files with 7,562 additions and 5,843 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

*.sqlite
*.suo
*.vsidx
*.lock
8 changes: 8 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ExpandedNodes": [
"",
"\\sp_HumanEvents"
],
"SelectedNode": "\\sp_HumanEvents\\sp_HumanEventsBlockViewer.sql",
"PreviewInSolutionExplorer": false
}
86 changes: 43 additions & 43 deletions Alerts/Alerts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Copyright 2022 Darling Data, LLC
https://www.erikdarlingdata.com/
For support, head over to GitHub:
https://github.com/erikdarlingdata/DarlingData
https://github.com/erikdarlingdata/DarlingData
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
Expand All @@ -50,7 +50,7 @@ DECLARE @operator_name sysname = 'Who You Want To Notify';

RETURN;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Severity 019',
@message_id=0,
@severity=19,
Expand All @@ -59,12 +59,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 019',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 019',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Severity 020',
@message_id=0,
@severity=20,
Expand All @@ -73,12 +73,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 020',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 020',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Severity 021',
@message_id=0,
@severity=21,
Expand All @@ -87,12 +87,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 021',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 021',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Severity 022',
@message_id=0,
@severity=22,
Expand All @@ -101,12 +101,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 022',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 022',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Severity 023',
@message_id=0,
@severity=23,
Expand All @@ -115,12 +115,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 023',
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 023',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Severity 024',
@message_id=0,
@severity=24,
Expand All @@ -129,12 +129,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 024',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 024',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Severity 025',
@message_id=0,
@severity=25,
Expand All @@ -143,12 +143,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 025',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Severity 025',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Error Number 823',
@message_id=823,
@severity=0,
Expand All @@ -157,26 +157,26 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Error Number 823',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Error Number 823',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Error Number 824',
@message_id=824,
@severity=0,
@enabled=1,
@delay_between_responses=60,
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Error Number 824',
@operator_name=@operator_name,

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Error Number 824',
@operator_name=@operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXEC msdb.dbo.sp_add_alert
@name=N'Error Number 825',
@message_id=825,
@severity=0,
Expand All @@ -185,7 +185,7 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in=1,
@job_id=N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
@alert_name=N'Error Number 825',
@operator_name=@operator_name,
EXEC msdb.dbo.sp_add_notification
@alert_name=N'Error Number 825',
@operator_name=@operator_name,
@notification_method = 7;
126 changes: 63 additions & 63 deletions ClearTokenPerm/ClearTokenPerm Agent Job.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,115 +3,115 @@ GO

BEGIN TRANSACTION;

DECLARE
DECLARE
@ReturnCode int = 0,
@jobId binary(16),
@active_start_date int = (SELECT CONVERT(int, CONVERT(varchar(35), GETDATE(), 112)));

IF NOT EXISTS
IF NOT EXISTS
(
SELECT
1/0
FROM msdb.dbo.syscategories
WHERE name = N'[Uncategorized (Local)]'
SELECT
1/0
FROM msdb.dbo.syscategories
WHERE name = N'[Uncategorized (Local)]'
AND category_class = 1
)
BEGIN

EXEC @ReturnCode = msdb.dbo.sp_add_category
@class = N'JOB',
@type = N'LOCAL',
EXEC @ReturnCode = msdb.dbo.sp_add_category
@class = N'JOB',
@type = N'LOCAL',
@name = N'[Uncategorized (Local)]';
IF (@@ERROR <> 0 OR @ReturnCode <> 0)

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

END;


EXEC @ReturnCode = msdb.dbo.sp_add_job
@job_name = N'Clear Security Cache Every 30 Minutes',
@enabled = 1,
@notify_level_eventlog = 0,
@notify_level_email = 0,
@notify_level_netsend = 0,
@notify_level_page = 0,
@delete_level = 0,
EXEC @ReturnCode = msdb.dbo.sp_add_job
@job_name = N'Clear Security Cache Every 30 Minutes',
@enabled = 1,
@notify_level_eventlog = 0,
@notify_level_email = 0,
@notify_level_netsend = 0,
@notify_level_page = 0,
@delete_level = 0,
@description = N'For background on why you need this:
https://www.erikdarlingdata.com/troubleshooting-security-cache-issues-userstore_tokenperm-and-tokenandpermuserstore/
Copyright 2022 Darling Data, LLC
https://www.erikdarlingdata.com/
For support, head over to GitHub:
https://github.com/erikdarlingdata/DarlingData',
@category_name = N'[Uncategorized (Local)]',
@owner_login_name = N'sa',
https://github.com/erikdarlingdata/DarlingData',
@category_name = N'[Uncategorized (Local)]',
@owner_login_name = N'sa',
@job_id = @jobId OUTPUT;

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_add_jobstep
@job_id = @jobId,
@step_name = N'Execute dbo.ClearTokenPerm',
@step_id = 1,
@cmdexec_success_code = 0,
@on_success_action = 1,
@on_success_step_id = 0,
@on_fail_action = 2,
@on_fail_step_id = 0,
@retry_attempts = 0,
@retry_interval = 0,
@os_run_priority = 0,
@subsystem = N'TSQL',
@command = N'EXEC dbo.ClearTokenPerm
@CacheSizeGB = 1;',
@database_name = N'master',
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep
@job_id = @jobId,
@step_name = N'Execute dbo.ClearTokenPerm',
@step_id = 1,
@cmdexec_success_code = 0,
@on_success_action = 1,
@on_success_step_id = 0,
@on_fail_action = 2,
@on_fail_step_id = 0,
@retry_attempts = 0,
@retry_interval = 0,
@os_run_priority = 0,
@subsystem = N'TSQL',
@command = N'EXEC dbo.ClearTokenPerm
@CacheSizeGB = 1;',
@database_name = N'master',
@flags = 0;

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_update_job
@job_id = @jobId,
EXEC @ReturnCode = msdb.dbo.sp_update_job
@job_id = @jobId,
@start_step_id = 1;

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule
@job_id = @jobId,
@name = N'Clear Security Cache Every 30 Minutes',
@enabled = 1,
@freq_type = 4,
@freq_interval = 1,
@freq_subday_type = 8,
@freq_subday_interval = 30,
@freq_relative_interval = 0,
@freq_recurrence_factor = 0,
@active_start_date = @active_start_date,
@active_end_date = 99991231,
@active_start_time = 0,
@active_end_time = 235959,
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule
@job_id = @jobId,
@name = N'Clear Security Cache Every 30 Minutes',
@enabled = 1,
@freq_type = 4,
@freq_interval = 1,
@freq_subday_type = 8,
@freq_subday_interval = 30,
@freq_relative_interval = 0,
@freq_recurrence_factor = 0,
@active_start_date = @active_start_date,
@active_end_date = 99991231,
@active_start_time = 0,
@active_end_time = 235959,
@schedule_uid = N'b9dca576-7d86-4120-8f04-b666139677d6';

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_add_jobserver
@job_id =
@jobId,
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver
@job_id =
@jobId,
@server_name = N'(local)';

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

COMMIT TRANSACTION;
GOTO EndSave;

QuitWithRollback:
IF (@@TRANCOUNT > 0)
IF (@@TRANCOUNT > 0)
ROLLBACK TRANSACTION;

EndSave:
Expand Down
Loading

0 comments on commit 6d0ed0a

Please sign in to comment.