Mail Fetching - Poll SQL database for failure

Mail Fetching - Poll SQL database for failure

Hi

Just wrote this and thought I would share in case any one else can use it.

Change the error log id to the max value then create a SQL job that runs every 5 minutes or so -

Now you will be emailed if the SDP fetching service goes down or gets an error.
  1. USE SERVICEDESK
  2. GO
  3. DECLARE @sub VARCHAR(100);
  4. DECLARE @qry VARCHAR(1000);
  5. DECLARE @msg VARCHAR(250);

  6. IF EXISTS(select * from errorlog where message like '%MAIL_FETCHING%' AND PROBABLECAUSE LIKE 'Fetching stopped due to an error% AND ERRORLOGID > "603016"')
  7. begin
  8. SELECT @sub = 'SERVICEDESK MAIL FAILURE - OPEN AND START FETCHING';
  9. SELECT @msg = 'SERVICEDESK MAIL FETCHING FAILURE'

  10. EXEC msdb.dbo.sp_send_dbmail
  11.      @profile_name = 'your_mail_profile',
  12.      @recipients = 'your_email_address',
  13.      @body = @msg,
  14.      @subject = @sub,
  15.      @query_result_header = 1,
  16.      @query_result_width = 256,
  17.      @query_result_separator = '   ',
  18.      @query_result_no_padding = 1;
  19. END

                  New to ADSelfService Plus?