Zerto Virtual Replication APIs : Alerts API : Code Examples
  
Code Examples
For complete code examples, see Code Samples.
/v1/alerts cURL Code Example
Retrieve the list of all alerts.
curl -D responseHeader -H "Content-Type: application/json" –H "Accept: application/json -H "x-zerto-session: 9UDQD6RG7YF33QJLWQXGJV8C453N277NA22P7FSNWVZCJTWCBRHQ" https://127.0.0.1:9669/v1/alerts
Dismiss a specific alert.
curl -D responseHeader -H "Content-Type: application/json" –H "Accept: application/json -H "x-zerto-session: 9UDQD6RG7YF33QJLWQXGJV8C453N277NA22P7FSNWVZCJTWCBRHQ" https://127.0.0.1:9669/v1/alerts/d00ea07a-9317-4ab6-a609-0a5fcbb04680/dismiss -d ""
This cURL command does not return any response. The -d "" is required so that cURL uses the POST method with this API.
For a more code examples, see cURL Code.
/v1/alerts C# Code Example
Retrieve all the alerts. For a full code example, including setting up a session, see C# Code.
/*
 * Example - get all alerts, filtering is not used
 */
private void GetAlerts() {
  Console.WriteLine("\nRequest the list of alerts:");
  Console.WriteLine("============================");
  string apiAddress = m_baseAddress + "alerts";
  string result = ExecuteHttpGet(apiAddress, m_format, m_sessionId);
  List<AlertApi> events = (List<AlertApi>)DeserializeObjectFromJson(result, typeof(List<AlertApi>));
  Console.WriteLine("Found " + alerts.Count + " alerts.");
  // Go Over all alerts fetching them one by one
  for (int i = 0;i < alerts.Count;i++) {
    Console.WriteLine((i+1) + ". " + alerts[i].Description);
  }
}
Dismiss all the alerts that are warning level and not error level
/*
 * Example - dismiss all the 'warning' level alerts that are not already dismissed
 */
private void DismissAllAlerts() {
  Console.WriteLine("\nDismiss all alerts that are warning level and not dismissed.");
  Console.WriteLine("===================================================");
  // Do Get fetch all alerts with certain filter
  string apiAddress = m_baseAddress + "alerts?isDismissed=false&level=Error";
  string result = ExecuteHttpGet(apiAddress, m_format, m_sessionId);
  // Deserialize response into zerto api object
  List<AlertApi> alerts = (List<AlertApi>)DeserializeObjectFromJson(result, typeof(List<AlertApi>));
  Console.WriteLine("Found " + alerts.Count + " alerts matching filter.");
  int count = 0;
  // Go Over all alerts fetch and dismiss them one by one
  foreach (var alert in alerts) {
    try {
      Console.WriteLine("Dismiss alert : " + alert.Description);
      string apiAlertAddress = m_baseAddress + "alerts/" + alert.Link.Identifier + "/dismiss";
      ExecuteHttpPost(apiAlertAddress, m_format, m_sessionId, null);
      count++;
    }
    catch (Exception e) {
      Console.WriteLine("error " + e.Message + ".");
    }
    Console.WriteLine("Dismissed " + count + " alerts.");
  }
}