Ad Widget

Collapse

Multi macro json in discovery rule returns an item already exists response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • obcx
    Junior Member
    • Jan 2022
    • 3

    #1

    Multi macro json in discovery rule returns an item already exists response

    Hello,
    I have created a discovery rule that generates 2 macros as output for further item prototype-creating purpose. The discovery rule works correctly and item prototypes are creating items but I am having an error icon on the list with discovery rules saying:
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.
    Cannot create item: item with the same key "foo_bar_[{#MACRO_CODES_SEP}]" already exists.

    Originally I created JSON that has for each [HASHTAG="t5"]macro[/HASHTAG] corresponding several #MACRO_CODES:

    {"data":[{"{#MACRO}":"GROUP1","{#MACRO_CODES}":"666","{# MACRO_CODES}" :"777"},{"{#MACRO}":"GROUP2","{#MACRO_CODES}":" 666 ","{# MACRO_CODES}":"777"},{"{#MACRO}":"GROUP3","{#MACRO _CODES}":" 666","{#MACRO_CODES}":"777"},{"{#MACRO}":"GROUP4" , "{#MACRO_CODES}":"666","{#MACRO_CODES}":"777"}]}

    It works very well for all combinations of prototypes except of using only MACRO_CODES as key/name:
    foo_bar_[{#MACRO_CODES}]

    Other combinations do not return error, ex.:
    foo_bar_[{#MACRO}_{#MACRO_CODES}]

    I did testing as well with creating additional object with seperated {#MACRO_CODES_SEP} but it still returns an error:
    {"data":[{"{#MACRO}":"GROUP1","{#MACRO_CODES}":"666","{# MACRO_CODES}":"777"},{"{#MACRO}":"GROUP2","{#MACRO _CO DES}":"666","{#MACRO_CODES}":"777"},{"{#MACRO}":"G ROUP3","{#MACRO_CODES}":"666","{#MACRO_CODES}":"77 7"},{"{#MACRO}":"GROUP4","{#MACRO_CODES}":"666" ,"{ #MACRO_CODES}":"777"},{"{#MACRO_CODES_SEP}":"666", "{#MACRO_CODES_SEP}":"777"}]}
    Last edited by obcx; 25-08-2023, 09:52.
  • Felix Schäfer
    Junior Member
    • Mar 2021
    • 4

    #2
    Hi,
    can you show the way the LLD marcos are extracted from your json data?
    As I understand the discovery rule parses through each element of the data list.
    That is the preprocessing step:
    Code:
    [
       {"{#MACRO}":"GROUP1","{#MACRO_CODES}":"666","{#MACRO_CODES}":"777"},
       {"{#MACRO}":"GROUP2","{#MACRO_CODES}":"666","{#MACRO_CODES}":"777"},
       {"{#MACRO}":"GROUP3","{#MACRO_CODES}":"666","{#MACRO_CODES}":"777"},
       {"{#MACRO}":"GROUP4","{#MACRO_CODES}":"666","{#MACRO_CODES}":"777"},
       {"{#MACRO_CODES_SEP}":"666", "{#MACRO_CODES_SEP}":"777"}
    ]
    In the second step the actual LLD macros are extracted fron each entry that can happen by JSONPatch for example.
    As an result you should have an distinct set of LLD macros for each item in the list. The macrose will be replaced by the contend that is extracted from the data

    item1:
    {#MACRO} = GROUP1
    {#MACRO_CODE1} = 666
    {#MACRO_CODE2} = 777
    item2:
    {#MACRO} = GROUP2
    {#MACRO_CODE1} = 666
    {#MACRO_CODE2} = 777​
    ...

    For the prototypes these macro variables are used. That is why you need the {#MACRO}/Name to get disctinct item keys.

    I think you need to restructure your data code to get better results.
    Every data item should consist of the same data structure.
    The error messages you listed point out, that the LLD macros are not replaced the right way.
    For item prototypes you have to create an individual item key for every discovered item.​
    Perhaps you should explain your scenario a bit more detailed.

    best regards Felix

    Comment

    Working...