Parser for incoming webhook from OpsGenie

Does anyone already have a script that will parse an incoming OpsGenie webhook and turn it into a message that rocket.chat likes?

From digging it out of the logs, looks like they’re sending e.g.:

{
  action: 'Acknowledge',
  alert: {
    alertId: 'fxxxxxx9-xxxx-xxxx-xxxx-xxxxxxxxxxxx-1532948900683',
    message: 'Test alert: https://youtu.be/J91ti_MpdHA?t=5',
    tags: [],
    tinyId: '2',
    entity: '',
    alias: 'fxxxxxx9-xxxx-xxxx-xxxx-xxxxxxxxxxxx-1532948900683',
    createdAt: 1522948900683,
    updatedAt: 1522948957348000500,
    username: 'michael@pandas-are-awesome.net',
    userId: '6xxxxxx5-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    teams: [ 'bxxxxxxf-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ],
    priority: 'P3',
    source: 'michael@pandas-are-awesome.net'
  },
  source: { name: '', type: 'web' },
  integrationName: 'Webhook',
  integrationId: '5xxxxxx1-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
  integrationType: 'Webhook'
} 
1 Like

@jomaxro wrote a simple one for us :heart:

class Script {
  process_incoming_request({ request }) {
    var alert = request.content.alert;
    
    return {
      content: {
        attachments: [{
          title: alert.message,
          title_link: "https://app.eu.opsgenie.com/alert/V2#/show/" + alert.alertId,
          text: "Priority: " + alert.priority + "\nLast Action: " + request.content.action + "\nAlert ID: " + alert.alertId
        }]
      }
    };
  }
}
3 Likes

Perfect! Glad you got it. Can pretty much grab and use any of the properties from your payload all available in request.content

Often like github for example we’ll take a run through a switch based on type. That way one webhook can handle multiple different payloads