Ad Widget

Collapse

Script for restart Windows service

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TRNX
    Member
    • Oct 2019
    • 54

    #1

    Script for restart Windows service

    Hello. I want to set up auto restart Windows services via trigger base action. I am running Zabbix 6 on Debian.
    But I don´t want create script for every one service, I want to use variable in script.

    The only one workaround (this is not a solution) I found is add {#SERVICE.NAME} macro to the trigger level tag and then use {EVENT.TAGS} macro in the script. This works.
    But what to do, if I have more than one tag? Nice, there is another macro {EVENT.TAGS.<tag name>}. But this macro doesn´t work in scripts and it´s presented as normal string and not variable.
    So what else can I do? Delete all tags? I wouldn't have a problem with that in Zabbix 5 and older version, where application category is. But in Zabbix 6 there was ridiculous change and application category was removed and all applications were moved to the tags. So these tags are now alternative to categorize different items and I don´t want to delete them.

    Is there any solution to resolve this?
    Thanks for any help.
    Last edited by TRNX; 21-06-2022, 16:21.
  • TRNX
    Member
    • Oct 2019
    • 54

    #2
    I made my own workaround.
    I used {EVENT.TAGS} macro as variable for service name in the script. In my situation, output from this macro are 3 tags. Example {EVENT.TAGS}: Application:Services, SvcName:wuauserv, WindowsServer
    Via powershell I removed first and last tags and the tag that remain is service name, which the script runs.

    Powershell script:
    Code:
    powershell -NoProfile -ExecutionPolicy Bypass -Command "& {$tags = '{EVENT.TAGS}';$out1 = ($tags -split ',',2)[-1];$out2 = ($out1 -split ':',2)[-1];$out3 = ($out2 -split ',',2)[-2];Start-Service $out3}"
    Maybe it will help someone.

    Comment


    • freemanjostus
      freemanjostus commented
      Editing a comment
      Hello Sir I can't configure the automatic start of services. Can you help me?
Working...