Example Runbook: Monitor a folder with a runbook
This article shows you how to create a simple runbook that monitors a folder for new text files. When a file is detected, the runbook sends an event log message, and then starts another runbook.
Create and test a monitor runbook
The procedures to create, configure, and test a simple runbook that monitors a folder are described below.
Create the workflow
Follow these steps to create a workflow:
In the Runbook Designer Connections pane, right-click the Runbooks folder to select New, and then select Runbook.
Right-click the New Runbook tab to select Rename.
In the Confirm Check out dialog, select Yes.
Enter a name for the runbook, such as Monitor Runbook, and then press Enter.
In the Activities pane, select File Management to expand the category, and then drag the Monitor Folder activity into the Runbook Designer Design workspace.
In the Activities pane, select Notification to expand the category, and then drag the Send Event Log Message activity into the Runbook Designer Design workspace, to the right of the Monitor Folder activity.
In the Runbook Designer Design workspace, move your pointer over the right side of the Monitor Folder activity to display the smart link arrow.
Select the smart link arrow, and then drag it to the Send Event Log Message activity.
In the Activities pane, select Runbook Control to expand the category, and then drag the Invoke Runbook activity into the Runbook Designer Design workspace, to the right of the Send Event Log Message activity.
In the Runbook Designer Design workspace, move your pointer over the right side of the Send Event Log Message activity to display the smart link arrow.
Select the smart link arrow, and then drag it to the Invoke Runbook activity.
Configure the workflow
Follow these steps to configure the workflow:
In the Runbook Designer Design workspace, double-click the Monitor Folder activity.
In the Monitor Folder Properties dialog box, select the General tab.
In the Name box, change the name of the activity to something informative. For example, Monitor C:\Monitor Folder.
Select the Details tab.
On the Details tab, in the Path box, enter the path of the folder you want to monitor. For example, C:\Monitor.
Below the File Filters list, select Add.
In the Filter Settings dialog, set the following:
In the Name list box, select File Name.
In the Relation list box, select Matches pattern.
In the Value box, enter *.txt.
This setting directs the monitor to look for files with the txt extension. This field accepts regular expression syntax.
Select OK.
Select the Triggers tab.
Select the Number of files is option, set the value in the list to greater than, and then enter 0 in the edit box.
Select Finish.
In the Runbook Designer Design workspace, double-click the Send Event Log Message.
In the Send Event Log Message Properties dialog, on the Details tab, in the Properties section, set the following:
In the Computer box, enter the name of the computer to receive the Event message.
This is typically the computer where you're running Runbook Designer.
In the Message box, enter the message to display in the Event log. For example, File Detected.
Leave the Severity level at Information.
Select Finish.
Note
In this sample, the Invoke Runbook activity isn't configured.
Modify runbook settings
Follow these steps to modify the runbook settings:
Above the Runbook Designer Design workspace, right-click the Monitor Runbook tab to select Properties.
In the Monitor Runbook Properties dialog, select the Logging tab, and then select both Store Activity-specific Returned Data and Store Common Returned Data.
Select Finish.
Right-click the Monitor Runbook tab to select Check In.
Test the runbook
In the Runbook Tester, you can test runbooks in a simulated runtime and debugging environment. You can run an entire runbook, step through it one activity at a time, or add breakpoints to stop the simulation at any activity that you select.
Use the following steps to test your runbook in the Runbook Tester.
Prepare your computer
Follow these steps to prepare your computer:
Right-click Start to select Open Windows Explorer.
Create a C:\Monitor folder on your computer.
Create a C:\Source folder on your computer.
In the C:\Source folder, create a file with a txt extension. For example, text.txt.
Test the runbook
Follow these steps to test the runbook:
In the Runbook Designer Design workspace, select the Monitor Runbook tab.
On the toolbar above the Runbook Designer Design workspace, select Runbook Tester.
In the Confirm Check out dialog, select Yes.
In Runbook Tester, on the toolbar, select Step Over to start stepping through the runbook.
Tip
To increase the size of the Log pane, remove the Resource Browser pane by selecting View on the menu, and then clearing the Resource Browser option.
In Windows Explorer, browse to the C:\Source folder.
Copy test.txt to C:\Monitor.
Close Windows Explorer.
On the Runbook Tester toolbar, select Next.
After a few moments, the Log pane entry updates and shows an event for the Monitor Folder activity.
On the Log pane, select the Show Details link to see the contents of the data bus for that runbook.
Scroll down the list of properties. If the activity status is success, it indicates that the Monitor Folder activity detected the change in the folder.
On the Runbook Tester toolbar, select Next.
Notice that the Log pane changes and shows an event for the Send Event Log Message activity.
Select the Show Details link. If the activity status is success, it indicates that the Send Event Log Message activity detected the change in the folder.
Close Runbook Tester.
On the Runbook Designer toolbar, select Check In.
Next steps
- Read Design and build runbooks to learn more about building runbooks and get best practice guidance for designing runbooks.
- Read Control runbook activities to learn more about the options for controlling runbook execution.