{{triggerDescription}} {{triggerUrl}} parameters via API

matvey_teplov September 20, 2023

Good afternoon Everyone,

I am looking into OG alert API (and perhaps a python wrapper) at https://docs.opsgenie.com/docs/python-sdk-alert, and I cannot find triggerUrl and triggerDescription parameters in the json'ized parameter set. Anyone knows how can I get a handle on these?

Regards

2 answers

1 accepted

1 vote
Answer accepted
Rafael Meira
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 22, 2023

Hey @matvey_teplov 

The `triggerUrl` and `triggerDescription` parameters won't be directly available in the OpsGenie Alert API. However, you can potentially use custom fields to include this information in an alert.

I will send you some suggestions below:

Looking at the OpsGenie Alert API documentation, you can pass extra properties as a dictionary using the `details` parameter when you create an alert. For example, you can do something like this:

```python
from opsgenie.swagger_client import AlertApi, AddAlertRequest, UserRecipient, TeamRecipient
from opsgenie.swagger_client.models import CreateAlertNoteRequest
from opsgenie.swagger_client.rest import ApiException

alert_api = AlertApi()

body = AddAlertRequest(
message="Server CPU Usage High",
alias="Server-1",
description="CPU Utilization has reached 90%",
responders=[
UserRecipient(username="john.doe@your-domain.com"),
TeamRecipient(name="ops_team")
],
actions=["Restart", "AnExampleAction"],
tags=["Overload", "Critical"],
details={
"triggerUrl": "http://example.com/triggerUrl",
"triggerDescription": "This is the trigger description"
},
entity="Server-1",
priority="P1"
)

try:
response = alert_api.create_alert(body=body)
print(response)
except ApiException as err:
print("Exception when calling AlertApi->create_alert: %s\n" % err)
```

In this example, we're using the `details` dictionary to add custom fields for `triggerUrl` and `triggerDescription`. Note that these fields should then be accessible in the alert details on the OpsGenie user interface.

Let me know if the information above was indeed useful.



Best,
Rafa

matvey_teplov September 22, 2023

Hi  Rafa,

 

Yes, the payload can be manipulated like:

 

body = og.CreateAlertPayload(
message='Message from: ' + datetime.datetime.utcnow().isoformat(),
alias=str(uuid.uuid1()),
description='ABCDEF',
responders=[{
'name': 'SampleTeam',
'type': 'team'
}],
visible_to=[
{'name': 'Sample',
'type': 'team'}],
actions=['Restart', 'AnExampleAction'],
tags=['OverwriteQuietHours'],
details={'key1': 'value1',
'key2': 'value2',
'URI': "https://www.google.com",
'received': datetime.datetime.utcnow().isoformat()
},
entity='pack1/' + str(uuid.uuid1()),
priority=alert_priority,
source="Runaway",
note="Blah-blah-bla"
)

 

Thank you for your reply!

Regards Matt

0 votes
matvey_teplov September 22, 2023

Hi Rafa,

 

Yes, I did about that and it worked successfully. Thank you for replying, though!

 

 

Cheers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events