Ad Widget

Collapse

Error 400 on OpsGenie Webhook while getting details of Alert

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spectroman
    Junior Member
    • Sep 2008
    • 17

    #1

    Error 400 on OpsGenie Webhook while getting details of Alert

    Using the JavaScript for Webhook onto OpsGenie, the following happens:

    - Event occurs, and it is sent properly to OpsGenie and an Alert is opened. On the data received back I have an RequestID (example):
    Code:
    b9aeaaaa-2aaa-4aaa-aaaa-5aaaaaaa3326
    - The webhook then will try to fetch details from the aforementioned RequestID, using: Sending request:
    Code:
    https://api.opsgenie.com/v2/alerts/requests/b9aeaaaa-2aaa-4aaa-aaaa-5aaaaaaa3326
    This second call, I understand is to receive proper information from the recently opened Alert (called Get-Alert) but that one, I am getting an error 400 when fired from the webhook.

    Code:
    Received response with status code 400
    
    <!DOCTYPE HTML PUBLIC "-
    //W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    <TITLE>ERROR: The request could not be satisfied</TITLE>
    </HEAD><BODY>
    <H1>400 ERROR</H1>
    <H2>The request could not be satisfied.</H2>
    <HR noshade size="1px">
    Bad request.
    We can't connect to the server for this app or website at this time. There might be too much traffic or a configurat
    ion error. Try again later, or contact the app or website owner.
    <BR clear="all">
    If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this err
    or by reviewing the CloudFront documentation.
    <BR clear="all">
    <HR noshade size="1px">
    <PRE>
    Generated by cloudfront (CloudFront)
    Request ID: 1NnEUWg6mC8BsuyobgSK_CtB0-a6U61W4CFOKHHfsMTdH7k7XX46Dg==
    </PRE>
    <ADDRESS>
    </ADDRESS>
    </BODY></HTML>
    If I do the same, similar request via bash with cURL, it just works...

    Code:
    $curl -XGET -H 'Content-Type: application/json' -H 'Authorization: GenieKey ffblafff-fdbl-u60a-c4c1-kkkk6blabla7' https://api.opsgenie.com/v2/alerts/requests/b9aeaaaa-2aaa-4aaa-aaaa-5aaaaaaa3326
    
    {"data":{"success":true,"action":"Create","process edAt":"2020-09-04T10:04:41.308Z","integrationId":"1baaaa45-6bc0-48
    45-8e93-038bbbbbbf0f","isSuccess":true,"status":"Created alert","alertId":"8722cccc-8c7b-47f5-9ff5-3ecgggggggg7-1599
    213881259","alias":"99212345"},"took":0.007,"reque stId":"2ffffffe-2741-4019-86f2-d2cdbfffffff"}
    I am quite empty of ideas by now... anyone seen this?

    In an Update: Anyone know if there is some way to dump the headers of the request before sending ?

    I am looking on the source (5.2) and I only see methods like AddHeader and ClearHeader, I can't see the name of the object to dump the var, do anyone know what is it?

    I figured now that, if the request is sent without a Header setting of "Host: api.opsgenie.com" he gives a 400 on bash/curl... although when added the Header on the script, I am uncertain if the header is really sent out...
    Last edited by Spectroman; 04-09-2020, 14:39.
  • max.ch.88
    Senior Member
    • Oct 2018
    • 206

    #2
    If I understand you correctly, you are trying to open a web page https://api.opsgenie.com/v2/alerts/r...a-5aaaaaaa3326. Why? You get the error message because don't use authorization.
    Are you having problems using the Opsgenie webhook?
    If you are writing your own webhook, you could look at the Opsgenie webhook JS code as an example.
    Last edited by max.ch.88; 04-09-2020, 17:23.

    Comment

    • Spectroman
      Junior Member
      • Sep 2008
      • 17

      #3
      Hi Max,

      This is happening using the official OpsGenie Webhook gathered from: https://www.zabbix.com/integrations/opsgenie

      I was also surprise that, this code , after sending the alert, he tries to fetch more information from the Alert in order to provide more information on the event on OpsGenie side (see screenshot below). Here he initiate the second GET cal after receiving a 202 upon creation of the working opsGenie alert:

      Code:
      if (resp.status === 202) {
      resp = Media.getAlertId(resp.response.requestId);
      if (params.event_source == 0 && params.event_value == 1 && params.event_update_status == 0) {
      result.tags.__zbx_ops_issuekey = resp.response.data.alertId;
      result.tags.__zbx_ops_issuelink = Media.params.web + 'alert/detail/' + resp.response.data.alertId;
      }
      }
      And thereafter, it is not "me" who is trying to open the webpage, this call is going out from the Webhook, here:

      Code:
      getAlertId: function (requestId) {
      do {
      resp = Media.request('get', 'requests/' + requestId, undefined, true);
      }
      while (typeof resp.response !== 'object' || typeof resp.response.data === 'undefined'
      || resp.response.data.success === false);
      
      if (typeof resp.response !== 'object' || typeof resp.response.data === 'undefined') {
      throw 'Cannot get ' + Media.name + ' issue ID. Check debug log for more information.';
      }
      
      return resp;
      }
      This Code is executed right after he received the basic information of the Alert creation with the RequestID ( first call is a working POST ).

      And obviously, in every call made by the WebHook he will add the Auth header with the token here:

      Code:
      var response,
      url = Media.params.api + query,
      request = new CurlHttpRequest();
      
      request.AddHeader('Content-Type: application/json');
      request.AddHeader('Authorization: ' + Media.params.token);
      
      
      if (typeof data !== 'undefined') {
      data = JSON.stringify(data);
      }
      It is also important to point out that "missing auth header" will give a 401 -- wrong body on the GET will give a 403 and throttle problems will give a 429.

      I am trying to make the WebHook work as is in a Zabbix 4.4.5, and apparently, doesn't matter if I add more headers (to match with the curl or postman headers) , this won't work. I can't explain why.

      I then tried to copy the exact same MediaType to a zabbix 5.2, and it worked like a charm.

      But on the 4.4.5, because this second call fails, he keeps repeating the alert, as if it hadn't created on OpsGenie side ( again, he did and I got the requestID)... and after 3 tries (default) he gives up with the error 400:

      Click image for larger version  Name:	error.png Views:	0 Size:	22.2 KB ID:	408504


      After testing on the Version 5.2 I see he creates this, after successfully doing all the steps:

      Click image for larger version  Name:	result.png Views:	0 Size:	19.5 KB ID:	408505


      So yeah... I cannot explain this behavior, I really tried a zillion things , for me it seems the only solution is to remove the code that makes the second GET-Alert call and do without the tags with the link to the Alert on opsg...

      Or if someone has any ideas...
      Last edited by Spectroman; 04-09-2020, 19:44.

      Comment

      • Spectroman
        Junior Member
        • Sep 2008
        • 17

        #4
        It is worth mention that the second call will create this veeeery handy and brilliant menu:

        Click image for larger version

Name:	menu.png
Views:	1363
Size:	24.8 KB
ID:	408507

        It would be a pity to break that functionality.

        Comment

        • max.ch.88
          Senior Member
          • Oct 2018
          • 206

          #5
          I would suggest upgrading to 5.0 and using out-of-the-box webhooks.
          But if it's impossible and you very very very want to have the Opsgenie webhook in your 4.4, then take that https://git.zabbix.com/projects/ZBX/...a_opsgenie.xml, change 5.0 to 4.4 on line 3 and remove lines 165, 418-476.
          Last edited by max.ch.88; 09-09-2020, 15:29.

          Comment

          Working...