Ad Widget

Collapse

Unique host prototype names with macros

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 875

    #1

    Unique host prototype names with macros

    Hey guys.

    I'm creating a discovery rule with a host prototype, and I'm looking for a good way to add a unique host name for each discovered host.
    Each original host has a master item that returns only two values per object. Something like this:

    Code:
    [{
        "NAME":"QMNAME1",
        "STATUS":"Running"
    },
        (...),
    {
        "NAME":"QMNAME2",
        "STATUS":"Running"
    }]
    The host prototype uses the LLD macro
    {#NAME} to create new hosts. However, some of these names are repeated on other hosts.

    I first thought of using the built-in macro "{HOST.HOST}" followed by the discovery macro {#NAME}, like "{HOST.HOST} - {#NAME}". This way, each newly discovered host would have a unique name.

    Click image for larger version

Name:	host_prototype.png
Views:	610
Size:	16.0 KB
ID:	493150​

    Unfortunately, built-in macros are not supported for host prototypes names.

    So, I'm wondering if there's another way to append a unique value from the original host to the discovered host names.

    Any thoughts on this matter?​
  • aigars.kadikis
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Mar 2018
    • 208

    #2
    A workaround can be to create a script to populate value from {HOST.HOST} in a user macro {$HOST.HOST}. This video describes how to do that:

    There is a template to install and maintain these values in long term:


    After that, it's possible to inject extra JavaScript preprocessing for LLD rule:
    Code:
    var jsonData = JSON.parse(value);
    lenghtOfArray=jsonData.length;
    
    var lld = [];
    
    for(var el = 0; el < lenghtOfArray; el++) {
    
    row = jsonData[el];
    row["{#HOST.HOST}"] = '{$HOST.HOST}';
    lld.push(row);
    
    }
    
    return JSON.stringify(lld);
    In the output, it will give:
    Code:
    ​
    [{
    "NAME":"QMNAME1",
    "STATUS":"Running",
    "{#HOST.HOST}":"hostOriginOfLLD"
    },
    ..

    Comment

    Working...