User configuration lost

Hello again Marcin,

I am running a POC on two production servers and noticed today that all of my updated configuration has been overwritten.

I had seen a previous post you’ve answered regarding explicitly updating the user_modified field on the sqlwatch_config_check table which I had incorporated into all my update statements but I noticed today these amendments had been overwritten and all my entries in the sqlwatch_config_check_action table were also removed.

I’ve checked the procedure usp_sqlwatch_internal_expand_checks and it has the code to ignore any entries where target.user_modified = 1.

Up until today everything seemed to be running OK, and I’ve been running this POC for several weeks,
install_date sqlwatch_version
2023-09-19 05:24:45.6983855 -04:00 4.8.0.548
2023-09-13 13:22:11.1927649 +01:00 4.8.0.548

What process calls usp_sqlwatch_internal_expand_checks and is there another process that might update sqlwatch_config_check and reset the user_modified field?

Thanks, Shaun

Hi Shaun,

I’m sorry to hear this. The only other process that could update the sqlwatch_config_check table is: usp_sqlwatch_config_add_check (https://github.com/marcingminski/sqlwatch/blob/1b3543c290f327a7a918aab8c60a8826ec371cba/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Procedures/usp_sqlwatch_config_add_check.sql#L28)
This is run by a SQL Server “Configuration/Meta” Job (Can’t recall the exact name). But, this job would usually run every 1 hour.

The only process that could update the sqlwatch_config_check_action table is usp_sqlwatch_internal_expand_checks

I’m happy to jump on a Zoom call to take a look at this with you.

Morning Marcin,

The SQL job is called SQLWATCH-[dbadmin]-INTERNAL-CONFIG which runs every hour and calls several procedures including dbo.usp_sqlwatch_internal_expand_checks.

I can’t see where the procedure usp_sqlwatch_config_add_check would be called from, there are no reported dependencies and a search doesn’t find any reference.
If I’m reading it correctly the procedures code checks for user_modified only for @check_ids < 0 which would be the default blocking check only, else it does the update.

The only other option is the hourly run of usp_sqlwatch_internal_expand_checks which does check the user_modified column but then doesn’t have code to remove the data from sqlwatch_config_check_action and all these entries had been deleted as well.

As it seems my amendments were replaced by the defaults (via template) I was wondering if I should update the sqlwatch_config_check_template table with all the modifications I want?

My other thought is that I’m using our own database dbadmin when installing SQLWatch on these remote servers, not the default SQLWatch.

Thanks, Shaun

P.S.
Thank you for your offer of a zoom call but I don’t want to take up too much of your time, I know this is a free community offering.

I really need to document this better because I am forgetting how this was coded :slight_smile:

If you want your check to “expanded” by a list (databases, tables, etc) then you should add it to the template. If you just want a single check, you can add it straight to the config table. It rins a bell however, that there is a “switch” to tell whether checks should be kept in sync with the template or left alone. Let me do some digging.

It’s fine to use your own database btw, you shouldn’t have problems with that.

Thanks again Marcin,

I’ve updated the template table and will monitor.

Cheers, Shaun

My updates have been cleared again. This must be something I do in setting up the servers, some misunderstanding on my part.

Can I just run through the update scripts I run?

Firstly, I amend the checks I require:

UPDATE [dbo].[sqlwatch_config_check] SET [check_frequency_minutes] = 60, user_modified = 1 
WHERE check_description like 'The "Free Space %" value is lower than expected.%'

Because of this issue, I also update the check template table so that when I experience one of these resets, at least the check values will be correct, but I’ve found the user_modified setting doesn’t get set back on the sqlwatch_config_check table:

UPDATE [dbo].[sqlwatch_config_check_template] SET [check_frequency_minutes] = 60, user_modified = 1 
WHERE check_description like 'The "Free Space %" value is lower than expected.%'

Then for each required check I insert the required actions:

--check\action association
declare @check_id bigint, @check_name nvarchar(255)
SELECT @check_id = min( check_id ) FROM [dbo].[sqlwatch_config_check] where check_description like  'The "Free Space %" value is lower than expected.%'
WHILE @check_id IS NOT NULL
BEGIN
SELECT check_id, @check_name FROM [dbo].[sqlwatch_config_check] WHERE check_id = @check_id
INSERT INTO [dbo].[sqlwatch_config_check_action]
		   ([check_id]
		   ,[action_id]
		   ,[action_every_failure]
		   ,[action_recovery]
		   ,[action_repeat_period_minutes]
		   ,[action_hourly_limit]
		   ,[action_template_id]
		   ,[date_created]
		   ,[date_updated])
	 VALUES
		   (@check_id
		   ,-4 	-- this is action_id of the run disk utilisation report (action_report_id -4) 
		   ,1 	-- action will happen on check failure
		   ,0 	-- don't run a recovery email when disk above 10%
		   ,60 	-- mins before next action alert (nag)
		   ,1 	-- number of nags per hour
		   ,-2 	-- this is the default action template to use for email reports
		   ,getdate()
		   ,getdate())

SELECT @check_id = min( check_id ) FROM [dbo].[sqlwatch_config_check] WHERE check_id > @check_id AND check_description like  'The "Free Space %" value is lower than expected.%'
END;

This all seems to work for a while but at some point the sqlwatch_config_check table is reset and the sqlwatch_config_check_action is cleared leaving only the default blocked process report (check__id -2) so I no longer get any alerts.

Other people are seemingly using SQLWatch so I’m assuming I’m doing something fundementally wrong when I set the servers up.

Thanks in advance for any help you can give on this.

Shaun

Hi, I’m happy to jump on Zoom/Teams with you to sort it. It may be quicker than through this as I’m not sure what’s going on. We can then update this thread with a solution for others.

That would be great, let me know the details.

Thanks, Shaun

Apologies I thought I had responded to this.
Just someone else posted a similar problem which a solution, does this help?

Im having quite the difficult time with configuring alerts to send out via email.

My test case is just taking a test database offline, and having the check send an email at some frequency per hour.

Ive tested the sqlwatch_config_action:

exec msdb.dbo.sp_send_dbmail @recipients = '[email protected]',
@subject = '{SUBJECT}',
@body = '{BODY}',
@profile_name='SQLWatch'

and that works as a test.

Next Ive set the check_name "Database TEST State) so that user_modified is 1, frequency is 5 minutes. The check_threshold_critical is >0

next I set the sqlwatch_config_check_action to:

waited for 5 minutes many times and nothing. The sqlwatch_logger_check keeps reporting this check_id as OK but the database is definitely offline?

any ideas as to what Im missing here?