Ad Widget

Collapse

Pass a value from a 'Discovery rule' to the key of an 'Item prototype' in Zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tonik
    Junior Member
    • Jun 2023
    • 13

    #1

    Pass a value from a 'Discovery rule' to the key of an 'Item prototype' in Zabbix

    Good afternoon. It is necessary to receive data from the Item and pass it to the "Discovery rules", and then use it in the key on each "Item prototypes".
    1) I get the data of the "Item".
    Code:
    Type: Zabbix agent
    Key: system.run["smartctl --scan-open"]​
    I get:
    Code:
    /dev/sda -d ata # /dev/sda, ATA device
    /dev/sdb -d sat # /dev/sdb [SAT], ATA device
    /dev/sdc -d sat # /dev/sdc [SAT], ATA device​
    2) I convert the result to the form (through preprocessing in JavaScript) to Json.
    Preprocessing:
    Code:
    const sd = value.match(/sd(.)/g);
    var data = [];
    for (i = 0; i <= sd.length; i++) {
    if (i % 2 == 0) {
    data.push({"disk": sd[i]});
    }
    }
    data.pop();
    return JSON.stringify(data);

    I get:
    Code:
    [{"disk":"sda"},{"disk":"sdb"},{"disk":"sdc"}]

    3) I create a "Discovery rule":​
    Type: Dependent items
    Code:
    LLD macros: LLD - {#DISK} and JSONPath - $..disk

    4) I create a "Item prototypes":
    Code:
    Type: Zabbix agent
    Key: system.run["smartctl -A /dev/[{$DISK}]"]

    ​But data from №3 comes to №4 as ["sda"], but I need it as sda. For me to use them in the key of "Item prototypes". For example:​
    Code:
    system.run["smartctl -A /dev/sda"]
    Can you please tell me how to pass the value sda to the key of "Item prototypes"?​​
  • Tonik
    Junior Member
    • Jun 2023
    • 13

    #2
    It turned out to get the data in the desired format using the macro function:
    Code:
    Key: system.run["smartctl -A /dev/{{#DISK}.regsub(\"..(...)\", \1)}"]

    Comment

    Working...