Ad Widget

Collapse

Automatically add numbered macro for every discovered item?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tenou
    Junior Member
    • Feb 2020
    • 17

    #1

    Automatically add numbered macro for every discovered item?

    TLDR: How to have a discovery rule create a numbered Macro for every discovered item so you can manually define a custom alias for every finding?


    Hey there,

    I'll say in advance that I'm pretty new to discovered items and have only understood the basics yet (at least I think so).

    I'm using LLD to find connected 1wire devices (DS18B20 probes) and automatically create an item for each one checking the current temperature.

    My key for that is
    Code:
    system.run[find /sys/bus/w1/devices/* -maxdepth 0 -type l | sed '$d']
    Then a bit of preprocessing is done using javascript to transform the bash output to json:
    Code:
    var lld = [];
    var lines = value.split("\n");
    var lines_num = lines.length;
    for (i = 0; i < lines_num; i++)
    {
    var row = {};
    row["{#DEVICE}"] = lines[i]
    lld.push(row);
    }
    return JSON.stringify(lld);
    My item protoype is then using this key to extract the temperature reading:
    Code:
    system.run[cat {#DEVICE}/w1_slave | tail -n +2 | cut -d= -f2-]
    and uses a custom multiplier in the preprocessing section to give out a reading in °C.

    So far, so good. However, I'd like to have a friendly alias in the item title, which you can define as macro, so the current name won't give out the probe's path & name but rather a manually defined name, like the location of the probe.

    Currently I'm using this as item name:
    Code:
    Temperature reading of probe "{#DEVICE}"
    I'd rather have an macro created for every discovered item, like {$PROBE01}, {$PROBE02} and so on, which would, by default, equal {#DEVICE} but could be changed manually to another name like "Aisle 3, Rack 1, Inlet" or something like that.
  • Tenou
    Junior Member
    • Feb 2020
    • 17

    #2
    Solved, using context-specific macros.

    Comment

    Working...