I wanted to be able to get Zabbix to start a specific stopped Windows services with an action in 6.4 if it stops.
It's a fairly simple solution but it's taken me hours to get there so hopefully this helps.
I'm certain someone will point out a simpler way, but this is what worked for me.
Step 1
The first thing I had to do was add a new tag to the service discovery template.
I opened the 'Windows by Zabbix agent' template. Went to Discovery>Windows service discovery>Trigger prototypes.
There was only one entry in there for service not running, went into that and then tags and added a new one of servicename and {#SERVICE.NAME} for the value.
I then ran a rediscovery on the host. This puts a tag on the trigger with the service name that you use later in the script. With enough time it would have sorted this out itself.
Step 2
I then had to create a script to restart the service. Alerts>Scripts
I created a new one called 'Restart Windows Service' and selected action operation for scope, script for type and zabbix agent on execute on.
In the commands I put
c:\windows\system32\net start {EVENT.TAGS.servicename}
Theory being when it runs it replaces the tag with the Windows service name, and it seems to work nicely.
Step 3
I then had to create a trigger action, Alerts>Actions>Trigger Actions.
I created a new one called 'restart service action'.
On the conditions I added an entry of value of tag 'servicerestart' = true and the operation to run the script from earlier.
This part baffled me, until you create the script, the only option you get is to send a message, once you create the script that becomes an option in the operations.
Step 4
I then cloned the trigger for the Windows service I wanted to restart if it fails and added a new tag of servicerestart with a value of true.
I've always wondered if there was an easier way of doing this but it works.
When the trigger fires for that service, it kicks off the script and starts it and it seems to work nicely.
You do have to have
AllowKey=system.run[*]
In the zabbix_agent2.conf file for it to allow it.
As I say, hopefully this helps someone you should be able to adapt this for other jobs to run too.
Comment