Hello,
I have a LLD which returns this JSON:
Now I with to extract the {#DISK.SIZE.GB} value via a data prototype, this works fine, when I create the item manually
But when I use the template like below, all macros are resolved, which then does not work.
How can I escape the macros in the javascript, so only the instances I wish are replaced by the values?
Unfortunalty, the {{#DISK.ID}} gets expanded to {apps-aarboard_IDE_0_0} value
I have a LLD which returns this JSON:
Code:
{ "disks": [
{
"{#DISK.MINIMUM.SIZE.GB}": "16",
"{#DISK.BLOCK.SIZE}": "33554432",
"{#DISK.VHD.TYPE}": "Dynamic",
"{#DISK.VHD.FORMAT}": "VHDX",
"{#VM.ID}": "b7dbb0ba-9bc0-4358-9cda-cc7ebdf0fdcf",
"{#VM.NAME}": "apps-aarboard",
"{#DISK.ALIGNMENT}": "1",
"{#DISK.LOGICAL.SECTOR.SIZE}": "512",
"{#DISK.LOCATION}": "0",
"{#DISK.PATH}": "D:\\Hyper-V\\Hyper-V Replica\\Virtual hard disks\\B7DBB0BA-9BC0-4358-9CDA-CC7EBDF0FDCF\\APPS aarboard innovaphone.vhdx",
"{#DISK.CONTROLLER}": "IDE",
"{#DISK.NUMBER}": "0",
"{#DISK.SIZE.GB}": "16",
"{#DISK.FILE.SIZE.GB}": "9.5",
"{#DISK.PHYSICAL.SECTOR.SIZE}": "4096",
"{#DISK.FRAGMENTATION}": "3",
"{#DISK.ID}": "apps-aarboard_IDE_0_0"
}]
}
Code:
var data = JSON.parse(value);
var diskId = "apps-aarboard_IDE_0_0";
// Debug: Return info about what we found
if (!data.disks || data.disks.length === 0) {
throw "ZBX_UNSUPPORTED: No disks array found";
}
for (var i = 0; i < data.disks.length; i++) {
var disk = data.disks[i];
if (disk["{#DISK.ID}"] === diskId) {
var fileSize = disk["{#DISK.FILE.SIZE.GB}"];
if (!fileSize) {
throw "ZBX_UNSUPPORTED: Field {#DISK.FILE.SIZE.GB} not found or empty";
}
return fileSize;
}
}
// Debug: Show what disk IDs we found
var foundIds = [];
for (var i = 0; i < data.disks.length; i++) {
foundIds.push(data.disks[i]["{#DISK.ID}"]);
}
throw "ZBX_UNSUPPORTED: Disk ID '" + diskId + "' not found. Found: " + foundIds.join(", ") + "Values: "+value;
How can I escape the macros in the javascript, so only the instances I wish are replaced by the values?
Unfortunalty, the {{#DISK.ID}} gets expanded to {apps-aarboard_IDE_0_0} value
Code:
var data = JSON.parse(value);
var diskId = "{#DISK.ID}";
// Debug: Return info about what we found
if (!data.disks || data.disks.length === 0) {
throw "ZBX_UNSUPPORTED: No disks array found";
}
for (var i = 0; i < data.disks.length; i++) {
var disk = data.disks[i];
if (disk["{{#DISK.ID}}"] === diskId) {
var fileSize = disk["{#DISK.FILE.SIZE.GB}"];
if (!fileSize) {
throw "ZBX_UNSUPPORTED: Field {#DISK.FILE.SIZE.GB} not found or empty";
}
return fileSize;
}
}
// Debug: Show what disk IDs we found
var foundIds = [];
for (var i = 0; i < data.disks.length; i++) {
foundIds.push(data.disks[i]["{#DISK.ID}"]);
}
throw "ZBX_UNSUPPORTED: Disk ID '" + diskId + "' not found. Found: " + foundIds.join(", ") + "Values: "+value;
Comment