Deprecated Alert Actions

The Opsgenie SDK for Java provides the following actions that can be executed on Opsgenie service.

Create Alert

Creates alerts at Opsgenie

OpsGenieClient client = new OpsGenieClient();

CreateAlertRequest request = new CreateAlertRequest();
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setMessage("appserver1 down");
request.setDescription("cpu usage is over 60%");
request.setSource("nagios");
request.setEntity("appserver1");
request.setActions(Arrays.asList("ping", "restart"));
request.setTags(Arrays.asList("network", "operations"));
request.setRecipients(Arrays.asList("[email protected]"));
request.setTeams(Arrays.asList("ops_team","dev_team"));

CreateAlertResponse response = client.alert().createAlert(request);
String alertId = response.getId();

Close Alert

Closes alerts at Opsgenie.

OpsGenieClient client = new OpsGenieClient();

CloseAlertRequest request = new CloseAlertRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
CloseAlertResponse response = client.alert().closeAlert(request);
assert response.isSuccess();

Delete Alert

Deletes alerts at Opsgenie.

OpsGenieClient client = new OpsGenieClient();

DeleteAlertRequest request = new DeleteAlertRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
DeleteAlertResponse response = client.alert().deleteAlert(request);
assert response.isSuccess();

Get Alert

Retrieves specified alert details from Opsgenie

OpsGenieClient client = new OpsGenieClient();

GetAlertRequest request = new GetAlertRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
GetAlertResponse response = client.alert().getAlert(request);
String message = response.getAlert().getMessage();
String description = response.getAlert().getDescription();
List<string> recipients = response.getAlert().getRecipients();
List<string> teams = response.getAlert().getTeams();

List Alerts

Retrieves latest alerts with given limit at Opsgenie. If limit is not set it retrieves latest 20 alerts and 100 alerts max per request.

OpsGenieClient client = new OpsGenieClient();

ListAlertsRequest request = new ListAlertsRequest();
request.setApiKey("39d50168-24b3-4355-b285-b91060823dee");

ListAlertsResponse response = client.alert().listAlerts(request);
List<Alert> alerts = response.getAlerts();

List Alerts With Paging

Let's say we have 100 alerts at the system. We want to get 5 alerts per request and we want to start polling from the oldest alert.

Our first request will be like the following:

OpsGenieClient client = new OpsGenieClient();

ListAlertsRequest request = new ListAlertsRequest();
request.setApiKey("39d50168-24b3-4355-b285-b91060823dee");
request.setLimit(5);
request.setSortOrder(ListAlertsRequest.SortOrder.asc);
request.setSortBy(ListAlertsRequest.SortBy.createdAt);

ListAlertsResponse response = client.alert().listAlerts(request);
List<Alert> alerts = response.getAlerts();
long createdAt = alerts.get(alerts.size()-1).getCreatedAt();

Now, we have the latest "createdAt" value of the retrieved 5 alerts shown above. We will use the "createdAt" value at our next request to retrieve 6th to 10th alerts.

Our next request will be like the following:

OpsGenieClient client = new OpsGenieClient();

ListAlertsRequest request = new ListAlertsRequest();
request.setApiKey("39d50168-24b3-4355-b285-b91060823dee");
request.setLimit(5);
request.setSortOrder(ListAlertsRequest.SortOrder.asc);
request.setSortBy(ListAlertsRequest.SortBy.createdAt);
request.setCreatedAfter(createdAt); // createdAt value from the first request.

ListAlertsResponse response = client.alert().listAlerts(request);
List<Alert> alerts = response.getAlerts();
long createdAt = alerts.get(alerts.size()-1).getCreatedAt();

The next request will be the same as above.

Count Alerts

Count alerts at Opsgenie.

OpsGenieClient client = new OpsGenieClient();

CountAlertsRequest request = new CountAlertsRequest();
request.setApiKey("39d50168-24b3-4355-b285-b91060823dee");

