We have configured Alerts for the major severities and error codes on our SQL Server instances. Each alert then runs the same SQL Server Agent job, to trigger an alert in our monitoring system (for SMS messaging).
It would be useful to be able to retrieve the alert description text (see "This was just a test!" in the example below) from somewhere, to feed through to our monitoring system.
DATE/TIME: 27/09/2018 16:08:19
DESCRIPTION: Error: 50000 Severity: 20 State: 1 This was just a test!
COMMENT: (None)
JOB RUN: SystemAlerts
Is this text stored anywhere in the msdb database? Or is it not persisted like SQL Server Agent job history?
Best Answer
Tokens may be what you're looking for:
Using
$(ESCAPE_SQUOTE(A-MSG))
should allow you to access the description from an error message when the agent job is triggered by an alert.