🧡 Skip to main content🔍 Skip to search
Thomas UnderwoodBy Thomas Underwood 🕦 Updated on June 18, 2021 at 11:30 am
YouTube video · Ping server regularly

Suppose that we have a remote server machine that always needs to be up and running. In case the connection fails, system administrators need to know that as soon as possible. This tutorial shows how to configure Automation Workshop to monitor the connection to a remote machine.

Solution

Use the Task Scheduler to periodically execute the Task which pings the server machine and, in case it is not responding, gathers different data and notifies the administrator either by sending an email or playing an audible warning by using the Play Audio File Action.

Task overview…

Let us see the necessary steps to design such a Task.

  • 1 · The Task Scheduler Trigger is added and configured to execute the Task every 20 seconds (that will be the period of ping operations).
  • 2 · The Run CMD Command Action is added and configured to run the ping command to verify whether the remote server is accessible. If the ping command cannot connect to the remote server, the Action ends with an error and tells the Task to skip Step 3 and proceed immediately with Step 4. Otherwise, it just continues with Step 3 at which the Task is stopped.
  • 3 · The Stop Task Action is configured to stop the very Task within which it is located. However, this Action will be performed only when the ping command performed by the Run CMD Command Action in Step 2 manages to successfully reach the server.
  • 4 · Reaching this step implies the failure of the ping command to reach the destination server in Step 2. Thus, from here on, Automation Workshop starts gathering additional data on connectivity problems and tries to deliver the notification on the initial ping failure to the system administrator. Let us add the Run CMD Command Action to ping the domain name server (DNS) to check whether it is possible to resolve the IP address of the server.
  • 5 · The Run CMD Command Action performs a ping operation to check router & gateway connectivity.
  • 6 · Another Run CMD Command Action performs the tracert command to get info on mediating servers.
  • 7 · In Step 7, we use the Run CMD Command to make sure if the SMTP server for the email error report is accessible. If the ping to the SMTP server fails, the Action will skip Step 8 which uses the SMTP server for sending an email and go directly to Step 10 (using On Error settings).
  • 8 · The Send Email Action is added and configured using the Variable Wizard to send data gathered by pings to the domain name server (DNS) and gateway, as well as the tracert command.
  • 9 · If the SMTP server has been reached successfully in Step 7, the Task stops here using the Stop Task Action.
  • 10 · This step is executed only if pinging the SMTP server has failed in Step 7. Since it is not possible to send an email report when the SMTP server is not reachable, we can still try to notify the administrator with an audible alarm. We will configure the Play Audio File Action to play the alarm.

Deploy the Task…

Let us see in detail how to create the Task and configure every Action according to the aforementioned design.

How to create a new Task? First, let us create a Task file. Creating a Task is easy. Open the Automation Workshop Manager and select New Task from the File or context menu.

Create a new automated Task
Automation Workshop · Create a new automated Task

Alternatively, you can use the CTRL+N keyboard shortcut or select New Task in the context menu by pushing the right mouse button in the Task Pane. Whichever you choose, it will open the Task Wizard which will lead us through the rest of the configuration process.

Task Wizard · Welcome
Task Wizard · Welcome

Task Scheduler

How to add the Task Scheduler trigger? After reading the info on the Welcome tab in the Task Wizard, click Next to get to the Triggers tab.

Task Wizard Triggers
Task Wizard · Triggers

Click the Add button to open the window with all available Triggers. Select Task Scheduler from the list and click OK to open its properties. After configuring the Trigger, it will automatically be added to the Task.

Add Trigger: Task Scheduler
Add a Task Scheduler

Configure scheduler…

How to configure the Task Scheduler trigger for periodic Task execution? When added, the Task Scheduler properties are opened on the Scheduler tab which contains the most relevant parameters.

By default, the Task Scheduler is set to execute daily. Since we need to ping the remote server much more often, let us change the schedule type from daily to seconds. Set the recurrence interval to 20 seconds and the configuration is done. Click OK to save the settings.

Task Scheduler · recur every 20 seconds
Task Scheduler · recur every 20 seconds

If a more advanced schedule is necessary, it is always possible to disable scheduling on particular days, weekdays, months, or even time of the day. It is also possible to specify the end date of the schedule as well as multiple other options which we leave at their defaults in this particular case · Advanced Task Scheduler explained

Actions?