CountAlertsResponse response = client.alert().countAlerts(request);
int count = response.getCount();

List Alert Logs

Retrieves latest alert logs with given limit at Opsgenie. If limit is not set it retrieves latest 100 logs. 100 is also max log to be retrieved per request.

OpsGenieClient client = new OpsGenieClient();

ListAlertLogsRequest request = new ListAlertLogsRequest();
request.setId("3009c832-f578-42dd-8404-776b392da7b6");
request.setApiKey("51508352-1c40-4d6a-9625-ac80b4dbb972");
request.setSortOrder(ListAlertLogsRequest.SortOrder.asc);
request.setLimit(5);

ListAlertLogsResponse response = client.alert().listAlertLogs(request);
List<AlertLog> alertLogs = response.getAlertLogs();
String lastKey = response.getLastKey();

To make pagination while getting logs:

  1. Make the request above. Notice that "lastKey" value response returned. You will use it in the second request.
  2. Make a second request like above, but make sure you populate the new requests lastKey field with the lastKey you obtained from first request. request.setLastKey(lastKey);

List Alert Notes

Retrieves latest alert notes with given limit at Opsgenie. If limit is not set it retrieves latest 100 notes. 100 is also max note to be retrieved per request.

OpsGenieClient client = new OpsGenieClient();

ListAlertNotesRequest request = new ListAlertNotesRequest();
request.setId("3009c832-f578-42dd-8404-776b392da7b6");
request.setApiKey("51508352-1c40-4d6a-9625-ac80b4dbb972");
request.setSortOrder(ListAlertNotesRequest.SortOrder.asc);
request.setLimit(5);

ListAlertNotesResponse response = client.alert().listAlertNotes(request);
List<AlertNote> alertNotes = response.getAlertNotes();
String lastKey = response.getLastKey();

To make pagination while getting notes:

  1. Make the request above. Notice that "lastKey" value response returned. You will use it in the second request.
  2. Make a second request like above, but make sure you populate the new requests lastKey field with the lastKey you obtained from first request. request.setLastKey(lastKey);

List Alert Recipients

Retrieves recipients of the specified alert in Opsgenie

OpsGenieClient client = new OpsGenieClient();

ListAlertRecipientsRequest request = new ListAlertRecipientsRequest();
request.setId("3009c832-f578-42dd-8404-776b392da7b6");
request.setApiKey("39d50168-24b3-4355-b285-b91060823dee");
ListAlertRecipientsResponse response = client.alert().listAlertRecipients(request);
Map<String, List<AlertRecipient>> groups = response.getGroups();
List<AlertRecipient> users = response.getUsers();

Acknowledge

Acknowledges alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

AcknowledgeRequest request = new AcknowledgeRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
AcknowledgeResponse response = client.alert().acknowledge(request);
assert response.isSuccess();

Unacknowledge

Unacknowledges alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

UnAcknowledgeRequest request = new UnAcknowledgeRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
UnAcknowledgeResponse response = client.alert().unAcknowledge(request);
assert response.isSuccess();

Snooze Request

Snooze request is used to snooze alerts in Opsgenie.

OpsGenieClient client = new OpsGenieClient();
client.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");

SnoozeRequest request = new SnoozeRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
SnoozeResponse response = client.alert().snooze(request);
assert response.isSuccess();

Renotify

Renotifies the recipients about specified alert in Opsgenie

OpsGenieClient client = new OpsGenieClient();

RenotifyRequest request = new RenotifyRequest();
request.setId("3009c832-f578-42dd-8404-776b392da7b6");
request.setApiKey("39d50168-24b3-4355-b285-b91060823dee");
request.setSource("System");

List<RenotifyRecipient> recipients = new LinkedListRenotifyRecipient>();
RenotifyResponse response = client.alert().renotify(request);

Take Ownership

Takes the ownership of alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

