Skip to content
Merged
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
42 changes: 31 additions & 11 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32305,15 +32305,23 @@ components:
properties:
recipients:
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
description: A list of recipients to notify. Uses the same format as the
monitor `message` field. Must not start with an '@'.
scope:
$ref: '#/components/schemas/MonitorNotificationRuleScope'
$ref: '#/components/schemas/MonitorNotificationRuleConditionScope'
required:
- scope
- recipients
type: object
MonitorNotificationRuleConditionScope:
description: The scope to which the monitor applied.
example: transition_type:alert
maxLength: 3000
minLength: 1
type: string
MonitorNotificationRuleConditionalRecipients:
description: Use conditional recipients to define different recipients for different
situations.
situations. Cannot be used with `recipients`.
properties:
conditions:
description: Conditions of the notification rule.
Expand Down Expand Up @@ -32363,12 +32371,30 @@ components:
description: Filter used to associate the notification rule with monitors.
oneOf:
- $ref: '#/components/schemas/MonitorNotificationRuleFilterTags'
- $ref: '#/components/schemas/MonitorNotificationRuleFilterScope'
MonitorNotificationRuleFilterScope:
additionalProperties: false
description: Filter monitor notifications. A monitor notification must match
the scope.
properties:
scope:
description: A scope composed of one or several key:value pairs, which can
be used to filter monitor notifications on monitor and group tags.
example: service:(foo OR bar) AND team:test NOT environment:staging
maxLength: 3000
minLength: 1
type: string
required:
- scope
type: object
MonitorNotificationRuleFilterTags:
additionalProperties: false
description: Filter monitors by tags. Monitors must match all tags.
description: Filter monitor notifications by tags. A monitor notification must
match all tags.
properties:
tags:
description: A list of monitor tags.
description: A list of tags (key:value pairs), which can be used to filter
monitor notifications on monitor and group tags.
example:
- team:product
- host:abc
Expand Down Expand Up @@ -32408,7 +32434,7 @@ components:
type: string
MonitorNotificationRuleRecipients:
description: A list of recipients to notify. Uses the same format as the monitor
`message` field. Must not start with an '@'.
`message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
example:
- slack-test-channel
- jira-test
Expand Down Expand Up @@ -32491,12 +32517,6 @@ components:
description: An object related to a monitor notification rule.
oneOf:
- $ref: '#/components/schemas/User'
MonitorNotificationRuleScope:
description: The scope to which the monitor applied.
example: transition_type:alert
maxLength: 3000
minLength: 1
type: string
MonitorNotificationRuleUpdateRequest:
description: Request for updating a monitor notification rule.
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Create a monitor notification rule with scope 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.MonitorNotificationRuleFilterScope;
import com.datadog.api.client.v2.model.MonitorNotificationRuleResourceType;
import com.datadog.api.client.v2.model.MonitorNotificationRuleResponse;
import java.util.Arrays;

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

MonitorNotificationRuleCreateRequest body =
new MonitorNotificationRuleCreateRequest()
.data(
new MonitorNotificationRuleCreateRequestData()
.attributes(
new MonitorNotificationRuleAttributes()
.filter(
new MonitorNotificationRuleFilter(
new MonitorNotificationRuleFilterScope()
.scope("test:example-monitor")))
.name("test rule")
.recipients(Arrays.asList("slack-test-channel", "jira-test")))
.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,50 @@
// Update a monitor notification rule with scope 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.MonitorNotificationRuleFilterScope;
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();
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 MonitorNotificationRuleFilterScope()
.scope("test:example-monitor")))
.name("updated rule")
.recipients(Collections.singletonList("slack-test-channel")))
.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 @@ -54,7 +54,8 @@ public MonitorNotificationRuleAttributes conditionalRecipients(
}

/**
* Use conditional recipients to define different recipients for different situations.
* Use conditional recipients to define different recipients for different situations. Cannot be
* used with <code>recipients</code>.
*
* @return conditionalRecipients
*/
Expand Down Expand Up @@ -127,7 +128,7 @@ public MonitorNotificationRuleAttributes addRecipientsItem(String recipientsItem

/**
* A list of recipients to notify. Uses the same format as the monitor <code>message</code> field.
* Must not start with an '@'.
* Must not start with an '@'. Cannot be used with <code>conditional_recipients</code>.
*
* @return recipients
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public MonitorNotificationRuleCondition addRecipientsItem(String recipientsItem)

/**
* A list of recipients to notify. Uses the same format as the monitor <code>message</code> field.
* Must not start with an '@'.
* Must not start with an '@'. Cannot be used with <code>conditional_recipients</code>.
*
* @return recipients
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import java.util.Map;
import java.util.Objects;

/** Use conditional recipients to define different recipients for different situations. */
/**
* Use conditional recipients to define different recipients for different situations. Cannot be
* used with <code>recipients</code>.
*/
@JsonPropertyOrder({
MonitorNotificationRuleConditionalRecipients.JSON_PROPERTY_CONDITIONS,
MonitorNotificationRuleConditionalRecipients.JSON_PROPERTY_FALLBACK_RECIPIENTS
Expand Down Expand Up @@ -91,7 +94,7 @@ public MonitorNotificationRuleConditionalRecipients addFallbackRecipientsItem(

/**
* A list of recipients to notify. Uses the same format as the monitor <code>message</code> field.
* Must not start with an '@'.
* Must not start with an '@'. Cannot be used with <code>conditional_recipients</code>.
*
* @return fallbackRecipients
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,54 @@ public MonitorNotificationRuleFilter deserialize(JsonParser jp, DeserializationC
Level.FINER, "Input data does not match schema 'MonitorNotificationRuleFilterTags'", e);
}

// deserialize MonitorNotificationRuleFilterScope
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
if (MonitorNotificationRuleFilterScope.class.equals(Integer.class)
|| MonitorNotificationRuleFilterScope.class.equals(Long.class)
|| MonitorNotificationRuleFilterScope.class.equals(Float.class)
|| MonitorNotificationRuleFilterScope.class.equals(Double.class)
|| MonitorNotificationRuleFilterScope.class.equals(Boolean.class)
|| MonitorNotificationRuleFilterScope.class.equals(String.class)) {
attemptParsing = typeCoercion;
if (!attemptParsing) {
attemptParsing |=
((MonitorNotificationRuleFilterScope.class.equals(Integer.class)
|| MonitorNotificationRuleFilterScope.class.equals(Long.class))
&& token == JsonToken.VALUE_NUMBER_INT);
attemptParsing |=
((MonitorNotificationRuleFilterScope.class.equals(Float.class)
|| MonitorNotificationRuleFilterScope.class.equals(Double.class))
&& (token == JsonToken.VALUE_NUMBER_FLOAT
|| token == JsonToken.VALUE_NUMBER_INT));
attemptParsing |=
(MonitorNotificationRuleFilterScope.class.equals(Boolean.class)
&& (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
attemptParsing |=
(MonitorNotificationRuleFilterScope.class.equals(String.class)
&& token == JsonToken.VALUE_STRING);
}
}
if (attemptParsing) {
tmp = tree.traverse(jp.getCodec()).readValueAs(MonitorNotificationRuleFilterScope.class);
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
if (!((MonitorNotificationRuleFilterScope) tmp).unparsed) {
deserialized = tmp;
match++;
}
log.log(Level.FINER, "Input data matches schema 'MonitorNotificationRuleFilterScope'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(
Level.FINER,
"Input data does not match schema 'MonitorNotificationRuleFilterScope'",
e);
}

MonitorNotificationRuleFilter ret = new MonitorNotificationRuleFilter();
if (match == 1) {
ret.setActualInstance(deserialized);
Expand Down Expand Up @@ -162,10 +210,18 @@ public MonitorNotificationRuleFilter(MonitorNotificationRuleFilterTags o) {
setActualInstance(o);
}

public MonitorNotificationRuleFilter(MonitorNotificationRuleFilterScope o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}

static {
schemas.put(
"MonitorNotificationRuleFilterTags",
new GenericType<MonitorNotificationRuleFilterTags>() {});
schemas.put(
"MonitorNotificationRuleFilterScope",
new GenericType<MonitorNotificationRuleFilterScope>() {});
JSON.registerDescendants(
MonitorNotificationRuleFilter.class, Collections.unmodifiableMap(schemas));
}
Expand All @@ -177,7 +233,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check the instance parameter is valid
* against the oneOf child schemas: MonitorNotificationRuleFilterTags
* against the oneOf child schemas: MonitorNotificationRuleFilterTags,
* MonitorNotificationRuleFilterScope
*
* <p>It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a
* composed schema (allOf, anyOf, oneOf).
Expand All @@ -189,18 +246,27 @@ public void setActualInstance(Object instance) {
super.setActualInstance(instance);
return;
}
if (JSON.isInstanceOf(
MonitorNotificationRuleFilterScope.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}

if (JSON.isInstanceOf(UnparsedObject.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}
throw new RuntimeException("Invalid instance type. Must be MonitorNotificationRuleFilterTags");
throw new RuntimeException(
"Invalid instance type. Must be MonitorNotificationRuleFilterTags,"
+ " MonitorNotificationRuleFilterScope");
}

/**
* Get the actual instance, which can be the following: MonitorNotificationRuleFilterTags
* Get the actual instance, which can be the following: MonitorNotificationRuleFilterTags,
* MonitorNotificationRuleFilterScope
*
* @return The actual instance (MonitorNotificationRuleFilterTags)
* @return The actual instance (MonitorNotificationRuleFilterTags,
* MonitorNotificationRuleFilterScope)
*/
@Override
public Object getActualInstance() {
Expand All @@ -218,4 +284,16 @@ public MonitorNotificationRuleFilterTags getMonitorNotificationRuleFilterTags()
throws ClassCastException {
return (MonitorNotificationRuleFilterTags) super.getActualInstance();
}

/**
* Get the actual instance of `MonitorNotificationRuleFilterScope`. If the actual instance is not
* `MonitorNotificationRuleFilterScope`, the ClassCastException will be thrown.
*
* @return The actual instance of `MonitorNotificationRuleFilterScope`
* @throws ClassCastException if the instance is not `MonitorNotificationRuleFilterScope`
*/
public MonitorNotificationRuleFilterScope getMonitorNotificationRuleFilterScope()
throws ClassCastException {
return (MonitorNotificationRuleFilterScope) super.getActualInstance();
}
}
Loading
Loading