Conditions based on previous alert contents?
Asked by Paul Lopez:

I am not sure if this is possible, but am trying to figure out if it is - appreciate any insight.

We have a system that delivers 'up' and 'down' alerts for BGP link status. This is a libreNMS delivering to Opsgenie from incoming SNMP traps. We want opsgenie to alert us when a 'Down' alert is recieved, and an 'Up' alert so we know when peers recover on their own.

However, sometimes our routers issue fake 'up' alerts. We want to ignore these.

The logic I am trying to recreate goes something like this:

"If alert contains text 'BGP Up', then only notify if 'AS#####' (The AS number contained in the body of the alert) matches an AS##### in a previous alert recieved within the last, say 24 hours".   

I've been reading through policies section, action filters and 'services' which still confuse me to see if anything like this is possible, and I'm starting to think it's not.

Looking for the communities opinion - is there any way to corellate an alert to the textual content of a previous alert and make that a condition of the alert triggering in this way?

Our option B is to just 'ignore' 'Up' alerts from the two older routers that seem to be issuing the fake up alerts.


Answers:
author: Connor Eyles
body: Hey Paul!

I'm Connor from the Opsgenie support team here at Atlassian ?

If I understand this correctly and please correct me if I am wrong here, The logic you are wanting to do here is *"If alert contains text 'BGP Up', then only notify if 'AS#####' (The AS number contained in the body of the alert) matches an AS##### in a previous alert received within the last, say 24 hours".*

* Now is the timeframe important here for your logic?
* A real UP message will contain a matching AS##### and an existing alert is open with the same AS##### correct?
* A fake UP message will send a UP message containing AS##### with no existing open down alert?

So if this is the case what you can do is configure your integration so that the create action ignores UP messages and the UP messages can match the close action here. The logic here is when your system sends a UP message and there is an existing open alert that matches the AS##### it will automatically close the alert but if there is no existing open alert it will ignore that alert. You can set notifications when an alert is automatically closed, if you don't want the alert to close to set the UP messages to match the add note action instead.

To achieve this you can do the following:

* Edit the integration so that the create action ignores UP messages, configure the filter with your desired conditions.
* Ensure that the alias is configured so that the UP messages and down messages match with each other. The **Alias** field is a **user-defined unique identifier for "open" alerts**so for example if an open alert is AS##### and a UP alert comes in with the same alias the close action will match against this.
* Have the conditions set on the close action so that the UP messages match this action.

Now if you wanted to pull out AS##### from your payload you can use our string processing methods or regex to do this:

* <https://support.atlassian.com/opsgenie/docs/string-processing-methods-in-opsgenie-integrations/>
* <https://support.atlassian.com/opsgenie/docs/regular-expressions-for-improved-alert-filtering/>
* <https://support.atlassian.com/opsgenie/docs/dynamic-fields-in-opsgenie-integrations/>

For option 2 if you wanted to simply ignore the UP messages then all you need to do is configure the filters on the create action like this -   
![Image 2021-09-06 at 9.31.05 am](https://p-25foddj.b0.n0.cdn.getcloudapp.com/items/jku4vBLz/26087be6-06bc-47b1-bd44-51384336328d.jpg?v=f3b24bb00257f1e87feb689c25e0c015)  

Thanks,  
Connor

comments: author: Paul Lopez
body: Hi Conner -- you have interpreted my request correctly, and this sounds like it will probably work. I will give it a try and report back in a few days.  

Thankyou!


author: Connor Eyles
body: Glad to hear it Paul ?

Let me know how you go!

Thanks,

Connor


Tags: cloud