Ad Widget

Collapse

Zabbix 5.0 and Opsgenie Notification - Error Message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andredeo
    Junior Member
    • May 2008
    • 19

    #1

    Zabbix 5.0 and Opsgenie Notification - Error Message

    Hi everyone,

    I Followed the documentation and created a Opsgenie notification. The message is sent to Opsgenie, but presents a error:
    Opsgenie notification failed : TypeError: cannot read property 'id' of undefined
    Click image for larger version  Name:	Opsgenie Error.png Views:	0 Size:	16.2 KB ID:	402612
    This occurrers just on PROBLEM events.

    But OK events don't pute a note in Opsgenie and I don't know if is related for the first error.

    If I change the line:
    Code:
    result.tags.opsgenie_issue_key = params.web + '/alert/detail/' + resp.data.id + '/details';
    to:
    Code:
    result.tags.opsgenie_issue_key = params.web + '/alert/detail/' + '/details';
    The error doesn't appears, but of course I can't do this...

    Regards,
    Déo
    Last edited by andredeo; 04-06-2020, 16:21.
  • andredeo
    Junior Member
    • May 2008
    • 19

    #2
    Changing the block:
    Code:
    if ((params.eventvalue == 1) && (params.eventupdate == 0)) {
    url = params.url + '/' + params.eventid + '?identifierType=alias';
    resp = req.Get(url);
    resp = JSON.parse(resp);
    result.tags.opsgenie_issue_key = params.web + '/alert/detail/' + resp.data.id + '/details';
    }
    
    }
    To:
    Code:
    if ((params.eventvalue == 1) && (params.eventupdate == 0)) {
    url = params.url + '/' + params.eventid + '?identifierType=alias';
    resp = req.Get(url);
    resp = JSON.parse(resp);
    Zabbix.Log(3, "RESP_String: " + JSON.stringify(resp));
    result.tags.opsgenie_issue_key = params.web + '/alert/detail/' + resp.data.id + '/details';
    }
    
    }
    Is possible to show the error:
    RESP_String: {"code":40401,"message":"Alert with alias [5] not found.","took":0.004,"requestId":"afff143e-0075-4ed5-ba8e-df2f6a7ef766"}

    Comment

    • andredeo
      Junior Member
      • May 2008
      • 19

      #3
      The solution to the problem is:
      Click image for larger version

Name:	Message_Subject.png
Views:	794
Size:	27.6 KB
ID:	403112

      If you use any other subject, this will result in a problem.

      Apparently the problem is in Opsgenie API.

      If you change the code from:
      Code:
       else if (params.eventvalue == 0) {
      url = url + '/' + params.eventid + '/close?identifierType=alias'
      fields.note = params.message;
      }
      
      var resp = req.Post(url,
      JSON.stringify(fields)
      To:
      Code:
       else if (params.eventvalue == 0) {
      url = url + '/' + params.eventid + '/close?identifierType=alias'
      fields.note = params.message;
      }
      
      Zabbix.Log(3, "URL_PRE_POST: " + url);
      Zabbix.Log(3, "FIELDS: " + JSON.stringify(fields));
      
      var resp = req.Post(url,
      JSON.stringify(fields)
      You can see the log:
      Code:
      2097:20200610:205534.770 URL_PRE_POST: https://api.opsgenie.com/v2/alerts
      2097:20200610:205534.770 FIELDS: {"message":"[Zabbix Alert] PROBLEM - INFRA - TESTE Zabbix Novo - zabbix-web-dc2.wavy.systems","alias":"818","description":...,"priority":"P1"}
      The important part is the alias is here: "alias":"818"

      But, after the OpsGenie processed the message, the result is:
      Click image for larger version

Name:	Message_OpsGenie.png
Views:	680
Size:	132.0 KB
ID:	403113
      The alias field turns equal to the title.

      Regards,

      Comment

      Working...