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
66 changes: 66 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7255,6 +7255,12 @@ components:
Monitor:
description: Object describing a monitor.
properties:
assets:
description: The list of monitor assets tied to a monitor, which represents
key links for users to take action on monitor alerts (for example, runbooks).
items:
$ref: '#/components/schemas/MonitorAsset'
type: array
created:
description: Timestamp of the monitor creation.
format: date-time
Expand Down Expand Up @@ -7338,6 +7344,52 @@ components:
- type
- query
type: object
MonitorAsset:
description: 'Represents key links tied to a monitor to help users take action
on alerts.

This feature is in Preview and only available to users with the feature enabled.'
properties:
category:
$ref: '#/components/schemas/MonitorAssetCategory'
name:
description: Name for the monitor asset
example: Monitor Runbook
type: string
resource_key:
description: Represents the identifier of the internal Datadog resource
that this asset represents. IDs in this field should be passed in as strings.
example: '12345'
type: string
resource_type:
$ref: '#/components/schemas/MonitorAssetResourceType'
url:
description: URL link for the asset. For links with an internal resource
type set, this should be the relative path to where the Datadog domain
is appended internally. For external links, this should be the full URL
path.
example: /notebooks/12345
type: string
required:
- name
- url
- category
type: object
MonitorAssetCategory:
description: Indicates the type of asset this entity represents on a monitor.
enum:
- runbook
example: runbook
type: string
x-enum-varnames:
- RUNBOOK
MonitorAssetResourceType:
description: Type of internal Datadog resource associated with a monitor asset.
enum:
- notebook
type: string
x-enum-varnames:
- NOTEBOOK
MonitorDeviceID:
description: ID of the device the Synthetics monitor is running on. Same as
`SyntheticsDeviceID`.
Expand Down Expand Up @@ -8452,6 +8504,13 @@ components:
MonitorUpdateRequest:
description: Object describing a monitor update request.
properties:
assets:
description: The list of monitor assets tied to a monitor, which represents
key links for users to take action on monitor alerts (for example, runbooks).
items:
$ref: '#/components/schemas/MonitorAsset'
nullable: true
type: array
created:
description: Timestamp of the monitor creation.
format: date-time
Expand Down Expand Up @@ -31584,6 +31643,13 @@ paths:
required: false
schema:
type: boolean
- description: If this argument is set to `true`, the returned data includes
all assets tied to this monitor.
in: query
name: with_assets
required: false
schema:
type: boolean
responses:
'200':
content:
Expand Down
48 changes: 48 additions & 0 deletions examples/v1_monitors_CreateMonitor_3541766733.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Create a monitor with assets returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_monitors::MonitorsAPI;
use datadog_api_client::datadogV1::model::Monitor;
use datadog_api_client::datadogV1::model::MonitorAsset;
use datadog_api_client::datadogV1::model::MonitorAssetCategory;
use datadog_api_client::datadogV1::model::MonitorAssetResourceType;
use datadog_api_client::datadogV1::model::MonitorOptions;
use datadog_api_client::datadogV1::model::MonitorOptionsSchedulingOptions;
use datadog_api_client::datadogV1::model::MonitorOptionsSchedulingOptionsEvaluationWindow;
use datadog_api_client::datadogV1::model::MonitorThresholds;
use datadog_api_client::datadogV1::model::MonitorType;

