Tutorial - Launching an Email Task Based on a File Monitor

Introduction

In this exercise, we will monitor a machine for a specific file. When the file appears, we will send an email that uses variables to supply information about when and how the email was sent.

In order to set this up, we need the following:

  • Universal Agent
  • File Monitor task
  • File Monitor trigger
  • Email task being launched by the trigger.
     


Prerequisites:

  • In order to perform this exercise, you need a Windows, Linux/Unix, or z/OS Agent running on the machine that is being monitored for the file. Create a directory on the machine called controller tutorial. Later on, you will copy a text file to this directory to satisfy the File Monitor trigger.
     

    Note

    If you do not have a running Agent, you can bypass this step by manually satisfying the trigger, as per instructions in the tutorial. However, you do need an Agent defined in the database.

  • Since we are going to generate an email when the trigger is satisfied, you will need an Email Connection defined.

Create File Monitor Task

The File Monitor task monitors the agent machine for the specified file.

Step 1

From the Automation Center navigation pane, select Tasks > File Monitors. The File Monitors list displays.

Step 2

Click the New button to display an empty File Monitor Details.

Step 3

In the Task Name field, enter stonebranch-filemonitor-01.

Step 4

In the Task Description field, enter Demo File Monitor.

Step 5

In the Agent field, select an Agent.

Step 6

In the Monitor Type field, keep the default value, Create. (See File Monitor Task Details Field Descriptions for details about the other file monitor options.)

Step 7

In the Monitor File field, type file1.txt. Since we have not specified any directory, the Controller will search the root directory.

Step 8

Enable the Recursive field. Since we are going to write our file to the controller tutorial directory, we want the Controller to search all sub-directories for the file.

Step 9

In the Stable (seconds) field, enter 5. This tells the Controller to satisfy the trigger only when the file has not changed in 5 seconds.
 

Step 10

Click Save.

Create an Email Task

Create the task that will run when the File Monitor is satisfied. In this case, we will generate an email, using the Email task:

Step 1

From the Automation Center navigation pane, select Tasks > Email Tasks. The Email Tasks list displays.

Step 2

Click the New button to display an empty Email task Details.

Step 3

In the Task Name field, enter stonebranch-emailtask-01.

Step 4

In the Description field, enter Send Email When File Appears.

Step 5

In the Email Connection field, select your Email Connection.

Step 6

In the To field, enter your email address. This is where the email will be sent.

Step 7

In the Subject field, enter file1.txt arrived.

Step 8

In the body field, enter the following Universal Controller variable and Universal Controller function:
 

Step 9

When the email is generated, the variables will be substituted with the name of the trigger that launched the Email task, along with the date and time the task was launched.
 

Step 9

Click the Save button.

Create File Monitor Trigger

Create the File Monitor trigger:

Step 1

From the Automation Center* navigation pane, select Triggers > File Triggers. The File Monitor Triggers list displays.

Step 2

Click the New button to display an empty File Monitor Trigger Details.

Step 3

In the Trigger Name field, enter stonebranch-filemonitortrigger-01.

Step 4

In the Description field, enter When File Arrives Send Email.

Step 5

In the Task(s) field, select stonebranch-emailtask-01.)

Step 6

In the File Monitor field, select stonebranch-filemonitor-01.

Step 7

Click the Save button.
 

Test Your File Monitor Set-up

Test your File Monitor set-up.

Step 1

Enable the File Monitor trigger. This launches the File Monitor task. It will appear in the Activity Monitor with a status of Running.

Step 2

Do one of the following:

  • If you have a running agent, place a text file called file1.txt in the controller tutorial directory on the machine that is being monitored by the File Monitor task. When the file appears, the File Monitor task waits five seconds, as specified, and then satisfies the trigger.
  • If you do not have a running agent but do have an agent connected to your instance, you can manually satisfy the trigger as follows:
    1. From the Automation Center navigation pane, select Triggers > File Triggers to display the File Monitor Triggers list.
    2. Right-click the stonebranch-file monitortrigger-01 trigger and select Trigger Now.

Step 3

When the trigger is satisfied, the Email is sent. Go to the Activity Monitor and note that the astonebranch-emailtask-01 Email task has been launched.

Step 4

Go to your email account where the email was sent and open the email. Note that the variables were resolved.


For additional information, see: