Duplicate tickets for same alerts are created in Jira
Asked by Awais Ali:

I have recently integrated opsgenie to Jira integration to get the tickets for alerts in opsgenie. But the issue is there is a lot of noise since there are same alerts again and again and similarly tickets are generated for the same alerts. There should be one ticket for the same alerts and not duplicates. Any idea on how can that be done in opsgenie or Jira side?


Answers:
author: Awais Ali
body: I did this through Webhook and AWS Lambda. So how it works is it posts to REST API endpoint which is AWS Lambda and there is a Python script in AWS lambda which processes the Opsgenie request and searches the Jira with some parameters. I will post a link to the script and describe its functionality in a day or two.

The script finds an issue, if it does not get one it makes one and if it finds one it adds the alert link to the comments section of an already existing ticket


author: Awais Ali
body: Hey [@Mamta Kalwani](/t5/user/viewprofilepage/user-id/2779122) here you go, feel free to improve if you want to. Thanks

[OG_JIRA](https://github.com/syed-awais-ali/automation-scripts/blob/master/opsgenie_jira_hook)


author: Andrew Laden
body: The key to this is you want to "de-duplicate" the alert in opsgenie, so that only one opsgenie alert is created.

opsgenie uses the "alias" field to determine if two alerts are for the same event. If they have the same alias, and there is an open alerts for the alias, a new one will not be created.

So what you want to do is see what the alias field is set to currently, and modify it to allow it to be the same for the same alerts.

Exactly how to do this is very dependent on the opsgenie integration and how the alerts are being created, so I cant give you specifics.

However, Opsgenie support is VERY helpful at helping you to create the right rules. I'd suggest reaching out to them (even via the chatbox on thier site) and asking for thier assistance in building the alias.

comments: author: Awais Ali
body: Hey [@Andrew Laden](/t5/user/viewprofilepage/user-id/744425)

Thanks for the reply. The issue is that I am talking about the Jira side. I understand about the Alias concept that opsgenie uses. The use case is that if you get an alert a ticket is created in opsgenie. Now after some time the alert gets closed and then opens again after lets say X hours. The ticket on the Jira for that alert is already there and it again creates a new one since its a new alert right.

So I wanted to see that if an issue exists in Jira -- for an alert lets say ABC no matter how many times the alert ABC flaps -- there should be no duplicate tickets in Jira for the alert ABC if it comes lets say 4 times a day.

I hope I made it clear. Thank You !!


author: Andrew Laden
body: Thats a little harder. The general model is 1 jira issue to 1 opsgenie alert. If you want a model of many opsgenie alerts to 1 jira issue, you are going to have to do that yourself.

Are you using OEC to generate the jira issues from opsgenie? or are you using the native integration. If you are using OEC, you could theoretically write some validation code in that could search jira for an open issue matching your parameters and if found change to a comment operation instead of a create, but its going to take some work to get that right.


author: Awais Ali
body: Yeah, that's what I thought as well. I am currently using native integration. I guess I will have to switch to OEC and write a script to call Jira API and search for the issues and if that exists then there is no need to make another ticket.

What are your thoughts on <https://confluence.atlassian.com/adminjiraserver073/creating-issues-and-comments-from-email-861253784.html?_ga=2.202354585.924284190.1583141218-1364091263.1530101294>

Do you think this could be useful?


author: Andrew Laden
body: Not really. I suppose you are thinking of having the email from opsgenie create the ticket instead of the integration?

You would actually make your situation worse. When an email comes in, jira tries to figure out if it should comment on an existing ticket, or open a new one. There are a few ways it tries.

1: Looks for an jira issue key in the subject of the email

2: looks for "in-reply-to" or "in-response-to" headers, and tries to match up to a previous email.

Neither of these will match, so every mail from opsgenie will create a new issue.

The built in jira email handler isnt very configurable.

If you have a add on email handlers (JEMH for example) you could write some custom handling to try to match a mail up to an existing issue. Would probably be harder them the OEC solution.


author: Awais Ali
body: Hey, [@Andrew Laden](/t5/user/viewprofilepage/user-id/744425) I did this through Webhook and AWS Lambda. So how it works is it posts to REST API endpoint which is AWS Lambda and there is a Python script in AWS lambda which processes the Opsgenie request and searches the Jira with some parameters. I will post a link to the script and describe its functionality in a day or two.

The script finds an issue, if it does not get one it makes one and if it finds one it adds the alert link to the comments section of an already existing ticket.


author: Mamta Kalwani
body: Hi [@Awais Ali](/t5/user/viewprofilepage/user-id/2367590) ,

I'd be interested in this script.   

Thanks,

Mamta


Tags: duplicate

jira