Ad Widget

Collapse

Nested macros / variable substitution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bitbucket
    Junior Member
    • Sep 2020
    • 18

    #1

    Nested macros / variable substitution

    I see a post from 2010 that indicates that nested macros won't be supported. However, the use case seems like it would be so common, there must be a workaround.

    I have an HTTP Agent that retrieves a json array containing details about 5 ethernet switches. I've gotten Discovery to create the host entries. So far, so good. Now I'm trying to create a template that will do this across multiple devices. The first issue I run into is API keys. I'd expect to be able to define the API keys as macros within each respective top-level host. Then, in the template macro, I could just reference them like this...

    {$API_SWITCHES_URL} => https://somedomain.com/api/switches/index.json?api_key={$API_KEY}

    {$API_KEY} is defined in the host.

    When I attempt to test this in a host though, it shows up as two separate macros and no substitution is done. Is there a way around this?
    Last edited by bitbucket; 17-01-2021, 22:25.
  • yurtesen
    Senior Member
    • Aug 2008
    • 130

    #2
    But you do not need nested macros. Do you? Why don't you enter URL value as

    URL => {$API_SWITCHES_URL}?=api_key={$API_KEY}

    and use the following template variables
    {$API_SWITCHES_URL} => https://somedomain.com/api/switches/index.json
    {$API_KEY} => ""
    in your host you can then define
    {$API_KEY} => YOURAPIKEY

    Comment

    Working...