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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rafa,
Yes, I did about that and it worked successfully. Thank you for replying, though!
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.