Ad Widget

Collapse

Zabbix Integration Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TecDragon
    Member
    • Nov 2019
    • 63

    #1

    Zabbix Integration Issue

    Trying to integrate Zabbix into our Freshserivce instance

    Following these instructions to the letter
    About this integration: Integrate Zabbix with Freshservice to triage the alerts sent from your diverse IT components, including networks, servers, virtual machines and cloud services to act upon them in a timely manner and prevent outages. C...


    Step 1 - says to create a media type, which I did, exactly as the instructions above instructed. I even deleted it and re-did it again, just to double check and I receive the exact same error each time.

    Media type test failed.
    • ReferenceError: identifier 'fields' undefined at [anon] (duktape.c:83867) internal at [anon] (function:115) preventsyield
    Googling it, it seems to be an error with the 'fields' variable but I have no idea how to fix it. Below is the supplied script from the link above.

    Code:
    try {
    Zabbix.Log(4, 'webhook script value=' + value);
    var result = {
    'tags': {
    'endpoint': 'FS_AMS'
    }
    };
    params = JSON.parse(value);
    var tags_array = [];
    if (params.tags != "" && params.tags != "{EVENT.TAGS}") {
    tags = params.tags.split(",");
    for(i = 0; i < tags.length; i++) {
    tags_array.push(tags[i].trim());
    }
    }
    req = new CurlHttpRequest();
    fields = {
    "message": params.message,
    "subject": params.subject,
    "item_key": params.item_key,
    "host_ip": params.host_ip,
    "event_name": params.event_name,
    "hostname": params.hostname,
    "event_opdata": params.event_opdata,
    "severity": params.severity,
    "item_name": params.item_name,
    "event_status": params.event_status,
    "action_id": params.action_id,
    "action_name": params.action_name,
    "event_date": params.event_date,
    "event_time": params.event_time,
    "event_age": params.event_age,
    "tags": tags_array
    };
    if(params.event_status == "RESOLVED") {
    fields.severity = "ok";
    }
    resp = '';
    req.AddHeader('Content-Type: application/json');
    req.AddHeader('Authorization: ' + params.auth_key);
    resp = req.Post(params.url, JSON.stringify(fields));
    if (req.Status() != 202) {
    throw 'Response code: ' + req.Status();
    }
    else {
    results = JSON.stringify({"response_body": resp });
    Zabbix.Log(4, results);
    }
    return results;
    }
    catch(error) {
    Zabbix.Log(4, 'FS AMS Notification failed: ' + JSON.stringify({ "fields": fields }));
    Zabbix.Log(4, 'FS AMS alert creation failed : ' + error);
    results = JSON.stringify({"error": error});
    return results;
    }
    Please assist, thank you.
  • WillHolmes
    Junior Member
    • Jul 2022
    • 4

    #2
    Having a similar issue and I currently have a ticket open with Freshservice on this, I think they are amending the script to account for changes that have been made on the Zabbix side with recent upgrades and deprecations of functions.

    Comment

    • WillHolmes
      Junior Member
      • Jul 2022
      • 4

      #3
      This is the script I received from Freshservice Support, appears to solve the issue.

      Code:
      try {
      Zabbix.Log(4, 'webhook script value=' + value);
      var result = {
      'tags': {
      'endpoint': 'FS_AMS'
      }
      };
      
      params = JSON.parse(value);
      var tags_array = [];
      if (params.tags != '' && params.tags != '{EVENT.TAGS}') {
      tags = params.tags.split(',');
      for(i = 0; i < tags.length; i++) {
      tags_array.push(tags[i].trim());
      }
      }
      req = new HttpRequest();
      fields = {
      'message': params.message,
      'subject': params.subject,
      'item_key': params.item_key,
      'host_ip': params.host_ip,
      'event_name': params.event_name,
      'hostname': params.hostname,
      'event_opdata': params.event_opdata,
      'severity': params.severity,
      'item_name': params.item_name,
      'event_status': params.event_status,
      'action_id': params.action_id,
      'action_name': params.action_name,
      'event_date': params.event_date,
      'event_time': params.event_time,
      'event_age': params.event_age,
      'tags': tags_array
      };
      if(params.event_status == 'RESOLVED') {
      fields.severity = 'ok';
      }
      resp = '';
      
      req.addHeader('Content-Type: application/json');
      req.addHeader('Authorization: ' + params.auth_key);
      
      resp = req.post(params.url, JSON.stringify(fields));
      
      if (req.getStatus() != 202) {
      throw 'Response code: ' + req.getStatus();
      }
      else {
      results = JSON.stringify({'response_body': resp });
      Zabbix.Log(4, results);
      }
      return results;
      }
      catch(error) {
      Zabbix.Log(4, 'FS AMS Notification failed: ' + JSON.stringify({ 'fields': fields }));
      Zabbix.Log(4, 'FS AMS alert creation failed : ' + error);
      results = JSON.stringify({'error': error});
      return results;
      }

      Comment

      • TecDragon
        Member
        • Nov 2019
        • 63

        #4
        WillHolmes Thank you so much that solved my issue as well.

        Comment

        • WillHolmes
          Junior Member
          • Jul 2022
          • 4

          #5
          TecDragon You're more than welcome. Glad I was able to help, not sure how long it will take Freshservice to publish the new script on their site.

          Comment

          • galavichid
            Member
            • Mar 2021
            • 40

            #6
            WillHolmes thanks for your sharing! You helped me too! Freshservice still haven’t updated the code over the website.

            Comment

            • spyglass8393
              Junior Member
              • Sep 2023
              • 1

              #7
              WillHolmes +1 for another person you helped by posting this. Freshservice still has outdated instructions on their site.

              Comment

              Working...