Zabbix: restart a Windows service

In this tutorial, I will explain how to restart a Windows service where Zabbix agent is installed. If you followed the tutorial: Zabbix – Restart a service on Ubuntu – Linux, it’s almost identical.

To illustrate this tutorial, we will try to restart the Winlogbeat service.

As you can see, on several servers the Winlogbeat service is stopped and it happens regularly. To avoid manual actions in the future, we will make Zabbix agent restart the service when it is stopped.

We will start by creating a “script” indicating the PowerShell command that will allow the service to be restarted.

From the Zabbix web interface, expand the Administrations 1 part then click on Scripts 2. On this page which displays the list of scripts, click on the button Create a script 3 which is at the top left.

Name the script 1, enter the command that will allow restarting 2: powershell Start-Service NameOfService and click on Add 3.

The script is added to Zabbix.

We must now create the action that will execute the script, this is where we will select the item’s trigger and tell it the script to execute.

From the menu in the Configuration section 1, go to Action 2 and click on Trigger Actions 3.

Click on the Create an action 1 button.

Name the action 1 then click on Add 2 in the conditions part.

For the configuration of the trigger, there are several ways to proceed, either select each existing trigger, which can be long, or use an expression, which we will do.

In Type, select Trigger name 1, Operator choose contains and in the value enter for example the name of the service 3 (here Winlogbeat) and finish by clicking on Add 4.

Once the condition 1 has been added, click on Operation 2.

Click on Add 1 in the Operation part.

Select the previously created script in the Operation field 1, in the list of targets, check Current host 2 so that the script is executed on the server where the trigger was activated, then click on Add < <3.

Once the Operation has been added, click on the Add 1 button.

We have finished for the Zabbix level part, now we need to configure Zabbix agents so that they are allowed to run scripts.

What we are going to do now, must be done on all servers where you want the action to be performed.

Il faut éditer le fichier zabbix_agent2.conf qui se trouve dans le répertoire où vous avez installé l’agent Zabbix.

In the file, find the Option: AllowKey 1 part.

Add the following line below:[] 1 and uncomment the following line[] 2.

Save changes and close the file.

For changes to take effect, restart Zabbix agent service.

At next service stop, it will be automatically restarted by Zabbix agent.

Leave a Comment