How to add Actions to the Task? After returning to the Triggers tab of the Task Wizard, click Next to go to the Actions tab. Click the Add button to open the Add Action window that contains a list of all available Actions divided into broader categories. Select an Action and click OK to open its properties.

Add Action · Run CMD Command
Add Action · Run CMD Command

When finishing configuring an Action, click OK and it will be added to the Actions list in Task Wizard. We will need to do this over and over again to add multiple Actions to our Task. Let us see how to configure all necessary Actions one by one.

Ping server

Ping the remote server. In order to verify whether the server is online, we will use the ping command included in Microsoft Windows. We will need to use the Run CMD Command Action which can execute external commands from the command line.

So, let us add the Run CMD Command Action and configure it to ping the remote server. Write ping -n 1 www.example.com into the Command line input in the Command tab of the Run CMD Command Action properties.

Command line: ping -n 1 www.example.com
ping -n 1 www.example.com

The parameter -n 1 means that only one data packet per command execution will be sent to ensure server connectivity. You will have to substitute www.example.com with the actual server URL or IP address. If the connection is somewhat unstable, you might want to increase the number of data packets sent each time, for example, -n 5.

The ping command returns an error level 0 if the round-trip of at least one data packet is successful. If no data packet is returned or on any other error, the ping command returns an error level 1.

Now, when the ping command is set, we must configure alternative endings of the Task. If the ping command has successfully reached the server, there is nothing more to be done and the Task has to finish. In case of failure, though, the Task must proceed with gathering more data and reporting the situation to the system administrator.

However, before telling the Action with what other Actions to continue in case of successful or failed pinging of the server, we have to create those very Actions in the first place and return to configuring this Action afterward. Click OK to return to the Action tab of the Task Wizard.

Stop the Task

Stop the Task upon successfully reaching the server. Let us first configure the Action which is to be performed if pinging the server has been successful.

In case the server has responded to the ping, the Task has performed its function and can be stopped. Let us add the Stop Task Action. The default option to stop the very Task in which the Action is located, namely, this Task is what we actually need.

Stop Task · this Task
Stop this Task

Since this is also a planned stopping and not some error, there is no need to mark Warning and Error checkboxes. Click OK to return to Task Wizard.

Troubleshooting?

Set the default folder for troubleshooting data. Now, let us configure Actions that will gather some data in case the ping command fails to reach the server. Since the external commands like ping and tracert will output returned data into text files, we need to specify a folder in which these files will be created.

While it is possible to specify that folder using a command line parameter for each command, it might be easier to just specify one folder as the default for them all. Add the Change Current Folder Action and choose a folder which will be considered as the default for all subsequent Actions. In this example, we will use the C:\PING\ folder.

Change Current Folder · C:\PING
Change current folder to C:\PING

Once set, click OK to return to the Task Wizard. Note that the C:\PING\ folder has to be created before running the Task. The good idea is to create it right at this point.

Ping DNS…

Ping the domain name server (DNS). Once the default working folder has been specified, we can start with gathering various data from other machines possibly involved in the inability of Automation Workshop to reach the remote server.

If the DNS server is not reachable, the domain names are not resolved, causing the inability to reach the remote server machine. Let us ping the domain name server (DNS) to verify whether the domain name of the server (host name) can be resolved into an IP address (and hence is not the cause of connectivity problems).

Add the Run CMD Command Action and configure it to ping the domain name server (for example, 8.8.8.8). Additionally, we need to save the pinging result into a text file to add it later to the email report. Thus, we have to use the redirection operator bigger than > character and a file name to make the ping command use a file as its output instead of the screen.
Enter ping 8.8.8.8 >dns.txt into the Command line input.

Command line: ping 8.8.8.8 >dns.txt
ping 8.8.8.8 >dns.txt

Ping router…

Ping the gateway & router. Another possible problem may lie in the gateway. Let us add the Run CMD Command Action and configure it exactly as in the previous step. Except that the IP address has to be substituted with that of your gateway.
Enter ping 192.168.1.1 >gateway.txt into the Command line input.

Command line: ping 192.168.1.1 >gateway.txt
ping 192.168.1.1 >gateway.txt

Trace route…

Perform a trace route to the remote server. Finally, let us perform the tracert command to verify whether some intermediate machine is not the cause of the inability of Automation Workshop to reach the server. Add the Run CMD Command Action.
Enter tracert www.example.com >traceroute.txt into the Command line input.

