Ad Widget

Collapse

LLD with an item that is a list object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaveDill
    Senior Member
    • Sep 2014
    • 103

    #1

    LLD with an item that is a list object

    I've created a discovery item that querys my netbox API and returns the Tags for the host.

    The Tags field that netbox returns, does not have key value pairing, but a list object.

    Is there a way to manipulate this to create unique items using LLD? Right now it creates an item like this service.info[\["gogs", "httpd"\]]



    Example of what im trying to LLD against:


    Code:
    {
        "data": [
            ["gogs", "httpd"]
        ]
    }
    Here's an example of the raw portion that i'm preprocessing and pulling the tags out of;

    Code:
    {
        "count": 1,
        "next": null,
        "previous": null,
        "results": [
            {
    
                "tags": [
                    "gogs",
                    "httpd"
                ]
            }
        ]
    }

    I want to have an item prototype that lines up with those names, such as service.info[{#VM_SERVICE_NAMES}]
  • HaveDill
    Senior Member
    • Sep 2014
    • 103

    #2
    I managed to get this working. What i ended up doing was writing a javascript preprocess, that took the list value i got and appended the macro in front of it.


    Here was my code, in case this can help anyone in the future

    Code:
    var array = JSON.parse(value)
    var len = array.length;
    var x = 0
    output = "{ \"data\" :["
    for (; x < len - 1; x++){
       var stripped = array[x].replace('service_','');
       output += "{\"{#VMSERVICE}\": \"" + stripped + "\"},"
    }
    var stripped = array[x].replace('service_','');
    output += "{\"{#VMSERVICE}\": \"" + stripped + "\"}"
    output += "]}"
    return output

    Comment

    Working...