You can trigger alerts and actions in Uptime Infrastructure Monitor when an Element changes state. This is discussed in the UIM Administrator's Guide under Alerts and Actions. The following actions are available out of the box:
- Log to File
- Recovery Script
- Windows Service
- SNMP trap
The Windows service action can start, stop, or restart a Windows service identified by name. This is useful when you've created a service monitor using the Windows Service Check monitor to watch for a state change with a specific Windows service. A typical scenario is to set a Critical status if a specified Windows service is stopped. In this case, you can use the Windows service action in UIM to automatically try to start the Windows service in an attempt to minimize service disruption.
The limitation to leveraging the Windows service action on an action profile is that the Windows service that you want to start must be identified by name. If you have a large number of Windows services that could drive an action, you should create a new action profile for each Windows service, and then make sure that you tie it to the correct service monitor. In environments where the number of Windows services that fit this scenario is small, this works well. However, in larger environments where the number of Windows services that fit this scenario is large, it might be desirable to create a single action profile that can restart any Windows service.
This article explores how to restart any Windows service with an action profile as an alternative to creating a specific action profile for each Windows service.
Create a service monitor
To create a service monitor
- Select the Windows Service Check monitor.
You must match the Service Name to the Windows Service Display Name. This name is leveraged later to select the Windows service to start. Note that Microsoft has both a Display Name and a Service Name. We want the Display Name, as shown in the following images.
- Complete the remainder of the Service Monitor window making sure that the Windows Service - Service Name is also the Display Name.
- Make sure to select options that allow you to raise a Critical alert when the service status is Stopped. Your service monitor settings should look the following example.
Create a recovery script
We are going to leverage a Recovery Script in an Action Profile to Start the Windows Service. This will be a very simple script. We are going to leverage two key components built into Uptime Infrastructure Monitor:
First, the ability to create a script on the Uptime Infrastructure Monitor Monitoring Station that directs a UIM Agent to perform an action. In fact, the Uptime Infrastructure Monitor Agent exposes a method to the UIM Monitoring Station to Start a Window Service – we simply have to supply the Windows Service name.
Second, the use of Recovery Script Variables (variables available when creating Recovery Scripts). These are variables handed into our script by Uptime Infrastructure Monitor.
Here is what the Recovery Script looks like:
@ECHO OFF
agentcmd.exe -s -p 9998 %UPTIME_HOSTNAME% svc_start \"%UPTIME_SERVICENAME%\" Changeme2
Some items to note:
%UPTIME_HOSTNAME% is the name of the system raising the Alert, also the system where the Windows Service will be restarted.
%UPTIME_SERVICENAME% is the name of the Service Monitor we created earlier. Note that this is why we needed the Service Monitor name to match the Windows Service Display Name.
The \" may look strange, this ensures the whole Windows Service name gets included regardless of spaces.
Changeme2 is the Uptime Infrastructure Monitor Agent Password in this environment, your environment will differ.
This script is saved to the Scripts directory on the Uptime Infrastructure Monitor Monitoring Station (default: C:\Program Files\uptime software\uptime\scripts).
For the sake of brevity we will skip the remaining details. However, if you want more information you can find it online, here are two key articles: Creating an Action Profile Recovery Script (for the purposes of this article focus on the Monitoring Station Script).
Alert Profile and Action Profile Variables (for the purposes of this article focus on the Recovery Script Variables):
Create an action profile
Lastly, we need to tie the Service Monitor and Recovery Script together in an Action Profile. Follow these steps:
Create a new Action Profile and name it appropriately (no specific name is required).
Populate the full path to the recovery script.
Add the Service Monitor we created above.
It should look something like this:
Testing
The final test is to make sure that everything works as expected. Testing is as simple as stopping the Windows Service from your Service Monitor. You may want to adjust the Timing Settings on the Service Monitor to trigger the action sooner for the purposes of testing.
If you are familiar with Action Profiles you may know that Uptime Infrastructure Monitor has a built in Test Action Profile capability. However, that won't work in our case because the variables we are leveraging only get populated when a Service Monitor is triggered.
Important notes
The Windows Service will be started in the security context of the Uptime Infrastructure Monitor agent running on the system where the Windows Service is being started (by default Local System).
This is only one way to accomplish this task, other viable options exist. You could create an Uptime Infrastructure Monitor Agent side script to perform the recovery, you could call a third party tool from the recovery script to start the service, etc, etc.