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
28 changes: 21 additions & 7 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32232,11 +32232,17 @@ components:
recipients:
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
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.
Expand Down Expand Up @@ -32289,6 +32295,20 @@ 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 monitors by scope. Monitors must match the scope evaluation.
properties:
scope:
description: The scope to which the monitor notification rule applies.
example: env:prod AND datacenter:us-east-1
maxLength: 3000
minLength: 1
type: string
required:
- scope
type: object
MonitorNotificationRuleFilterTags:
additionalProperties: false
description: Filter monitors by tags. Monitors must match all tags.
Expand Down Expand Up @@ -32417,12 +32437,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 @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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.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.Objects;

/** Filter monitors by scope. Monitors must match the scope evaluation. */
@JsonPropertyOrder({MonitorNotificationRuleFilterScope.JSON_PROPERTY_SCOPE})
@jakarta.annotation.Generated(
value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator")
public class MonitorNotificationRuleFilterScope {
@JsonIgnore public boolean unparsed = false;
public static final String JSON_PROPERTY_SCOPE = "scope";
private String scope;

public MonitorNotificationRuleFilterScope() {}

@JsonCreator
public MonitorNotificationRuleFilterScope(
@JsonProperty(required = true, value = JSON_PROPERTY_SCOPE) String scope) {
this.scope = scope;
}

public MonitorNotificationRuleFilterScope scope(String scope) {
this.scope = scope;
return this;
}

/**
* The scope to which the monitor notification rule applies.
*
* @return scope
*/
@JsonProperty(JSON_PROPERTY_SCOPE)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public String getScope() {
return scope;
}

public void setScope(String scope) {
this.scope = scope;
}

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

@Override
public int hashCode() {
return Objects.hash(scope);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class MonitorNotificationRuleFilterScope {\n");
sb.append(" scope: ").append(toIndentedString(scope)).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 ");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2025-11-11T21:28:39.129Z
Loading
Loading