Monitoring Alerts with Auto-Create and Auto-Close Tickets
This tutorial walks through building a workflow that handles "device offline" and "device online" alert emails from a monitoring tool. It automatically creates a ticket when a device goes offline and closes that same ticket when the device comes back online.
The pattern applies to any monitoring or alerting tool that can send email: Pingdom, Uptime Robot, PRTG, Auvik, custom scripts, or anything else that emails you on state changes.
What You Will Build
Two rules in a single dedicated mailbox:
| Rule | Expression | What it does |
|---|---|---|
| Close Existing Ticket (runs first) | Only fires when email indicates device is online | Finds the open alert ticket for the device and closes it |
| Create New Ticket (runs second) | Always fires (no expression) | Creates a new alert ticket for the device |
The rules are ordered so that the close rule runs first. If it fires and stops, the create rule never runs. If the close rule does not fire (because this is an offline alert, not an online alert), the create rule fires and creates a ticket.
Prerequisites
- An Email2AT account with Autotask connected
- Your monitoring tool configured to send alert emails to an Email2AT address
- Configuration Items (CIs) in Autotask for the devices being monitored, with a consistent identifier field you can match against (such as hostname, serial number, or reference title)
If you have not yet set up a mailbox, start with Create Your First Mailbox.
Step 1: Create a Dedicated Mailbox
Create a separate mailbox specifically for this monitoring tool. Do not use your general support mailbox.
- Navigate to Email2AT in the console and click Hosted Mailboxes
- Create a new mailbox, for example:
[email protected] - Click Save
The mailbox has no rules yet. Configure your monitoring tool to send its alert emails to this address before proceeding, or use test emails as described in the testing steps below.
Create a separate mailbox for each monitoring tool you integrate. This keeps History readable, simplifies troubleshooting, and means a misconfigured rule in one workflow cannot interfere with another.
Step 2: Understand Your Alert Emails
Before building rules, examine the actual emails your monitoring tool sends. The workflow depends on being able to extract a device identifier from the email, a value that is also stored on the Autotask CI for that device.
What to look for:
- Device identifier: a hostname, serial number, IP address, or other value that appears in every alert and is unique per device
- State indicator: something in the email (subject or body) that distinguishes an "offline" alert from an "online" alert
Example email pair (simplified):
Subject: Server ABC-123 status: offline
Body: Server: ABC-123
Status: offline
Subject: Server ABC-123 status: online
Body: Server: ABC-123
Status: online
From these, the device identifier is ABC-123 (the server name) and the state indicator is the word offline or online in the subject.
Step 3: Create the "Create New Ticket" Rule
Build the create rule first. It is simpler and you will clone it to build the close rule.
Add the rule
- In your new mailbox, click Add New Rule
- Name it
Create New Ticket - Leave the Expression empty. This rule should fire for every email. The close rule, added later, will be placed above it and stop processing for online alerts.
Action 1: Extract data from the email
Use the Extract Strings action to pull the device identifier and the alert state out of the email body in one step.
- Click Add New Action, select Extract Strings, click OK
- Name the step
Extract Alert Data - Add two definitions:
Definition 1: hostname
| Field | Value |
|---|---|
| Extraction Type | Regular Expression |
| Pattern | /Server:\s*([^\n]+)/ |
| Input | {{email.body}} |
| Variable | hostname |
| If Empty | Generate an exception and stop processing |
Definition 2: status
| Field | Value |
|---|---|
| Extraction Type | Regular Expression |
| Pattern | /Status:\s*([^\n]+)/ |
| Input | {{email.body}} |
| Variable | status |
| If Empty | Generate an exception and stop processing |
- In Store results in variable, enter
parsedAlert
After this step, {{custom.parsedAlert.hostname}} contains the device name (e.g., ABC-123) and {{custom.parsedAlert.status}} contains offline or online.
The patterns above match lines in the format Server: ABC-123 and Status: offline. If your monitoring tool uses different labels or formatting, adjust the patterns to match. You can use regex101.com (PCRE2 flavor) to test patterns against a sample email body, or contact support with a sample and we will help you build the right patterns.
You can also use Text Expression mode instead of regex for simple line-by-line extraction. For example, {{after_string email.body "Server:" flags="tn"}} extracts everything after Server: on the same line, with no regex required.
Action 2: Look up the Configuration Item in Autotask
- Click Add New Action, select API: Query for One Object, click OK
- Name the step
Find Config Item - Set Entity Type to
InstalledProduct(this is what Autotask calls Configuration Items in the API) - Add query conditions:
IsActiveequalstrue- The field you use to identify devices (e.g.,
ReferenceTitle) equals{{custom.parsedAlert.hostname}}
- Enable Generate an exception if no results. If no CI matches, you want to know about it.
- In Store results in variable, enter
configItem
After this step, {{custom.configItem.id}} is the CI's Autotask ID and {{custom.configItem.accountId}} is the account it belongs to.
The field you match against must contain the same value that appears in your alert emails. Common choices:
ReferenceTitleoften stores the device's hostname or display nameSerialNumberworks well for hardware identifiersReferenceNumberis a general-purpose identifier field
Check your existing CIs in Autotask to see which field holds the right value.
Alternatively, use the Create Autotask Ticket (by Configuration Item) workflow action, which handles the CI lookup and ticket creation in a single step.
Action 3: Create the alert ticket
- Click Add New Action, select API: Create an Object, click OK
- Name the step
Create Alert Ticket - Set Entity Type to
Ticket - Configure the required fields:
Ticket fields:
| Field | Value |
|---|---|
| AccountID | {{custom.configItem.accountId}} (unlock the field to enter this) |
| Status | New (or whichever status is appropriate for new alerts) |
| Priority | Set as appropriate for alert severity |
| QueueID | Your alert monitoring queue |
| Title | {{email.subject}} |
| Description | {{email.body}} |
| InstalledProductID | {{custom.configItem.id}} (unlock the field to enter this; links the ticket to the CI) |
- In Store results in variable, enter
newTicket. You will not need this value here, but it is available if you want to reference the ticket number in a subsequent step.
Add a consistent value somewhere on the ticket (in a note, a UDF, or the source field) that identifies it as being created by this workflow. You will use this when building the close rule to ensure you only locate tickets created by this specific alert. For example, set the Source field to a dedicated value like Ping Alert.
Action 4: Stop
- Click Add New Action, select Stop Processing This Message Completely, click OK
- Name it
Stop
Step 4: Create the "Close Existing Ticket" Rule
Now create the rule that handles online alerts. Clone the create rule if your UI supports it, or create a new rule from scratch.
Add the rule
- Click Add New Rule
- Name it
Close Existing Ticket - Set the Expression to fire only when the email indicates the device is back online
Example expression: email.body contains Status: online
This ensures the rule only fires for online alerts. For offline alerts, the expression is false and the rule is skipped entirely, allowing the Create rule to run.
Action 1: Extract alert data (same as create rule)
Add the same Extract Strings step as in the create rule:
- Extract Strings with the same definitions (hostname and status), same inputs (
{{email.body}}), and same variable name (parsedAlert)
Action 2: Look up the Configuration Item (same as create rule)
Add the same CI lookup step:
- API: Query for One Object with the same query conditions and same variable name (
configItem)
Action 3: Find the original open ticket
- Click Add New Action, select API: Query for One Object, click OK
- Name the step
Find Open Alert Ticket - Set Entity Type to
Ticket - Add query conditions:
InstalledProductIDequals{{custom.configItem.id}}Statusdoes not equalComplete(or whatever your closed status is)- Add any additional filter to ensure you only match tickets created by this alert workflow. For example, if you set Source to
Ping Alert, addSourceIDequals that source.
- Set Sort to
CreateDatedescending. This returns the most recently created matching ticket. - Leave Generate exception if no results unchecked. It is valid for an online alert to arrive when no open ticket exists (the device may have already been manually resolved).
- In Store results in variable, enter
existingTicket
Action 4: Add a note to the ticket
Only run this step if a ticket was actually found.
- Click Add New Action, select API: Create an Object, click OK
- Name the step
Add Resolved Note - Set Entity Type to
TicketNote - Add the Only perform this action if expression:
custom.existingTicket.idis not null - Configure fields:
| Field | Value |
|---|---|
| TicketID | {{custom.existingTicket.id}} (unlock the field) |
| Title | {{email.subject}} |
| Description | {{email.body}} |
| NoteType | Task Summary (or your preferred note type) |
| Publish | All Autotask Users |
Action 5: Close the ticket
- Click Add New Action, select API: Update an Object, click OK
- Name the step
Close Ticket - Set Entity Type to
Ticket - Add the Only perform this action if expression:
custom.existingTicket.idis not null - Configure fields. Only add the fields you want to change:
| Field | Value |
|---|---|
| ID | {{custom.existingTicket.id}} (unlock the field) |
| Status | Complete (or whichever status means resolved in your Autotask) |
In the Autotask UI, adding a note and changing the ticket status look like a single action. Under the hood, they are two separate API calls: one to create the TicketNote and one to update the Ticket. This is why the workflow has separate steps for each.
Action 6: Stop
- Click Add New Action, select Stop Processing This Message Completely, click OK
This stop fires regardless of whether a ticket was found. If no open ticket exists for this device, we still want to stop. There is nothing else to do with an online alert when no offline ticket was open.
Step 5: Order the Rules
The rule order in the mailbox determines which runs first. The Close rule must be above the Create rule.
In the mailbox's rule list:
- Drag Close Existing Ticket to the top
- Drag Create New Ticket below it
- Click Save Order
With this order:
- An online alert: Close rule expression matches → Close rule fires and stops → Create rule never runs
- An offline alert: Close rule expression does not match → Close rule is skipped → Create rule fires and creates a ticket
Step 6: Test
Test offline (ticket creation)
- Send a test email to your mailbox address that matches the offline pattern (e.g.,
Status: offlinein the body) - Navigate to History and click Refresh until it appears
- Open the details log and verify:
- The Close rule was skipped (expression did not match)
- The Create rule fired
- The regex extracted the correct hostname
- The CI was found in Autotask
- A new ticket was created with the correct Account and CI
Test online (ticket close)
- Open the ticket that was just created in Autotask and note the ticket number
- Send a second test email that matches the online pattern (e.g.,
Status: onlinein the body, same device hostname) - Navigate to History and click Refresh
- Open the details log and verify:
- The Close rule fired (expression matched)
- The regex extracted the correct hostname
- The CI was found
- The open ticket was located
- A note was added
- The ticket status was changed to Complete
If a step fails or produces unexpected output, fix the rule and click the Play button on the history entry to reprocess the same email. You do not need to send a new test email for each iteration.
Handling Edge Cases
Online alert arrives with no open ticket
This is expected and handled gracefully. The Find Open Alert Ticket step returns no result, custom.existingTicket.id is null, the note and close steps are skipped, and the Stop fires. Nothing bad happens.
Multiple open tickets for the same device
If a device generates rapid repeated offline alerts before you process the first online alert, you may accumulate multiple open tickets. The query uses Sort: CreateDate descending so it finds the most recent one. Consider enabling the ticket filter to only match the most recently created open ticket, or use a Source field to make matching more precise.
Device not in Autotask as a CI
If Find Config Item returns no result, the workflow exception fires and you receive an error notification. This is the right behavior: it tells you to add the CI to Autotask. Alternatively, remove the "generate exception if no results" flag and add a stop action that fires if custom.configItem.id is null, so the email is silently discarded for unknown devices.
Key Takeaways
- Dedicated mailbox per tool: keeps rules and history clean
- Close rule above Create rule: order determines which fires; the expression on the Close rule gates it
- Stop in every path: the Close rule stops whether or not a ticket was found, so the Create rule never runs for an online alert
- Extract before querying: use an Extract Strings step to pull the device identifier out of the email first, then use it in the CI query
- Guard update steps with an expression: add
custom.existingTicket.id is not nullto any step that uses the found ticket, so it gracefully skips when no ticket exists - Two API calls to add a note and close a ticket: Autotask requires separate calls; add a TicketNote first, then update the Ticket status
Related Documentation
- Core Concepts: the domain/mailbox/rule/action hierarchy
- Create Autotask Ticket (by Configuration Item): workflow action that handles CI lookup and ticket creation in one step
- API: Query for One Object: query Autotask for a single result
- API: Create an Object: create any Autotask entity
- API: Update an Object: update any Autotask entity
- Expression Builder: build rule and step expressions
- UniFi Online/Offline Emails with Autotask: a video walkthrough of the same pattern applied to UniFi devices
- PRTG Alerts with CI Association: the same pattern using the Create Autotask Ticket by CI workflow action