Command line: tracert www.example.com >traceroute.txt
tracert www.example.com >traceroute.txt

After setting up these three Run CMD Command Actions to ping the domain name server (DNS) and gateway, as well as trace route to the remote server, we have configured the basis for gathering the necessary data into text files.

Now we have to finalize the choice between two distinct scenarios, that of successfully stopping the Task, and that of continuing with data gathering upon initial ping failure.

Task Wizard · 6 Actions · Run; Stop; Change; Run; Run; Run
Task Wizard with 6 Actions

Choices

Choice between ending the Task and continuing with error procedures. Before going further with configuring the error reporting, let us now return to the very first Action which pinged the remote server to verify the connection. Double-click the first Action in the list to edit its properties.

The difference between configuring the Action for the first time and now is that we have added more Actions since then. The Task design implies that if the ping procedure finishes normally, the Task is automatically stopped by the Stop Task Action which we added as second.

However, if the ping procedure fails to reach the remote server, we need to skip the Stop Task Action and continue the Task with other Actions to gather additional data.

CMD command: Treat error levels greater than 0 as error
Treat error levels greater than 0 as error

Let us first go to the Advanced tab. A successful ping will return an error level 0 as an indication of its success. All other error level values that exceed 0 are treated as warnings by default. We need to change the settings to treat error levels greater than 0 as an error. The difference between warnings and errors is that warnings are merely reported in the Automation Workshop logs, while errors allow the user to specify additional Task management procedures in the On Error tab.

Go to the On Error tab, by enabling the Advanced fallback options checkbox. To avoid the situation that random packet loss triggers the Task execution, let us enable the option to Retry this Action 3 more times. We can set up email reports directly here. However, we will deal with that later. Instead, we need to tell the Action that in case of an error, it should continue with the Change Current Folder Action.

Continue with: Change Current Folder: C:\PING
Continue with Change Current Folder: C:\PING

Let us recall that the Change Current Folder Action is the one which starts the data gathering procedures in case of a ping failure. Click Ok to return to the Task Wizard.

Verify SMTP

Verify whether the SMTP server is reachable. Now, when all Actions responsible for gathering the necessary data are configured, let us think about how to deliver the server connectivity failure report to the system administrator. We will ping the SMTP server first, to verify whether it will be possible to send the email report.

Due to possible DNS server inaccessibility (which is not explicitly verified in this tutorial), the numeric SMTP server address should be used. For example, let us assume that the IP address of the SMTP is 192.168.1.44. Add the Run CMD Command Action.
Enter ping -n 1 192.168.1.44 into the Command line input.

Command line: ping -n 1 192.168.1.44
ping -n 1 192.168.1.44

Since the outcome of this ping will decide whether the Task will send an email report or play audible alarm, now we need to create those other Actions first, before finishing this one. Click OK to save the Action and return to Task Wizard.

Email reports

Send an email report to the system administrator. Assuming that pinging the SMTP server has finished successfully, the Task will send an email to the administrator's email containing the data related to the inability to connect to the remote server. Let us add the Send Email Action first. Let us add the From and To address first and write something relevant into the Subject field.

To format the Email text, we will use the contents of three files created by three Actions, namely, dns.txt, gateway.txt, and traceroute.txt that will be created in the C:\PING\ folder upon the first ping failure. Let us write a title for each file (e.g., PING DNS, PING GATEWAY, and TRACERT SERVER) in the Email text field.

Variable Wizard · Use file content · Local or network file: C:\PING\dns.txt
Use file content: C:\PING\dns.txt

After each title, let us add the respective text file. Click on the Variable Wizard button, choose the File category, select the use file content variable, and enter C:\PING\dns.txt into the Local or Network file input field. Since the dns.txt file does not exist prior to Task execution, we will have to enter the file name manually (instead of using the Browse button).

Send email · DNS, gateway, tracert
Send email · DNS, gateway, tracert

Let us put the cursor after the next title PING GATEWAY and repeat the previous step, but enter C:\PING\gateway.txt this time. And once again, under the TRACERT SERVER title, do the same with the C:\PING\traceroute.txt file.

Stop the Task

