I get "SyntaxError: unterminated statement (line 5)" in a preproccessing JavaScript. I don't get this error in my JS online editor
I'm trying to create a JS that parses IPv6 address in decimal form in the OID of Cisco SNMP to a HEX address.
I was able to make the code work in an online editor but when I copy the code to my template in Zabbix I get the above error
It looks like I'm missing a ; on line 5 but I'm not.
using Template in 6.0
Value:
I'm trying to create a JS that parses IPv6 address in decimal form in the OID of Cisco SNMP to a HEX address.
I was able to make the code work in an online editor but when I copy the code to my template in Zabbix I get the above error
It looks like I'm missing a ; on line 5 but I'm not.
using Template in 6.0
Value:
Code:
[{"{#SNMPINDEX}":"32.1.1.1.1.1.1.1.1.1.1.1.1.1.1.16","{#SNMPVALUE}":"65001"},{"{#SNMPINDEX}":"32.1.1.1.1.1.1.1.1.1.1.1.1.1.1.32","{#SNMPVALUE}":"65002"},{"{#SNMPINDEX}":"32.1.1.1.1.1.1.1.1.1.1.1.1.1.1.48","{#SNMPVALUE}":"65003"}]
Code:
value = value.slice(1, -1);
value = value.replaceAll("},{", "}£{");
const item = value.split("£");
value = '';
let i = 0;
while (i < item.length) {
item[i] = item [i].slice(1, -1);
let part = item[i].split(",");
let j = 0;
while (j < part.length) {
let result = part[j].split(":");
if ((j % 2) == 0) {
let k = 0;
let hex = "";
while (k < result.length) {
if ((k % 2) == 0) {
} else {
result[k] = result[k].slice(1, -1);
let number = result[k].split(".");
let l = 0;
while (l < number.length) {
if ((l % 2) == 0) {
number[l] = number[l] * 256;
} else {
number[l] = parseInt(number[l-1]) + parseInt(number[l]);
if (l == 1) {
hex = number[l].toString(16);
} else {
hex = hex + ":" + number[l].toString(16);
}
}
l++;
}
}
k++;
}
result[1] = hex;
part[0] = result[0] + ':"' + result[1] + '"';
}
j++
}
item[i] = part[0] + ',' + part[1];
if (i == 0) {
value = item[i];
} else {
value = value + '},{' + item[i];
}
i++;
};
return value;
Comment