Hi All,
I've written a Webhook script to grab a list of company names from an array & then match the start of the hostname to the company abbreviation in the array. When a match is found, split the array value and return the Company Name part after the delimiter.
The rest of the script is working well but I'm struggling to get this function to work. I've tested the function outside of Zabbix scripting and it works fine, with the same dataset. and with the test data below. My guess is that the find function may not exist for use in Zabbix?
I'm looking for an alternative way of doing this if that is the case.
In Zabbix when testing the Media Type I get an error "SyntaxError: parse error (line ##)" where the line ## is "var mycomp = myarr.find((comp) => findcompany(comp));"
Thanks in advance!
I've written a Webhook script to grab a list of company names from an array & then match the start of the hostname to the company abbreviation in the array. When a match is found, split the array value and return the Company Name part after the delimiter.
The rest of the script is working well but I'm struggling to get this function to work. I've tested the function outside of Zabbix scripting and it works fine, with the same dataset. and with the test data below. My guess is that the find function may not exist for use in Zabbix?
I'm looking for an alternative way of doing this if that is the case.
In Zabbix when testing the Media Type I get an error "SyntaxError: parse error (line ##)" where the line ## is "var mycomp = myarr.find((comp) => findcompany(comp));"
Code:
var myarr =[
"CON|Company One",
"CTW|CompanyTwo",
"CTH|CompanyThree"
]
var companyabbr = "CTW"
function findcompany(comp) {
return comp.startsWith(companyabbr);
}
var mycomp = myarr.find((comp) => findcompany(comp));
if (mycomp) {
let mycompParts = mycomp.split("|");
companyresult = mycompParts[1]
} else {
companyresult="catchall"
}
return JSON.stringify(mycomp,companyresult);
Thanks in advance!
Comment