opsgenie alert-api

prateesh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 11, 2019

From opsgenie alert-api, I am trying to get the alerts list for a particular team for last week Monday 8am to current week's Monday 8 am.

Can some one help me modify this query pls

response = requests.get('https://api.opsgenie.com/v2/alerts?query=createdAt%3A2019-04-29T08:00:00&teams=Site reliability&sort=createdAt&order=desc', headers=headers)

Appreciate  the help

3 answers

1 accepted

0 votes
Answer accepted
Gökçem
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 17, 2019

Hi there,

 

Thanks to contact with Opsgenie. You can use the following query:

https://api.opsgenie.com/v2/alerts?query=createdAt>1557129600+AND+createdAt<1557734400+AND+teams="Site reliability"&sort=createdAt&order=asc

 

For the time format we are using UNIX time stamp. And if you are searching for multiple queries "+AND+" should be used between them. (1557129600 for 06-05-2019 08.00.00 and 1557734400 for 13-06-2019 08.00.00)

 

Hope this helps to your API request. Best regards,

prateesh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 20, 2019

Thanks for the help!

0 votes
Patrick
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 7, 2023

Sorry for having to warm up this topic. Maybe in the meantime the API changed. But for me this does not work.

If I want to query this (UNIX timestamps)

https://api.eu.opsgenie.com/v2/alerts/?sort=createdAt&query=createdAt>1698218567+AND+createdAt<1698823367+AND+status=open+AND+acknowledged=true

and urlencode the query so that it looks like this:

https://api.eu.opsgenie.com/v2/alerts/?sort=createdAt&query=createdAt%3E1698218608%2BAND%2BcreatedAt%3C1698823408%2BAND%2Bstatus%3Dopen%2BAND%2Backnowledged%3Dtrue

I get this error from the API

"Time is accepted in following formats: [dd-MM-yyyy] - [dd-MM-yyyy'T'hh:mm:ss] - [dd-MM-yyyy'T'HH:mm:ssz]"

It should work according to the docs here: https://support.atlassian.com/opsgenie/docs/search-queries-for-alerts/

If I change the timestamp format it looks like this:

https://api.eu.opsgenie.com/v2/alerts/?sort=createdAt&query=createdAt>25-10-2023+AND+createdAt<01-11-2023+AND+status=open+AND+acknowledged=true
https://api.eu.opsgenie.com/v2/alerts/?sort=createdAt&query=createdAt%3E25-10-2023%2BAND%2BcreatedAt%3C01-11-2023%2BAND%2Bstatus%3Dopen%2BAND%2Backnowledged%3Dtrue

But I still get the same error message.

Any Idea what I might do wrong?

Patrick
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 8, 2023

Just had some idea and replaced "+" with " " (whitespace) before urlencoding.

This did the trick. Now the returned alerts look valid. So, looks to me like there was really a change in the API.

0 votes
öcs September 20, 2021

you might wanna pubish this in the API documentation. Kinda basic information for everybody, yet not mentioned there...

sandres
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 30, 2022

This seems to be documented here: https://docs.opsgenie.com/docs/alert-api#list-alerts currently.

öcs August 30, 2022

I meant the +AND+ part. That is something that many would need, yet I haven't found it described in the documentation.

sandres
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 30, 2022

Well, yeah - an example there would be nice. Generally the documentation refers to https://support.atlassian.com/opsgenie/docs/search-queries-for-alerts/ (with no direct URL and one has to search it yourself) which kind of explains it and then you have to combine it with html encoding (+), yes.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events