Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83298,6 +83298,8 @@ components:
$ref: "#/components/schemas/MonitorNotificationRuleName"
recipients:
$ref: "#/components/schemas/MonitorNotificationRuleRecipients"
rule_options:
$ref: "#/components/schemas/MonitorNotificationRuleOptions"
required: [name]
type: object
MonitorNotificationRuleBundleConfig:
Expand Down Expand Up @@ -83438,6 +83440,17 @@ components:
maxLength: 1000
minLength: 1
type: string
MonitorNotificationRuleOptions:
description: Additional options for the monitor notification rule.
properties:
is_threaded:
description: |-
Whether notifications from this rule are threaded. When `true`, follow-up notifications for the same monitor alert are posted in Slack as replies to the first notification.
Cannot be `true` when `bundle_config` is set.
example: true
type: boolean
required: [is_threaded]
type: object
MonitorNotificationRuleRecipients:
description: |-
A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
Expand Down Expand Up @@ -83515,6 +83528,8 @@ components:
$ref: "#/components/schemas/MonitorNotificationRuleName"
recipients:
$ref: "#/components/schemas/MonitorNotificationRuleRecipients"
rule_options:
$ref: "#/components/schemas/MonitorNotificationRuleOptions"
type: object
MonitorNotificationRuleResponseIncludedItem:
description: An object related to a monitor notification rule.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Create a monitor notification rule with rule options returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.MonitorsApi;
import com.datadog.api.client.v2.model.MonitorNotificationRuleAttributes;
import com.datadog.api.client.v2.model.MonitorNotificationRuleCreateRequest;
import com.datadog.api.client.v2.model.MonitorNotificationRuleCreateRequestData;
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilter;
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilterTags;
import com.datadog.api.client.v2.model.MonitorNotificationRuleOptions;
import com.datadog.api.client.v2.model.MonitorNotificationRuleResourceType;
import com.datadog.api.client.v2.model.MonitorNotificationRuleResponse;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
MonitorsApi apiInstance = new MonitorsApi(defaultClient);

MonitorNotificationRuleCreateRequest body =
new MonitorNotificationRuleCreateRequest()
.data(
new MonitorNotificationRuleCreateRequestData()
.attributes(
new MonitorNotificationRuleAttributes()
.filter(
new MonitorNotificationRuleFilter(
new MonitorNotificationRuleFilterTags()
.tags(Collections.singletonList("test:example-monitor"))))
.name("test rule")
.recipients(Collections.singletonList("slack-test-channel"))
.ruleOptions(new MonitorNotificationRuleOptions().isThreaded(true)))
.type(MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE));

