Ad Widget

Collapse

Macro function used in a script

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #1

    Macro function used in a script

    Hey guys.

    I'm using Zabbix 6.2 and, every now and then, I get some Windows "service is not running" event. Some of those services, I can just restart.

    Basically, I'm using "Windows services discovery" to find and monitor those services, and the associated trigger offers the following event name:
    Code:
    "{#SERVICE.NAME}" ({#SERVICE.DISPLAYNAME}) is not running (startup type {#SERVICE.STARTUPNAME})

    So, a simple command or two to restart the service was enough for me.
    Code:
    NET START "{#SERVICE.NAME}"

    For that, I created a script to issue the above command while using a macro function.
    Code:
    NET START {{EVENT.NAME}.regsub(^\"(.*)\".*,\1)}
    Click image for larger version

Name:	image.png
Views:	660
Size:	12.8 KB
ID:	456102

    I believe the syntax is correct, but when I test it, the Net Start output shows me the command is wrong.
    System error 123 has occurred.
    The filename, directory name, or volume label syntax is incorrect.​

    So, it seems "{EVENT.NAME}" macro was not properly filtered with the "regsub" function.

    Maybe I'm doing something wrong... Any ideas?
    Thanks​
  • Answer selected by markfree at 09-03-2023, 00:10.
    Semiadmin
    Senior Member
    • Oct 2014
    • 1625

    Macro function works with {ITEM.VALUE}, {ITEM.LASTVALUE} and LLD macros only. But you may tag item or trigger prototypes by {#SERVICE.NAME} and use {EVENT.TAGS.<tag name>} macro.

    Comment

    • Semiadmin
      Senior Member
      • Oct 2014
      • 1625

      #2
      Macro function works with {ITEM.VALUE}, {ITEM.LASTVALUE} and LLD macros only. But you may tag item or trigger prototypes by {#SERVICE.NAME} and use {EVENT.TAGS.<tag name>} macro.

      Comment

      • markfree
        Senior Member
        • Apr 2019
        • 868

        #3
        That worked great for me.
        Since "Windows Services" discovery already creates a "service" tag for every discovered service, I was abble to point the "{EVENT.TAG.<tag_name>}" macro to it.
        My script ended up like this:
        Code:
        NET START "{EVENT.TAGS.service}"
        Thanks a lot.​

        Comment

        Working...