Ad Widget

Collapse

Using macros in scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Speedfight
    Member
    • May 2007
    • 67

    #1

    Using macros in scripts

    Hi,

    I have a remote command script in "scripts" that can start a service when it is down.

    Is it possible to put in the service name with a macro in my script?

    let me show it:

    I have a item with key:
    service_state[Application]

    "Application" is the service name on windows.

    The item monitors if the service is down or not.

    When it is down Zabbix shows this through a trigger on my screen.
    I can click the trigger and have made a script "Start Service"

    the script contains:

    system.run[net start {MACRO}]


    What macro can I use so the script will work?

    I Tried filling the description field in the item and then use {ITEM.DESCRIPTION} in my script but that doesn't work.


    Does someone have a idea what macro I can use for it?
  • ingus.vilnis
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Mar 2014
    • 908

    #2
    Hi,

    Although it is not what you are exactly looking for, you can use user macros there.

    On host or template lever you add a user macro {$APP.MACRO.1} => Application

    In item you can use key service_state[{$APP.MACRO.1}]

    In script then use system.run[net start {$APP.MACRO.1}]

    Would that be an option?

    But wait! Why are you using item key system.run in a script? Why not simply net start {$APP.MACRO.1}?

    And don't forget you need to set EnableRemoteCommands=1 in agent config file for the remote host.

    Best Regards,
    Ingus

    Comment

    • Speedfight
      Member
      • May 2007
      • 67

      #3
      Hi Ignus,

      Thanks for your reply.

      I have thought of using user macro's but I have several servers with multiple applications with different service names.

      I could configure multiple macro's and let the script run on al of the services. If the service is running then that shouldn't be a problem but that is not that fancy and I hope there is a better way

      If I could use {ITEM.DESCRIPTION} that would be fine too but that is not working.

      Comment

      • ingus.vilnis
        Senior Member
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Mar 2014
        • 908

        #4
        Hi,

        There are very few macros that work in global scripts and {ITEM.DESCRIPTION} is not one of them.


        You can create a feature request for that.


        Best Regards,
        Ingus

        Comment

        • Speedfight
          Member
          • May 2007
          • 67

          #5
          Hi,

          I will create a feature request and use user macro's for now.

          Thanks.

          Comment

          Working...