#[tokio::main]
async fn main() {
let body = Monitor::new(
"avg(current_1mo):avg:system.load.5{*} > 0.5".to_string(),
MonitorType::METRIC_ALERT,
)
.assets(vec![MonitorAsset::new(
MonitorAssetCategory::RUNBOOK,
"Monitor Runbook".to_string(),
"/notebooks/12345".to_string(),
)
.resource_key("12345".to_string())
.resource_type(MonitorAssetResourceType::NOTEBOOK)])
.message("some message Notify: @hipchat-channel".to_string())
.name("Example-Monitor".to_string())
.options(
MonitorOptions::new()
.scheduling_options(
MonitorOptionsSchedulingOptions::new().evaluation_window(
MonitorOptionsSchedulingOptionsEvaluationWindow::new()
.day_starts("04:00".to_string())
.month_starts(1),
),
)
.thresholds(MonitorThresholds::new().critical(0.5 as f64)),
);
let configuration = datadog::Configuration::new();
let api = MonitorsAPI::with_config(configuration);
let resp = api.create_monitor(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
12 changes: 12 additions & 0 deletions src/datadogV1/api/api_monitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct GetMonitorOptionalParams {
pub group_states: Option<String>,
/// If this argument is set to true, then the returned data includes all current active downtimes for the monitor.
pub with_downtimes: Option<bool>,
/// If this argument is set to `true`, the returned data includes all assets tied to this monitor.
pub with_assets: Option<bool>,
}

impl GetMonitorOptionalParams {
Expand All @@ -49,6 +51,11 @@ impl GetMonitorOptionalParams {
self.with_downtimes = Some(value);
self
}
/// If this argument is set to `true`, the returned data includes all assets tied to this monitor.
pub fn with_assets(mut self, value: bool) -> Self {
self.with_assets = Some(value);
self
}
}

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

let local_client = &self.client;

Expand All @@ -1261,6 +1269,10 @@ impl MonitorsAPI {
local_req_builder =
local_req_builder.query(&[("with_downtimes", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = with_assets {
local_req_builder =
local_req_builder.query(&[("with_assets", &local_query_param.to_string())]);
};

// build headers
let mut headers = HeaderMap::new();
Expand Down
6 changes: 6 additions & 0 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,12 @@ pub mod model_metric_metadata;
pub use self::model_metric_metadata::MetricMetadata;
pub mod model_monitor;
pub use self::model_monitor::Monitor;
pub mod model_monitor_asset;
pub use self::model_monitor_asset::MonitorAsset;
pub mod model_monitor_asset_category;
pub use self::model_monitor_asset_category::MonitorAssetCategory;
pub mod model_monitor_asset_resource_type;
pub use self::model_monitor_asset_resource_type::MonitorAssetResourceType;
pub mod model_monitor_draft_status;
pub use self::model_monitor_draft_status::MonitorDraftStatus;
pub mod model_matching_downtime;
Expand Down
17 changes: 17 additions & 0 deletions src/datadogV1/model/model_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use std::fmt::{self, Formatter};
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct Monitor {
/// The list of monitor assets tied to a monitor, which represents key links for users to take action on monitor alerts (for example, runbooks).
#[serde(rename = "assets")]
pub assets: Option<Vec<crate::datadogV1::model::MonitorAsset>>,
/// Timestamp of the monitor creation.
#[serde(rename = "created")]
pub created: Option<chrono::DateTime<chrono::Utc>>,
Expand Down Expand Up @@ -92,6 +95,7 @@ pub struct Monitor {
impl Monitor {
pub fn new(query: String, type_: crate::datadogV1::model::MonitorType) -> Monitor {
Monitor {
assets: None,
created: None,
creator: None,
deleted: None,
Expand All @@ -115,6 +119,11 @@ impl Monitor {
}
}

pub fn assets(mut self, value: Vec<crate::datadogV1::model::MonitorAsset>) -> Self {
self.assets = Some(value);
self
}

pub fn created(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.created = Some(value);
self
Expand Down Expand Up @@ -224,6 +233,7 @@ impl<'de> Deserialize<'de> for Monitor {
where
M: MapAccess<'a>,
{
let mut assets: Option<Vec<crate::datadogV1::model::MonitorAsset>> = None;
let mut created: Option<chrono::DateTime<chrono::Utc>> = None;
let mut creator: Option<crate::datadogV1::model::Creator> = None;
let mut deleted: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
Expand Down Expand Up @@ -251,6 +261,12 @@ impl<'de> Deserialize<'de> for Monitor {

while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"assets" => {
if v.is_null() {
continue;
}
assets = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"created" => {
if v.is_null() {
continue;
Expand Down Expand Up @@ -387,6 +403,7 @@ impl<'de> Deserialize<'de> for Monitor {
let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;

let content = Monitor {
assets,
created,
creator,
deleted,
Expand Down
Loading