Skip to content

Commit 065f528

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add Support for Monitor Assets (#1012)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 33d61f4 commit 065f528

15 files changed

+527
-11
lines changed

.generator/schemas/v1/openapi.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7255,6 +7255,12 @@ components:
72557255
Monitor:
72567256
description: Object describing a monitor.
72577257
properties:
7258+
assets:
7259+
description: The list of monitor assets tied to a monitor, which represents
7260+
key links for users to take action on monitor alerts (for example, runbooks).
7261+
items:
7262+
$ref: '#/components/schemas/MonitorAsset'
7263+
type: array
72587264
created:
72597265
description: Timestamp of the monitor creation.
72607266
format: date-time
@@ -7338,6 +7344,52 @@ components:
73387344
- type
73397345
- query
73407346
type: object
7347+
MonitorAsset:
7348+
description: 'Represents key links tied to a monitor to help users take action
7349+
on alerts.
7350+
7351+
This feature is in Preview and only available to users with the feature enabled.'
7352+
properties:
7353+
category:
7354+
$ref: '#/components/schemas/MonitorAssetCategory'
7355+
name:
7356+
description: Name for the monitor asset
7357+
example: Monitor Runbook
7358+
type: string
7359+
resource_key:
7360+
description: Represents the identifier of the internal Datadog resource
7361+
that this asset represents. IDs in this field should be passed in as strings.
7362+
example: '12345'
7363+
type: string
7364+
resource_type:
7365+
$ref: '#/components/schemas/MonitorAssetResourceType'
7366+
url:
7367+
description: URL link for the asset. For links with an internal resource
7368+
type set, this should be the relative path to where the Datadog domain
7369+
is appended internally. For external links, this should be the full URL
7370+
path.
7371+
example: /notebooks/12345
7372+
type: string
7373+
required:
7374+
- name
7375+
- url
7376+
- category
7377+
type: object
7378+
MonitorAssetCategory:
7379+
description: Indicates the type of asset this entity represents on a monitor.
7380+
enum:
7381+
- runbook
7382+
example: runbook
7383+
type: string
7384+
x-enum-varnames:
7385+
- RUNBOOK
7386+
MonitorAssetResourceType:
7387+
description: Type of internal Datadog resource associated with a monitor asset.
7388+
enum:
7389+
- notebook
7390+
type: string
7391+
x-enum-varnames:
7392+
- NOTEBOOK
73417393
MonitorDeviceID:
73427394
description: ID of the device the Synthetics monitor is running on. Same as
73437395
`SyntheticsDeviceID`.
@@ -8452,6 +8504,13 @@ components:
84528504
MonitorUpdateRequest:
84538505
description: Object describing a monitor update request.
84548506
properties:
8507+
assets:
8508+
description: The list of monitor assets tied to a monitor, which represents
8509+
key links for users to take action on monitor alerts (for example, runbooks).
8510+
items:
8511+
$ref: '#/components/schemas/MonitorAsset'
8512+
nullable: true
8513+
type: array
84558514
created:
84568515
description: Timestamp of the monitor creation.
84578516
format: date-time
@@ -31584,6 +31643,13 @@ paths:
3158431643
required: false
3158531644
schema:
3158631645
type: boolean
31646+
- description: If this argument is set to `true`, the returned data includes
31647+
all assets tied to this monitor.
31648+
in: query
31649+
name: with_assets
31650+
required: false
31651+
schema:
31652+
type: boolean
3158731653
responses:
3158831654
'200':
3158931655
content:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Create a monitor with assets returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_monitors::MonitorsAPI;
4+
use datadog_api_client::datadogV1::model::Monitor;
5+
use datadog_api_client::datadogV1::model::MonitorAsset;
6+
use datadog_api_client::datadogV1::model::MonitorAssetCategory;
7+
use datadog_api_client::datadogV1::model::MonitorAssetResourceType;
8+
use datadog_api_client::datadogV1::model::MonitorOptions;
9+
use datadog_api_client::datadogV1::model::MonitorOptionsSchedulingOptions;
10+
use datadog_api_client::datadogV1::model::MonitorOptionsSchedulingOptionsEvaluationWindow;
11+
use datadog_api_client::datadogV1::model::MonitorThresholds;
12+
use datadog_api_client::datadogV1::model::MonitorType;
13+
14+
#[tokio::main]
15+
async fn main() {
16+
let body = Monitor::new(
17+
"avg(current_1mo):avg:system.load.5{*} > 0.5".to_string(),
18+
MonitorType::METRIC_ALERT,
19+
)
20+
.assets(vec![MonitorAsset::new(
21+
MonitorAssetCategory::RUNBOOK,
22+
"Monitor Runbook".to_string(),
23+
"/notebooks/12345".to_string(),
24+
)
25+
.resource_key("12345".to_string())
26+
.resource_type(MonitorAssetResourceType::NOTEBOOK)])
27+
.message("some message Notify: @hipchat-channel".to_string())
28+
.name("Example-Monitor".to_string())
29+
.options(
30+
MonitorOptions::new()
31+
.scheduling_options(
32+
MonitorOptionsSchedulingOptions::new().evaluation_window(
33+
MonitorOptionsSchedulingOptionsEvaluationWindow::new()
34+
.day_starts("04:00".to_string())
35+
.month_starts(1),
36+
),
37+
)
38+
.thresholds(MonitorThresholds::new().critical(0.5 as f64)),
39+
);
40+
let configuration = datadog::Configuration::new();
41+
let api = MonitorsAPI::with_config(configuration);
42+
let resp = api.create_monitor(body).await;
43+
if let Ok(value) = resp {
44+
println!("{:#?}", value);
45+
} else {
46+
println!("{:#?}", resp.unwrap_err());
47+
}
48+
}

src/datadogV1/api/api_monitors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pub struct GetMonitorOptionalParams {
3636
pub group_states: Option<String>,
3737
/// If this argument is set to true, then the returned data includes all current active downtimes for the monitor.
3838
pub with_downtimes: Option<bool>,
39+
/// If this argument is set to `true`, the returned data includes all assets tied to this monitor.
40+
pub with_assets: Option<bool>,
3941
}
4042

4143
impl GetMonitorOptionalParams {
@@ -49,6 +51,11 @@ impl GetMonitorOptionalParams {
4951
self.with_downtimes = Some(value);
5052
self
5153
}
54+
/// If this argument is set to `true`, the returned data includes all assets tied to this monitor.
55+
pub fn with_assets(mut self, value: bool) -> Self {
56+
self.with_assets = Some(value);
57+
self
58+
}
5259
}
5360

5461
/// ListMonitorsOptionalParams is a struct for passing parameters to the method [`MonitorsAPI::list_monitors`]
@@ -1242,6 +1249,7 @@ impl MonitorsAPI {
12421249
// unbox and build optional parameters
12431250
let group_states = params.group_states;
12441251
let with_downtimes = params.with_downtimes;
1252+
let with_assets = params.with_assets;
12451253

12461254
let local_client = &self.client;
12471255

@@ -1261,6 +1269,10 @@ impl MonitorsAPI {
12611269
local_req_builder =
12621270
local_req_builder.query(&[("with_downtimes", &local_query_param.to_string())]);
12631271
};
1272+
if let Some(ref local_query_param) = with_assets {
1273+
local_req_builder =
1274+
local_req_builder.query(&[("with_assets", &local_query_param.to_string())]);
1275+
};
12641276

12651277
// build headers
12661278
let mut headers = HeaderMap::new();

src/datadogV1/model/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,12 @@ pub mod model_metric_metadata;
976976
pub use self::model_metric_metadata::MetricMetadata;
977977
pub mod model_monitor;
978978
pub use self::model_monitor::Monitor;
979+
pub mod model_monitor_asset;
980+
pub use self::model_monitor_asset::MonitorAsset;
981+
pub mod model_monitor_asset_category;
982+
pub use self::model_monitor_asset_category::MonitorAssetCategory;
983+
pub mod model_monitor_asset_resource_type;
984+
pub use self::model_monitor_asset_resource_type::MonitorAssetResourceType;
979985
pub mod model_monitor_draft_status;
980986
pub use self::model_monitor_draft_status::MonitorDraftStatus;
981987
pub mod model_matching_downtime;

src/datadogV1/model/model_monitor.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use std::fmt::{self, Formatter};
1111
#[skip_serializing_none]
1212
#[derive(Clone, Debug, PartialEq, Serialize)]
1313
pub struct Monitor {
14+
/// The list of monitor assets tied to a monitor, which represents key links for users to take action on monitor alerts (for example, runbooks).
15+
#[serde(rename = "assets")]
16+
pub assets: Option<Vec<crate::datadogV1::model::MonitorAsset>>,
1417
/// Timestamp of the monitor creation.
1518
#[serde(rename = "created")]
1619
pub created: Option<chrono::DateTime<chrono::Utc>>,
@@ -92,6 +95,7 @@ pub struct Monitor {
9295
impl Monitor {
9396
pub fn new(query: String, type_: crate::datadogV1::model::MonitorType) -> Monitor {
9497
Monitor {
98+
assets: None,
9599
created: None,
96100
creator: None,
97101
deleted: None,
@@ -115,6 +119,11 @@ impl Monitor {
115119
}
116120
}
117121

122+
pub fn assets(mut self, value: Vec<crate::datadogV1::model::MonitorAsset>) -> Self {
123+
self.assets = Some(value);
124+
self
125+
}
126+
118127
pub fn created(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
119128
self.created = Some(value);
120129
self
@@ -224,6 +233,7 @@ impl<'de> Deserialize<'de> for Monitor {
224233
where
225234
M: MapAccess<'a>,
226235
{
236+
let mut assets: Option<Vec<crate::datadogV1::model::MonitorAsset>> = None;
227237
let mut created: Option<chrono::DateTime<chrono::Utc>> = None;
228238
let mut creator: Option<crate::datadogV1::model::Creator> = None;
229239
let mut deleted: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
@@ -251,6 +261,12 @@ impl<'de> Deserialize<'de> for Monitor {
251261

252262
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
253263
match k.as_str() {
264+
"assets" => {
265+
if v.is_null() {
266+
continue;
267+
}
268+
assets = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
269+
}
254270
"created" => {
255271
if v.is_null() {
256272
continue;
@@ -387,6 +403,7 @@ impl<'de> Deserialize<'de> for Monitor {
387403
let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
388404

389405
let content = Monitor {
406+
assets,
390407
created,
391408
creator,
392409
deleted,

0 commit comments

Comments
 (0)