Ad Widget

Collapse

Media Type Webhook Script - Error with find function

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MJ@1234
    Junior Member
    • Sep 2017
    • 6

    #1

    Media Type Webhook Script - Error with find function

    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));"


    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!
  • Answer selected by MJ@1234 at 12-09-2023, 00:02.
    Glencoe
    Zabbix developer
    • Oct 2019
    • 152

    Hi! Rewrite this script without using arrow functions (=>), Duktape doesn't support those.

    Comment

    • Glencoe
      Zabbix developer
      • Oct 2019
      • 152

      #2
      Hi! Rewrite this script without using arrow functions (=>), Duktape doesn't support those.

      Comment

      Working...