Stop the Task if the email is sent successfully. If we want the Task either to send an email or play an alarm, we need to add the Stop Task Action at this point. It will prevent Automation Workshop from playing the alarm. Let us add the Stop Task Action and set it to stop this very Task. Click OK to return to the Task Wizard.

Stop Task · this Task
Stop this Task

Alarm?

Play an audible alarm upon error. Now, let us add the Play Audio File Action. Specify the audio file to be played. Assuming that an audio file is already prepared, titled alarm.wav and located in C:\Sounds\, let us browse to the C:\Sounds\alarm.wav file. Note that the Windows volume has to be set appropriately to ensure the audibility of the alarm.

Play audio file · C:\Sounds\alarm.wav
Play C:\Sounds\alarm.wav audio file

Report?

Choice between sending an email report and playing an audible alarm. Now, when all Actions have been configured, let us just finalize the setup of the automated choice between an email report and an audible alarm.

Task Wizard · 10 Actions · Run; Stop; Change; Run; Run; Run; Run; Send; Stop; Play
Task Wizard with 10 Actions

Open the Run CMD Command Action (6th in the list) which pings the SMTP server. Go to the Options tab and set to Treat error levels greater than 0 as error. As a consequence, every SMTP server ping failure will produce an error.

CMD command: Treat error levels greater than 0 as error
Treat error levels greater than 0 as error

Let us now use this error to choose between sending an email and playing an alarm. Go to the On Error tab. Since in case of an error (failure to ping the SMTP server) we need to play an audible alarm instead of stopping the Task, let us change the Stop Task option to Continue with and choose the Start App Action which we've configured to play the alarm.wav file.

Continue with: Play Audio File: C:\Sounds\alarm.wav
Continue with audio file

When ping to SMTP server is successful, the Action will complete successfully and the next Action will send an email error report using just pinged SMTP server and the Task will stop right afterward. On the other hand, if pinging SMTP server fails, the Task will perform the On Error procedure and continue with the Play Audio File Action.

Finalize

Finalizing the Task. After finishing with configuring the choice in the Action that pings the SMTP server, click OK to return to the Task Wizard. Click Next to proceed to the Run As settings, then to the Reports tab. Remove the checkbox from Send email upon successful completion since, probably, we do not need to receive an email every time the ping is successful.

Give the Task a name and description in the Task tab and click Next to go to the Finish section. Due to the complexity of the Task, let us click the Advanced button to open its properties.

Let us start with the Settings tab. The tracert command used in one Action can take quite a long time to finish. Which in turn can lead to multiple simultaneously running instances of the same Task. Let us choose not to start the new instance of the task if an instance of an already running (or queued) task is being executed.

Also, we can choose to stop an already running instance of the Task if it runs longer than, say, 1 hour, which is already way too long for performing the specified Actions.

Ping test · Do not start the new task
Do not start the new task

Second, due to the frequent and periodic execution of the Task, we might want the execution data from this Task not to clutter the whole log file which may also contain more valuable data from other processes.

Let us go to the Log tab and choose the Disable log for this Task option. If, after disabling logging into the main log file, we still want to gather some data, let us check Additionally create separate log file and specify the alternative log file path and name as well as the logging level.

Ping test · Disable log for this Task
Disable log for this Task

Third, let us visit the On Error tab of the Send Email Action. Since in the case of an email failure we want to hear the alarm (even if the email sending process itself is attempted), we have to change the Stop Task option to Continue with Play Audio File Action which we've configured to play the alarm.wav file.

Send email · On error · Continue with: Play audio file · C:\Sounds\alarm.wav
On error play C:\Sounds\alarm.wav audio file

This way, the alarm will be played not only when the Send Email Action is skipped, but also when it fails.

Finally, if necessary, we can also revisit all Run CMD Command Actions, and change the CMD window startup state to Hidden (in the Advanced tab).

CMD window startup state: Hidden
CMD window startup state: Hidden

It will make the CMD window (where the ping and tracert commands are executed) invisible during execution.

Conclusion

We have created a Task that pings the remote server and, depending on the ping outcome, it either stops or performs one of two possible error procedures. We have used On Error settings in conjunction with the Stop Task Action to differentiate between a successful ping execution and a failure. The sequence of Task creation has been non-sequential, and we had to return to finalize some Actions after creating farther ones.

Seamless automation in action! 90 seconds to efficiency.

Need assistance?

If you have any questions, please do not hesitate to contact our support team.