try {
MonitorNotificationRuleResponse result = apiInstance.createMonitorNotificationRule(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MonitorsApi#createMonitorNotificationRule");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Update a monitor notification rule with rule options returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.MonitorsApi;
import com.datadog.api.client.v2.model.MonitorNotificationRuleAttributes;
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilter;
import com.datadog.api.client.v2.model.MonitorNotificationRuleFilterTags;
import com.datadog.api.client.v2.model.MonitorNotificationRuleOptions;
import com.datadog.api.client.v2.model.MonitorNotificationRuleResourceType;
import com.datadog.api.client.v2.model.MonitorNotificationRuleResponse;
import com.datadog.api.client.v2.model.MonitorNotificationRuleUpdateRequest;
import com.datadog.api.client.v2.model.MonitorNotificationRuleUpdateRequestData;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
MonitorsApi apiInstance = new MonitorsApi(defaultClient);

// there is a valid "monitor_notification_rule" in the system
String MONITOR_NOTIFICATION_RULE_DATA_ID = System.getenv("MONITOR_NOTIFICATION_RULE_DATA_ID");

MonitorNotificationRuleUpdateRequest body =
new MonitorNotificationRuleUpdateRequest()
.data(
new MonitorNotificationRuleUpdateRequestData()
.attributes(
new MonitorNotificationRuleAttributes()
.filter(
new MonitorNotificationRuleFilter(
new MonitorNotificationRuleFilterTags()
.tags(Collections.singletonList("test:example-monitor"))))
.name("updated rule")
.recipients(Collections.singletonList("slack-test-channel"))
.ruleOptions(new MonitorNotificationRuleOptions().isThreaded(false)))
.id(MONITOR_NOTIFICATION_RULE_DATA_ID)
.type(MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE));

try {
MonitorNotificationRuleResponse result =
apiInstance.updateMonitorNotificationRule(MONITOR_NOTIFICATION_RULE_DATA_ID, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MonitorsApi#updateMonitorNotificationRule");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
MonitorNotificationRuleAttributes.JSON_PROPERTY_CONDITIONAL_RECIPIENTS,
MonitorNotificationRuleAttributes.JSON_PROPERTY_FILTER,
MonitorNotificationRuleAttributes.JSON_PROPERTY_NAME,
MonitorNotificationRuleAttributes.JSON_PROPERTY_RECIPIENTS
MonitorNotificationRuleAttributes.JSON_PROPERTY_RECIPIENTS,
MonitorNotificationRuleAttributes.JSON_PROPERTY_RULE_OPTIONS
})
@jakarta.annotation.Generated(
value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator")
Expand All @@ -42,6 +43,9 @@ public class MonitorNotificationRuleAttributes {
public static final String JSON_PROPERTY_RECIPIENTS = "recipients";
private List<String> recipients = null;

public static final String JSON_PROPERTY_RULE_OPTIONS = "rule_options";
private MonitorNotificationRuleOptions ruleOptions;

public MonitorNotificationRuleAttributes() {}

@JsonCreator
Expand Down Expand Up @@ -181,6 +185,31 @@ public void setRecipients(List<String> recipients) {
this.recipients = recipients;
}

public MonitorNotificationRuleAttributes ruleOptions(MonitorNotificationRuleOptions ruleOptions) {
this.ruleOptions = ruleOptions;
this.unparsed |= ruleOptions.unparsed;
return this;
}

/**
* Additional options for the monitor notification rule.
*
* @return ruleOptions
*/
@jakarta.annotation.Nullable
@JsonProperty(JSON_PROPERTY_RULE_OPTIONS)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public MonitorNotificationRuleOptions getRuleOptions() {
return ruleOptions;
}

public void setRuleOptions(MonitorNotificationRuleOptions ruleOptions) {
this.ruleOptions = ruleOptions;
if (ruleOptions != null) {
this.unparsed |= ruleOptions.unparsed;
}
}

/** Return true if this MonitorNotificationRuleAttributes object is equal to o. */
@Override
public boolean equals(Object o) {
Expand All @@ -197,12 +226,13 @@ public boolean equals(Object o) {
this.conditionalRecipients, monitorNotificationRuleAttributes.conditionalRecipients)
&& Objects.equals(this.filter, monitorNotificationRuleAttributes.filter)
&& Objects.equals(this.name, monitorNotificationRuleAttributes.name)
&& Objects.equals(this.recipients, monitorNotificationRuleAttributes.recipients);
&& Objects.equals(this.recipients, monitorNotificationRuleAttributes.recipients)
&& Objects.equals(this.ruleOptions, monitorNotificationRuleAttributes.ruleOptions);
}

@Override
public int hashCode() {
return Objects.hash(bundleConfig, conditionalRecipients, filter, name, recipients);
return Objects.hash(bundleConfig, conditionalRecipients, filter, name, recipients, ruleOptions);
}

@Override
Expand All @@ -216,6 +246,7 @@ public String toString() {
sb.append(" filter: ").append(toIndentedString(filter)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" recipients: ").append(toIndentedString(recipients)).append("\n");
sb.append(" ruleOptions: ").append(toIndentedString(ruleOptions)).append("\n");
sb.append('}');
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/

package com.datadog.api.client.v2.model;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/** Additional options for the monitor notification rule. */
@JsonPropertyOrder({MonitorNotificationRuleOptions.JSON_PROPERTY_IS_THREADED})
@jakarta.annotation.Generated(
value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator")
public class MonitorNotificationRuleOptions {
@JsonIgnore public boolean unparsed = false;
public static final String JSON_PROPERTY_IS_THREADED = "is_threaded";
private Boolean isThreaded;

public MonitorNotificationRuleOptions() {}

@JsonCreator
public MonitorNotificationRuleOptions(
@JsonProperty(required = true, value = JSON_PROPERTY_IS_THREADED) Boolean isThreaded) {
this.isThreaded = isThreaded;
}

public MonitorNotificationRuleOptions isThreaded(Boolean isThreaded) {
this.isThreaded = isThreaded;
return this;
}

/**
* Whether notifications from this rule are threaded. When <code>true</code>, follow-up
* notifications for the same monitor alert are posted in Slack as replies to the first
* notification. Cannot be <code>true</code> when <code>bundle_config</code> is set.
*
* @return isThreaded
*/
@JsonProperty(JSON_PROPERTY_IS_THREADED)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public Boolean getIsThreaded() {
return isThreaded;
}

public void setIsThreaded(Boolean isThreaded) {
this.isThreaded = isThreaded;
}

/**
* A container for additional, undeclared properties. This is a holder for any undeclared
* properties as specified with the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value. If the property
* does not already exist, create it otherwise replace it.
*
* @param key The arbitrary key to set
* @param value The associated value
* @return MonitorNotificationRuleOptions
*/
@JsonAnySetter
public MonitorNotificationRuleOptions putAdditionalProperty(String key, Object value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap<String, Object>();
}
this.additionalProperties.put(key, value);
return this;
}

/**
* Return the additional (undeclared) property.
*
* @return The additional properties
*/
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}

/**
* Return the additional (undeclared) property with the specified name.
*
* @param key The arbitrary key to get
* @return The specific additional property for the given key
*/
public Object getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
return this.additionalProperties.get(key);
}

/** Return true if this MonitorNotificationRuleOptions object is equal to o. */
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MonitorNotificationRuleOptions monitorNotificationRuleOptions =
(MonitorNotificationRuleOptions) o;
return Objects.equals(this.isThreaded, monitorNotificationRuleOptions.isThreaded)
&& Objects.equals(
this.additionalProperties, monitorNotificationRuleOptions.additionalProperties);
}

@Override
public int hashCode() {
return Objects.hash(isThreaded, additionalProperties);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class MonitorNotificationRuleOptions {\n");
sb.append(" isThreaded: ").append(toIndentedString(isThreaded)).append("\n");
sb.append(" additionalProperties: ")
.append(toIndentedString(additionalProperties))
.append("\n");
sb.append('}');
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
Loading
Loading