I'm looking to monitor various events that may occur within a SQL Server Maintenance Plan. My desired method for doing this is to have the maintenance plan do an HTTP POST with the data. After some research I think my preferred approach is to use cURL but I understand this requires enabling xp_cmdshell which is not ideal from a security standpoint.
So, I'm trying to put together a bit of T-SQL that will check if xp_cmdshell is enabled and if not enable it long enough to run the command and then disable it again. However, what I have below is not cooperating and I'm pretty sure it has something to do with all those GO's...
DECLARE @cmdstatus INT
SET @cmdstatus = (SELECT CONVERT(INT, ISNULL(value, value_in_use)) AS config_value FROM sys.configurations WHERE name = N'xp_cmdshell')
IF @cmdstatus = 1
EXEC xp_cmdshell 'curl --user user:password --data "task=test&status=success" https://www.example.ca/index.php';
GO
IF @cmdstatus = 0
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'xp_cmdshell', 1;
GO
RECONFIGURE;
GO
EXEC xp_cmdshell 'curl --user user:password --data "task=test&status=success" https://www.example.ca/index.php';
GO
EXEC sp_configure 'xp_cmdshell', 0;
GO
RECONFIGURE;
GO
EXEC sp_configure 'show advanced options', 0;
GO
RECONFIGURE;
GO
Thanks for any help.