TakeOwnershipRequest request = new TakeOwnershipRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
TakeOwnershipResponse response = client.alert().takeOwnership(request);
assert response.isSuccess();

Assign

Assigns the ownership of alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

AssignRequest request = new AssignRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
request.setOwner("[email protected]");
AssignResponse response = client.alert().assign(request);
assert response.isSuccess();

Add Alert Team

Add alert team request is used to add new teams to alerts in Opsgenie.

OpsGenieClient client = new OpsGenieClient();
client.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");

AddAlertTeamRequest request = new AddAlertTeamRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setTeam("operations");
request.setUser("[email protected]");
request.setNote("We should warn operations team.");
request.setSource("java sdk");
AddAlertTeamResponse response = client.alert().addTeam(request);
assert response.isSuccess();

Add Recipient

Adds a new recipient to an alert in Opsgenie

OpsGenieClient client = new OpsGenieClient();

AddRecipientRequest request = new AddRecipientRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
request.setRecipient("[email protected]");
AddRecipientResponse response = client.alert().addRecipient(request);
assert response.isSuccess();

Add Note

Add notes to alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

AddNoteRequest request = new AddNoteRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
request.setNote("We should find another solution.");
AddNoteResponse response = client.alert().addNote(request);
assert response.isSuccess();

Add Tags

Add tags to alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

AddTagsRequest request = new AddTagsRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
request.setNote("We should find another solution.");
List<String> tags = new ArrayList<String>();
tags.add("support");
request.setTags(tags);
AddTagsResponse response = client.alert().addTags(request);
assert response.isSuccess();

Remove Tags

Remove tags from alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

RemoveTagsRequest request = new RemoveTagsRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
request.setNote("We should find another solution.");
List<String> tags = new ArrayList<String>();
tags.add("support");
request.setTags(tags);
RemoveTagsResponse response = client.alert().removeTags(request);
assert response.isSuccess();

Add Details

Add details request is used to add properties to alert details in Opsgenie.

OpsGenieClient client = new OpsGenieClient();
client.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");

AddDetailsRequest request = new AddDetailsRequest();
Map details = new HashMap();
details.put("prop1", "val1");
details.put("prop2", "val2");
request.setDetails(details);
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
AddDetailsResponse response = client.alert().addDetails(request);
assert response.isSuccess();

Remove Details

Remove details request is used to remove properties from alert details in Opsgenie.

OpsGenieClient client = new OpsGenieClient();
client.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");

RemoveDetailsRequest request = new RemoveDetailsRequest();
List keys = new ArrayList();
keys.add("prop1");
keys.add("prop2");
request.setKeys(keys);
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
RemoveDetailsResponse response = client.alert().removeDetails(request);
assert response.isSuccess();

Execute Alert Action

Executes actions on alerts in Opsgenie

OpsGenieClient client = new OpsGenieClient();

ExecuteAlertActionRequest request = new ExecuteAlertActionRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
request.setAction("restartEntity");
ExecuteAlertActionResponse response = client.alert().executeAlertAction(request);
String result = response.getResult();

Attach

Attaches files to the alerts in Opsgenie.

OpsGenieClient client = new OpsGenieClient();

AttachRequest request = new AttachRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
request.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");
request.setUser("[email protected]");
request.setFile(new File("/home/john/performanceGraphs.zip"));
AttachResponse response = client.alert().attach(request);
assert response.isSuccess();

Escalate To Next Request

Escalate to Next request is used to immediately process the next available rule in the specified escalation.

OpsGenieClient client = new OpsGenieClient();
client.setApiKey("ab5454992-fabb2-4ba2-ad44f-1af65ds8b5c079");

EscalateToNextRequest request = new EscalateToNextRequest();
request.setId("29c4d6f6-0919-40ec-8d37-4ab2ed2042c8");
EscalateToNextResponse response = client.alert().escalateToNext(request);
assert response.isSuccess();

Updated 8 months ago


Deprecated Alert Actions


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.