1use crate::datadog;
5use flate2::{
6 write::{GzEncoder, ZlibEncoder},
7 Compression,
8};
9use log::warn;
10use reqwest::header::{HeaderMap, HeaderValue};
11use serde::{Deserialize, Serialize};
12use std::io::Write;
13
14#[non_exhaustive]
16#[derive(Clone, Default, Debug)]
17pub struct GetMonitorNotificationRuleOptionalParams {
18 pub include: Option<String>,
21}
22
23impl GetMonitorNotificationRuleOptionalParams {
24 pub fn include(mut self, value: String) -> Self {
27 self.include = Some(value);
28 self
29 }
30}
31
32#[non_exhaustive]
34#[derive(Clone, Default, Debug)]
35pub struct GetMonitorNotificationRulesOptionalParams {
36 pub page: Option<i32>,
38 pub per_page: Option<i32>,
40 pub sort: Option<String>,
42 pub filters: Option<String>,
47 pub include: Option<String>,
50}
51
52impl GetMonitorNotificationRulesOptionalParams {
53 pub fn page(mut self, value: i32) -> Self {
55 self.page = Some(value);
56 self
57 }
58 pub fn per_page(mut self, value: i32) -> Self {
60 self.per_page = Some(value);
61 self
62 }
63 pub fn sort(mut self, value: String) -> Self {
65 self.sort = Some(value);
66 self
67 }
68 pub fn filters(mut self, value: String) -> Self {
73 self.filters = Some(value);
74 self
75 }
76 pub fn include(mut self, value: String) -> Self {
79 self.include = Some(value);
80 self
81 }
82}
83
84#[non_exhaustive]
86#[derive(Clone, Default, Debug)]
87pub struct GetMonitorUserTemplateOptionalParams {
88 pub with_all_versions: Option<bool>,
90}
91
92impl GetMonitorUserTemplateOptionalParams {
93 pub fn with_all_versions(mut self, value: bool) -> Self {
95 self.with_all_versions = Some(value);
96 self
97 }
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum CreateMonitorConfigPolicyError {
104 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
105 UnknownValue(serde_json::Value),
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum CreateMonitorNotificationRuleError {
112 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
113 UnknownValue(serde_json::Value),
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum CreateMonitorUserTemplateError {
120 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
121 UnknownValue(serde_json::Value),
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
126#[serde(untagged)]
127pub enum DeleteMonitorConfigPolicyError {
128 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
129 UnknownValue(serde_json::Value),
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
134#[serde(untagged)]
135pub enum DeleteMonitorNotificationRuleError {
136 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
137 UnknownValue(serde_json::Value),
138}
139
140#[derive(Debug, Clone, Serialize, Deserialize)]
142#[serde(untagged)]
143pub enum DeleteMonitorUserTemplateError {
144 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
145 UnknownValue(serde_json::Value),
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize)]
150#[serde(untagged)]
151pub enum GetMonitorConfigPolicyError {
152 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
153 UnknownValue(serde_json::Value),
154}
155
156#[derive(Debug, Clone, Serialize, Deserialize)]
158#[serde(untagged)]
159pub enum GetMonitorNotificationRuleError {
160 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
161 UnknownValue(serde_json::Value),
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize)]
166#[serde(untagged)]
167pub enum GetMonitorNotificationRulesError {
168 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
169 UnknownValue(serde_json::Value),
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize)]
174#[serde(untagged)]
175pub enum GetMonitorUserTemplateError {
176 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
177 UnknownValue(serde_json::Value),
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum ListMonitorConfigPoliciesError {
184 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
185 UnknownValue(serde_json::Value),
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190#[serde(untagged)]
191pub enum ListMonitorUserTemplatesError {
192 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
193 UnknownValue(serde_json::Value),
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum UpdateMonitorConfigPolicyError {
200 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
201 UnknownValue(serde_json::Value),
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize)]
206#[serde(untagged)]
207pub enum UpdateMonitorNotificationRuleError {
208 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
209 UnknownValue(serde_json::Value),
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize)]
214#[serde(untagged)]
215pub enum UpdateMonitorUserTemplateError {
216 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
217 UnknownValue(serde_json::Value),
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
222#[serde(untagged)]
223pub enum ValidateExistingMonitorUserTemplateError {
224 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
225 UnknownValue(serde_json::Value),
226}
227
228#[derive(Debug, Clone, Serialize, Deserialize)]
230#[serde(untagged)]
231pub enum ValidateMonitorUserTemplateError {
232 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
233 UnknownValue(serde_json::Value),
234}
235
236#[derive(Debug, Clone)]
242pub struct MonitorsAPI {
243 config: datadog::Configuration,
244 client: reqwest_middleware::ClientWithMiddleware,
245}
246
247impl Default for MonitorsAPI {
248 fn default() -> Self {
249 Self::with_config(datadog::Configuration::default())
250 }
251}
252
253impl MonitorsAPI {
254 pub fn new() -> Self {
255 Self::default()
256 }
257 pub fn with_config(config: datadog::Configuration) -> Self {
258 let mut reqwest_client_builder = reqwest::Client::builder();
259
260 if let Some(proxy_url) = &config.proxy_url {
261 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
262 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
263 }
264
265 let mut middleware_client_builder =
266 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
267
268 if config.enable_retry {
269 struct RetryableStatus;
270 impl reqwest_retry::RetryableStrategy for RetryableStatus {
271 fn handle(
272 &self,
273 res: &Result<reqwest::Response, reqwest_middleware::Error>,
274 ) -> Option<reqwest_retry::Retryable> {
275 match res {
276 Ok(success) => reqwest_retry::default_on_request_success(success),
277 Err(_) => None,
278 }
279 }
280 }
281 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
282 .build_with_max_retries(config.max_retries);
283
284 let retry_middleware =
285 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
286 backoff_policy,
287 RetryableStatus,
288 );
289
290 middleware_client_builder = middleware_client_builder.with(retry_middleware);
291 }
292
293 let client = middleware_client_builder.build();
294
295 Self { config, client }
296 }
297
298 pub fn with_client_and_config(
299 config: datadog::Configuration,
300 client: reqwest_middleware::ClientWithMiddleware,
301 ) -> Self {
302 Self { config, client }
303 }
304
305 pub async fn create_monitor_config_policy(
307 &self,
308 body: crate::datadogV2::model::MonitorConfigPolicyCreateRequest,
309 ) -> Result<
310 crate::datadogV2::model::MonitorConfigPolicyResponse,
311 datadog::Error<CreateMonitorConfigPolicyError>,
312 > {
313 match self.create_monitor_config_policy_with_http_info(body).await {
314 Ok(response_content) => {
315 if let Some(e) = response_content.entity {
316 Ok(e)
317 } else {
318 Err(datadog::Error::Serde(serde::de::Error::custom(
319 "response content was None",
320 )))
321 }
322 }
323 Err(err) => Err(err),
324 }
325 }
326
327 pub async fn create_monitor_config_policy_with_http_info(
329 &self,
330 body: crate::datadogV2::model::MonitorConfigPolicyCreateRequest,
331 ) -> Result<
332 datadog::ResponseContent<crate::datadogV2::model::MonitorConfigPolicyResponse>,
333 datadog::Error<CreateMonitorConfigPolicyError>,
334 > {
335 let local_configuration = &self.config;
336 let operation_id = "v2.create_monitor_config_policy";
337
338 let local_client = &self.client;
339
340 let local_uri_str = format!(
341 "{}/api/v2/monitor/policy",
342 local_configuration.get_operation_host(operation_id)
343 );
344 let mut local_req_builder =
345 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
346
347 let mut headers = HeaderMap::new();
349 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
350 headers.insert("Accept", HeaderValue::from_static("application/json"));
351
352 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
354 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
355 Err(e) => {
356 log::warn!("Failed to parse user agent header: {e}, falling back to default");
357 headers.insert(
358 reqwest::header::USER_AGENT,
359 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
360 )
361 }
362 };
363
364 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
366 headers.insert(
367 "DD-API-KEY",
368 HeaderValue::from_str(local_key.key.as_str())
369 .expect("failed to parse DD-API-KEY header"),
370 );
371 };
372 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
373 headers.insert(
374 "DD-APPLICATION-KEY",
375 HeaderValue::from_str(local_key.key.as_str())
376 .expect("failed to parse DD-APPLICATION-KEY header"),
377 );
378 };
379
380 let output = Vec::new();
382 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
383 if body.serialize(&mut ser).is_ok() {
384 if let Some(content_encoding) = headers.get("Content-Encoding") {
385 match content_encoding.to_str().unwrap_or_default() {
386 "gzip" => {
387 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
388 let _ = enc.write_all(ser.into_inner().as_slice());
389 match enc.finish() {
390 Ok(buf) => {
391 local_req_builder = local_req_builder.body(buf);
392 }
393 Err(e) => return Err(datadog::Error::Io(e)),
394 }
395 }
396 "deflate" => {
397 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
398 let _ = enc.write_all(ser.into_inner().as_slice());
399 match enc.finish() {
400 Ok(buf) => {
401 local_req_builder = local_req_builder.body(buf);
402 }
403 Err(e) => return Err(datadog::Error::Io(e)),
404 }
405 }
406 "zstd1" => {
407 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
408 let _ = enc.write_all(ser.into_inner().as_slice());
409 match enc.finish() {
410 Ok(buf) => {
411 local_req_builder = local_req_builder.body(buf);
412 }
413 Err(e) => return Err(datadog::Error::Io(e)),
414 }
415 }
416 _ => {
417 local_req_builder = local_req_builder.body(ser.into_inner());
418 }
419 }
420 } else {
421 local_req_builder = local_req_builder.body(ser.into_inner());
422 }
423 }
424
425 local_req_builder = local_req_builder.headers(headers);
426 let local_req = local_req_builder.build()?;
427 log::debug!("request content: {:?}", local_req.body());
428 let local_resp = local_client.execute(local_req).await?;
429
430 let local_status = local_resp.status();
431 let local_content = local_resp.text().await?;
432 log::debug!("response content: {}", local_content);
433
434 if !local_status.is_client_error() && !local_status.is_server_error() {
435 match serde_json::from_str::<crate::datadogV2::model::MonitorConfigPolicyResponse>(
436 &local_content,
437 ) {
438 Ok(e) => {
439 return Ok(datadog::ResponseContent {
440 status: local_status,
441 content: local_content,
442 entity: Some(e),
443 })
444 }
445 Err(e) => return Err(datadog::Error::Serde(e)),
446 };
447 } else {
448 let local_entity: Option<CreateMonitorConfigPolicyError> =
449 serde_json::from_str(&local_content).ok();
450 let local_error = datadog::ResponseContent {
451 status: local_status,
452 content: local_content,
453 entity: local_entity,
454 };
455 Err(datadog::Error::ResponseError(local_error))
456 }
457 }
458
459 pub async fn create_monitor_notification_rule(
461 &self,
462 body: crate::datadogV2::model::MonitorNotificationRuleCreateRequest,
463 ) -> Result<
464 crate::datadogV2::model::MonitorNotificationRuleResponse,
465 datadog::Error<CreateMonitorNotificationRuleError>,
466 > {
467 match self
468 .create_monitor_notification_rule_with_http_info(body)
469 .await
470 {
471 Ok(response_content) => {
472 if let Some(e) = response_content.entity {
473 Ok(e)
474 } else {
475 Err(datadog::Error::Serde(serde::de::Error::custom(
476 "response content was None",
477 )))
478 }
479 }
480 Err(err) => Err(err),
481 }
482 }
483
484 pub async fn create_monitor_notification_rule_with_http_info(
486 &self,
487 body: crate::datadogV2::model::MonitorNotificationRuleCreateRequest,
488 ) -> Result<
489 datadog::ResponseContent<crate::datadogV2::model::MonitorNotificationRuleResponse>,
490 datadog::Error<CreateMonitorNotificationRuleError>,
491 > {
492 let local_configuration = &self.config;
493 let operation_id = "v2.create_monitor_notification_rule";
494
495 let local_client = &self.client;
496
497 let local_uri_str = format!(
498 "{}/api/v2/monitor/notification_rule",
499 local_configuration.get_operation_host(operation_id)
500 );
501 let mut local_req_builder =
502 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
503
504 let mut headers = HeaderMap::new();
506 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
507 headers.insert("Accept", HeaderValue::from_static("application/json"));
508
509 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
511 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
512 Err(e) => {
513 log::warn!("Failed to parse user agent header: {e}, falling back to default");
514 headers.insert(
515 reqwest::header::USER_AGENT,
516 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
517 )
518 }
519 };
520
521 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
523 headers.insert(
524 "DD-API-KEY",
525 HeaderValue::from_str(local_key.key.as_str())
526 .expect("failed to parse DD-API-KEY header"),
527 );
528 };
529 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
530 headers.insert(
531 "DD-APPLICATION-KEY",
532 HeaderValue::from_str(local_key.key.as_str())
533 .expect("failed to parse DD-APPLICATION-KEY header"),
534 );
535 };
536
537 let output = Vec::new();
539 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
540 if body.serialize(&mut ser).is_ok() {
541 if let Some(content_encoding) = headers.get("Content-Encoding") {
542 match content_encoding.to_str().unwrap_or_default() {
543 "gzip" => {
544 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
545 let _ = enc.write_all(ser.into_inner().as_slice());
546 match enc.finish() {
547 Ok(buf) => {
548 local_req_builder = local_req_builder.body(buf);
549 }
550 Err(e) => return Err(datadog::Error::Io(e)),
551 }
552 }
553 "deflate" => {
554 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
555 let _ = enc.write_all(ser.into_inner().as_slice());
556 match enc.finish() {
557 Ok(buf) => {
558 local_req_builder = local_req_builder.body(buf);
559 }
560 Err(e) => return Err(datadog::Error::Io(e)),
561 }
562 }
563 "zstd1" => {
564 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
565 let _ = enc.write_all(ser.into_inner().as_slice());
566 match enc.finish() {
567 Ok(buf) => {
568 local_req_builder = local_req_builder.body(buf);
569 }
570 Err(e) => return Err(datadog::Error::Io(e)),
571 }
572 }
573 _ => {
574 local_req_builder = local_req_builder.body(ser.into_inner());
575 }
576 }
577 } else {
578 local_req_builder = local_req_builder.body(ser.into_inner());
579 }
580 }
581
582 local_req_builder = local_req_builder.headers(headers);
583 let local_req = local_req_builder.build()?;
584 log::debug!("request content: {:?}", local_req.body());
585 let local_resp = local_client.execute(local_req).await?;
586
587 let local_status = local_resp.status();
588 let local_content = local_resp.text().await?;
589 log::debug!("response content: {}", local_content);
590
591 if !local_status.is_client_error() && !local_status.is_server_error() {
592 match serde_json::from_str::<crate::datadogV2::model::MonitorNotificationRuleResponse>(
593 &local_content,
594 ) {
595 Ok(e) => {
596 return Ok(datadog::ResponseContent {
597 status: local_status,
598 content: local_content,
599 entity: Some(e),
600 })
601 }
602 Err(e) => return Err(datadog::Error::Serde(e)),
603 };
604 } else {
605 let local_entity: Option<CreateMonitorNotificationRuleError> =
606 serde_json::from_str(&local_content).ok();
607 let local_error = datadog::ResponseContent {
608 status: local_status,
609 content: local_content,
610 entity: local_entity,
611 };
612 Err(datadog::Error::ResponseError(local_error))
613 }
614 }
615
616 pub async fn create_monitor_user_template(
618 &self,
619 body: crate::datadogV2::model::MonitorUserTemplateCreateRequest,
620 ) -> Result<
621 crate::datadogV2::model::MonitorUserTemplateCreateResponse,
622 datadog::Error<CreateMonitorUserTemplateError>,
623 > {
624 match self.create_monitor_user_template_with_http_info(body).await {
625 Ok(response_content) => {
626 if let Some(e) = response_content.entity {
627 Ok(e)
628 } else {
629 Err(datadog::Error::Serde(serde::de::Error::custom(
630 "response content was None",
631 )))
632 }
633 }
634 Err(err) => Err(err),
635 }
636 }
637
638 pub async fn create_monitor_user_template_with_http_info(
640 &self,
641 body: crate::datadogV2::model::MonitorUserTemplateCreateRequest,
642 ) -> Result<
643 datadog::ResponseContent<crate::datadogV2::model::MonitorUserTemplateCreateResponse>,
644 datadog::Error<CreateMonitorUserTemplateError>,
645 > {
646 let local_configuration = &self.config;
647 let operation_id = "v2.create_monitor_user_template";
648 if local_configuration.is_unstable_operation_enabled(operation_id) {
649 warn!("Using unstable operation {operation_id}");
650 } else {
651 let local_error = datadog::UnstableOperationDisabledError {
652 msg: "Operation 'v2.create_monitor_user_template' is not enabled".to_string(),
653 };
654 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
655 }
656
657 let local_client = &self.client;
658
659 let local_uri_str = format!(
660 "{}/api/v2/monitor/template",
661 local_configuration.get_operation_host(operation_id)
662 );
663 let mut local_req_builder =
664 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
665
666 let mut headers = HeaderMap::new();
668 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
669 headers.insert("Accept", HeaderValue::from_static("application/json"));
670
671 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
673 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
674 Err(e) => {
675 log::warn!("Failed to parse user agent header: {e}, falling back to default");
676 headers.insert(
677 reqwest::header::USER_AGENT,
678 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
679 )
680 }
681 };
682
683 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
685 headers.insert(
686 "DD-API-KEY",
687 HeaderValue::from_str(local_key.key.as_str())
688 .expect("failed to parse DD-API-KEY header"),
689 );
690 };
691 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
692 headers.insert(
693 "DD-APPLICATION-KEY",
694 HeaderValue::from_str(local_key.key.as_str())
695 .expect("failed to parse DD-APPLICATION-KEY header"),
696 );
697 };
698
699 let output = Vec::new();
701 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
702 if body.serialize(&mut ser).is_ok() {
703 if let Some(content_encoding) = headers.get("Content-Encoding") {
704 match content_encoding.to_str().unwrap_or_default() {
705 "gzip" => {
706 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
707 let _ = enc.write_all(ser.into_inner().as_slice());
708 match enc.finish() {
709 Ok(buf) => {
710 local_req_builder = local_req_builder.body(buf);
711 }
712 Err(e) => return Err(datadog::Error::Io(e)),
713 }
714 }
715 "deflate" => {
716 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
717 let _ = enc.write_all(ser.into_inner().as_slice());
718 match enc.finish() {
719 Ok(buf) => {
720 local_req_builder = local_req_builder.body(buf);
721 }
722 Err(e) => return Err(datadog::Error::Io(e)),
723 }
724 }
725 "zstd1" => {
726 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
727 let _ = enc.write_all(ser.into_inner().as_slice());
728 match enc.finish() {
729 Ok(buf) => {
730 local_req_builder = local_req_builder.body(buf);
731 }
732 Err(e) => return Err(datadog::Error::Io(e)),
733 }
734 }
735 _ => {
736 local_req_builder = local_req_builder.body(ser.into_inner());
737 }
738 }
739 } else {
740 local_req_builder = local_req_builder.body(ser.into_inner());
741 }
742 }
743
744 local_req_builder = local_req_builder.headers(headers);
745 let local_req = local_req_builder.build()?;
746 log::debug!("request content: {:?}", local_req.body());
747 let local_resp = local_client.execute(local_req).await?;
748
749 let local_status = local_resp.status();
750 let local_content = local_resp.text().await?;
751 log::debug!("response content: {}", local_content);
752
753 if !local_status.is_client_error() && !local_status.is_server_error() {
754 match serde_json::from_str::<crate::datadogV2::model::MonitorUserTemplateCreateResponse>(
755 &local_content,
756 ) {
757 Ok(e) => {
758 return Ok(datadog::ResponseContent {
759 status: local_status,
760 content: local_content,
761 entity: Some(e),
762 })
763 }
764 Err(e) => return Err(datadog::Error::Serde(e)),
765 };
766 } else {
767 let local_entity: Option<CreateMonitorUserTemplateError> =
768 serde_json::from_str(&local_content).ok();
769 let local_error = datadog::ResponseContent {
770 status: local_status,
771 content: local_content,
772 entity: local_entity,
773 };
774 Err(datadog::Error::ResponseError(local_error))
775 }
776 }
777
778 pub async fn delete_monitor_config_policy(
780 &self,
781 policy_id: String,
782 ) -> Result<(), datadog::Error<DeleteMonitorConfigPolicyError>> {
783 match self
784 .delete_monitor_config_policy_with_http_info(policy_id)
785 .await
786 {
787 Ok(_) => Ok(()),
788 Err(err) => Err(err),
789 }
790 }
791
792 pub async fn delete_monitor_config_policy_with_http_info(
794 &self,
795 policy_id: String,
796 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteMonitorConfigPolicyError>> {
797 let local_configuration = &self.config;
798 let operation_id = "v2.delete_monitor_config_policy";
799
800 let local_client = &self.client;
801
802 let local_uri_str = format!(
803 "{}/api/v2/monitor/policy/{policy_id}",
804 local_configuration.get_operation_host(operation_id),
805 policy_id = datadog::urlencode(policy_id)
806 );
807 let mut local_req_builder =
808 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
809
810 let mut headers = HeaderMap::new();
812 headers.insert("Accept", HeaderValue::from_static("*/*"));
813
814 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
816 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
817 Err(e) => {
818 log::warn!("Failed to parse user agent header: {e}, falling back to default");
819 headers.insert(
820 reqwest::header::USER_AGENT,
821 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
822 )
823 }
824 };
825
826 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
828 headers.insert(
829 "DD-API-KEY",
830 HeaderValue::from_str(local_key.key.as_str())
831 .expect("failed to parse DD-API-KEY header"),
832 );
833 };
834 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
835 headers.insert(
836 "DD-APPLICATION-KEY",
837 HeaderValue::from_str(local_key.key.as_str())
838 .expect("failed to parse DD-APPLICATION-KEY header"),
839 );
840 };
841
842 local_req_builder = local_req_builder.headers(headers);
843 let local_req = local_req_builder.build()?;
844 log::debug!("request content: {:?}", local_req.body());
845 let local_resp = local_client.execute(local_req).await?;
846
847 let local_status = local_resp.status();
848 let local_content = local_resp.text().await?;
849 log::debug!("response content: {}", local_content);
850
851 if !local_status.is_client_error() && !local_status.is_server_error() {
852 Ok(datadog::ResponseContent {
853 status: local_status,
854 content: local_content,
855 entity: None,
856 })
857 } else {
858 let local_entity: Option<DeleteMonitorConfigPolicyError> =
859 serde_json::from_str(&local_content).ok();
860 let local_error = datadog::ResponseContent {
861 status: local_status,
862 content: local_content,
863 entity: local_entity,
864 };
865 Err(datadog::Error::ResponseError(local_error))
866 }
867 }
868
869 pub async fn delete_monitor_notification_rule(
871 &self,
872 rule_id: String,
873 ) -> Result<(), datadog::Error<DeleteMonitorNotificationRuleError>> {
874 match self
875 .delete_monitor_notification_rule_with_http_info(rule_id)
876 .await
877 {
878 Ok(_) => Ok(()),
879 Err(err) => Err(err),
880 }
881 }
882
883 pub async fn delete_monitor_notification_rule_with_http_info(
885 &self,
886 rule_id: String,
887 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteMonitorNotificationRuleError>>
888 {
889 let local_configuration = &self.config;
890 let operation_id = "v2.delete_monitor_notification_rule";
891
892 let local_client = &self.client;
893
894 let local_uri_str = format!(
895 "{}/api/v2/monitor/notification_rule/{rule_id}",
896 local_configuration.get_operation_host(operation_id),
897 rule_id = datadog::urlencode(rule_id)
898 );
899 let mut local_req_builder =
900 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
901
902 let mut headers = HeaderMap::new();
904 headers.insert("Accept", HeaderValue::from_static("*/*"));
905
906 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
908 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
909 Err(e) => {
910 log::warn!("Failed to parse user agent header: {e}, falling back to default");
911 headers.insert(
912 reqwest::header::USER_AGENT,
913 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
914 )
915 }
916 };
917
918 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
920 headers.insert(
921 "DD-API-KEY",
922 HeaderValue::from_str(local_key.key.as_str())
923 .expect("failed to parse DD-API-KEY header"),
924 );
925 };
926 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
927 headers.insert(
928 "DD-APPLICATION-KEY",
929 HeaderValue::from_str(local_key.key.as_str())
930 .expect("failed to parse DD-APPLICATION-KEY header"),
931 );
932 };
933
934 local_req_builder = local_req_builder.headers(headers);
935 let local_req = local_req_builder.build()?;
936 log::debug!("request content: {:?}", local_req.body());
937 let local_resp = local_client.execute(local_req).await?;
938
939 let local_status = local_resp.status();
940 let local_content = local_resp.text().await?;
941 log::debug!("response content: {}", local_content);
942
943 if !local_status.is_client_error() && !local_status.is_server_error() {
944 Ok(datadog::ResponseContent {
945 status: local_status,
946 content: local_content,
947 entity: None,
948 })
949 } else {
950 let local_entity: Option<DeleteMonitorNotificationRuleError> =
951 serde_json::from_str(&local_content).ok();
952 let local_error = datadog::ResponseContent {
953 status: local_status,
954 content: local_content,
955 entity: local_entity,
956 };
957 Err(datadog::Error::ResponseError(local_error))
958 }
959 }
960
961 pub async fn delete_monitor_user_template(
963 &self,
964 template_id: String,
965 ) -> Result<(), datadog::Error<DeleteMonitorUserTemplateError>> {
966 match self
967 .delete_monitor_user_template_with_http_info(template_id)
968 .await
969 {
970 Ok(_) => Ok(()),
971 Err(err) => Err(err),
972 }
973 }
974
975 pub async fn delete_monitor_user_template_with_http_info(
977 &self,
978 template_id: String,
979 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteMonitorUserTemplateError>> {
980 let local_configuration = &self.config;
981 let operation_id = "v2.delete_monitor_user_template";
982 if local_configuration.is_unstable_operation_enabled(operation_id) {
983 warn!("Using unstable operation {operation_id}");
984 } else {
985 let local_error = datadog::UnstableOperationDisabledError {
986 msg: "Operation 'v2.delete_monitor_user_template' is not enabled".to_string(),
987 };
988 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
989 }
990
991 let local_client = &self.client;
992
993 let local_uri_str = format!(
994 "{}/api/v2/monitor/template/{template_id}",
995 local_configuration.get_operation_host(operation_id),
996 template_id = datadog::urlencode(template_id)
997 );
998 let mut local_req_builder =
999 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1000
1001 let mut headers = HeaderMap::new();
1003 headers.insert("Accept", HeaderValue::from_static("*/*"));
1004
1005 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1007 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1008 Err(e) => {
1009 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1010 headers.insert(
1011 reqwest::header::USER_AGENT,
1012 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1013 )
1014 }
1015 };
1016
1017 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1019 headers.insert(
1020 "DD-API-KEY",
1021 HeaderValue::from_str(local_key.key.as_str())
1022 .expect("failed to parse DD-API-KEY header"),
1023 );
1024 };
1025 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1026 headers.insert(
1027 "DD-APPLICATION-KEY",
1028 HeaderValue::from_str(local_key.key.as_str())
1029 .expect("failed to parse DD-APPLICATION-KEY header"),
1030 );
1031 };
1032
1033 local_req_builder = local_req_builder.headers(headers);
1034 let local_req = local_req_builder.build()?;
1035 log::debug!("request content: {:?}", local_req.body());
1036 let local_resp = local_client.execute(local_req).await?;
1037
1038 let local_status = local_resp.status();
1039 let local_content = local_resp.text().await?;
1040 log::debug!("response content: {}", local_content);
1041
1042 if !local_status.is_client_error() && !local_status.is_server_error() {
1043 Ok(datadog::ResponseContent {
1044 status: local_status,
1045 content: local_content,
1046 entity: None,
1047 })
1048 } else {
1049 let local_entity: Option<DeleteMonitorUserTemplateError> =
1050 serde_json::from_str(&local_content).ok();
1051 let local_error = datadog::ResponseContent {
1052 status: local_status,
1053 content: local_content,
1054 entity: local_entity,
1055 };
1056 Err(datadog::Error::ResponseError(local_error))
1057 }
1058 }
1059
1060 pub async fn get_monitor_config_policy(
1062 &self,
1063 policy_id: String,
1064 ) -> Result<
1065 crate::datadogV2::model::MonitorConfigPolicyResponse,
1066 datadog::Error<GetMonitorConfigPolicyError>,
1067 > {
1068 match self
1069 .get_monitor_config_policy_with_http_info(policy_id)
1070 .await
1071 {
1072 Ok(response_content) => {
1073 if let Some(e) = response_content.entity {
1074 Ok(e)
1075 } else {
1076 Err(datadog::Error::Serde(serde::de::Error::custom(
1077 "response content was None",
1078 )))
1079 }
1080 }
1081 Err(err) => Err(err),
1082 }
1083 }
1084
1085 pub async fn get_monitor_config_policy_with_http_info(
1087 &self,
1088 policy_id: String,
1089 ) -> Result<
1090 datadog::ResponseContent<crate::datadogV2::model::MonitorConfigPolicyResponse>,
1091 datadog::Error<GetMonitorConfigPolicyError>,
1092 > {
1093 let local_configuration = &self.config;
1094 let operation_id = "v2.get_monitor_config_policy";
1095
1096 let local_client = &self.client;
1097
1098 let local_uri_str = format!(
1099 "{}/api/v2/monitor/policy/{policy_id}",
1100 local_configuration.get_operation_host(operation_id),
1101 policy_id = datadog::urlencode(policy_id)
1102 );
1103 let mut local_req_builder =
1104 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1105
1106 let mut headers = HeaderMap::new();
1108 headers.insert("Accept", HeaderValue::from_static("application/json"));
1109
1110 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1112 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1113 Err(e) => {
1114 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1115 headers.insert(
1116 reqwest::header::USER_AGENT,
1117 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1118 )
1119 }
1120 };
1121
1122 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1124 headers.insert(
1125 "DD-API-KEY",
1126 HeaderValue::from_str(local_key.key.as_str())
1127 .expect("failed to parse DD-API-KEY header"),
1128 );
1129 };
1130 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1131 headers.insert(
1132 "DD-APPLICATION-KEY",
1133 HeaderValue::from_str(local_key.key.as_str())
1134 .expect("failed to parse DD-APPLICATION-KEY header"),
1135 );
1136 };
1137
1138 local_req_builder = local_req_builder.headers(headers);
1139 let local_req = local_req_builder.build()?;
1140 log::debug!("request content: {:?}", local_req.body());
1141 let local_resp = local_client.execute(local_req).await?;
1142
1143 let local_status = local_resp.status();
1144 let local_content = local_resp.text().await?;
1145 log::debug!("response content: {}", local_content);
1146
1147 if !local_status.is_client_error() && !local_status.is_server_error() {
1148 match serde_json::from_str::<crate::datadogV2::model::MonitorConfigPolicyResponse>(
1149 &local_content,
1150 ) {
1151 Ok(e) => {
1152 return Ok(datadog::ResponseContent {
1153 status: local_status,
1154 content: local_content,
1155 entity: Some(e),
1156 })
1157 }
1158 Err(e) => return Err(datadog::Error::Serde(e)),
1159 };
1160 } else {
1161 let local_entity: Option<GetMonitorConfigPolicyError> =
1162 serde_json::from_str(&local_content).ok();
1163 let local_error = datadog::ResponseContent {
1164 status: local_status,
1165 content: local_content,
1166 entity: local_entity,
1167 };
1168 Err(datadog::Error::ResponseError(local_error))
1169 }
1170 }
1171
1172 pub async fn get_monitor_notification_rule(
1174 &self,
1175 rule_id: String,
1176 params: GetMonitorNotificationRuleOptionalParams,
1177 ) -> Result<
1178 crate::datadogV2::model::MonitorNotificationRuleResponse,
1179 datadog::Error<GetMonitorNotificationRuleError>,
1180 > {
1181 match self
1182 .get_monitor_notification_rule_with_http_info(rule_id, params)
1183 .await
1184 {
1185 Ok(response_content) => {
1186 if let Some(e) = response_content.entity {
1187 Ok(e)
1188 } else {
1189 Err(datadog::Error::Serde(serde::de::Error::custom(
1190 "response content was None",
1191 )))
1192 }
1193 }
1194 Err(err) => Err(err),
1195 }
1196 }
1197
1198 pub async fn get_monitor_notification_rule_with_http_info(
1200 &self,
1201 rule_id: String,
1202 params: GetMonitorNotificationRuleOptionalParams,
1203 ) -> Result<
1204 datadog::ResponseContent<crate::datadogV2::model::MonitorNotificationRuleResponse>,
1205 datadog::Error<GetMonitorNotificationRuleError>,
1206 > {
1207 let local_configuration = &self.config;
1208 let operation_id = "v2.get_monitor_notification_rule";
1209
1210 let include = params.include;
1212
1213 let local_client = &self.client;
1214
1215 let local_uri_str = format!(
1216 "{}/api/v2/monitor/notification_rule/{rule_id}",
1217 local_configuration.get_operation_host(operation_id),
1218 rule_id = datadog::urlencode(rule_id)
1219 );
1220 let mut local_req_builder =
1221 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1222
1223 if let Some(ref local_query_param) = include {
1224 local_req_builder =
1225 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1226 };
1227
1228 let mut headers = HeaderMap::new();
1230 headers.insert("Accept", HeaderValue::from_static("application/json"));
1231
1232 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1234 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1235 Err(e) => {
1236 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1237 headers.insert(
1238 reqwest::header::USER_AGENT,
1239 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1240 )
1241 }
1242 };
1243
1244 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1246 headers.insert(
1247 "DD-API-KEY",
1248 HeaderValue::from_str(local_key.key.as_str())
1249 .expect("failed to parse DD-API-KEY header"),
1250 );
1251 };
1252 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1253 headers.insert(
1254 "DD-APPLICATION-KEY",
1255 HeaderValue::from_str(local_key.key.as_str())
1256 .expect("failed to parse DD-APPLICATION-KEY header"),
1257 );
1258 };
1259
1260 local_req_builder = local_req_builder.headers(headers);
1261 let local_req = local_req_builder.build()?;
1262 log::debug!("request content: {:?}", local_req.body());
1263 let local_resp = local_client.execute(local_req).await?;
1264
1265 let local_status = local_resp.status();
1266 let local_content = local_resp.text().await?;
1267 log::debug!("response content: {}", local_content);
1268
1269 if !local_status.is_client_error() && !local_status.is_server_error() {
1270 match serde_json::from_str::<crate::datadogV2::model::MonitorNotificationRuleResponse>(
1271 &local_content,
1272 ) {
1273 Ok(e) => {
1274 return Ok(datadog::ResponseContent {
1275 status: local_status,
1276 content: local_content,
1277 entity: Some(e),
1278 })
1279 }
1280 Err(e) => return Err(datadog::Error::Serde(e)),
1281 };
1282 } else {
1283 let local_entity: Option<GetMonitorNotificationRuleError> =
1284 serde_json::from_str(&local_content).ok();
1285 let local_error = datadog::ResponseContent {
1286 status: local_status,
1287 content: local_content,
1288 entity: local_entity,
1289 };
1290 Err(datadog::Error::ResponseError(local_error))
1291 }
1292 }
1293
1294 pub async fn get_monitor_notification_rules(
1296 &self,
1297 params: GetMonitorNotificationRulesOptionalParams,
1298 ) -> Result<
1299 crate::datadogV2::model::MonitorNotificationRuleListResponse,
1300 datadog::Error<GetMonitorNotificationRulesError>,
1301 > {
1302 match self
1303 .get_monitor_notification_rules_with_http_info(params)
1304 .await
1305 {
1306 Ok(response_content) => {
1307 if let Some(e) = response_content.entity {
1308 Ok(e)
1309 } else {
1310 Err(datadog::Error::Serde(serde::de::Error::custom(
1311 "response content was None",
1312 )))
1313 }
1314 }
1315 Err(err) => Err(err),
1316 }
1317 }
1318
1319 pub async fn get_monitor_notification_rules_with_http_info(
1321 &self,
1322 params: GetMonitorNotificationRulesOptionalParams,
1323 ) -> Result<
1324 datadog::ResponseContent<crate::datadogV2::model::MonitorNotificationRuleListResponse>,
1325 datadog::Error<GetMonitorNotificationRulesError>,
1326 > {
1327 let local_configuration = &self.config;
1328 let operation_id = "v2.get_monitor_notification_rules";
1329
1330 let page = params.page;
1332 let per_page = params.per_page;
1333 let sort = params.sort;
1334 let filters = params.filters;
1335 let include = params.include;
1336
1337 let local_client = &self.client;
1338
1339 let local_uri_str = format!(
1340 "{}/api/v2/monitor/notification_rule",
1341 local_configuration.get_operation_host(operation_id)
1342 );
1343 let mut local_req_builder =
1344 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1345
1346 if let Some(ref local_query_param) = page {
1347 local_req_builder =
1348 local_req_builder.query(&[("page", &local_query_param.to_string())]);
1349 };
1350 if let Some(ref local_query_param) = per_page {
1351 local_req_builder =
1352 local_req_builder.query(&[("per_page", &local_query_param.to_string())]);
1353 };
1354 if let Some(ref local_query_param) = sort {
1355 local_req_builder =
1356 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
1357 };
1358 if let Some(ref local_query_param) = filters {
1359 local_req_builder =
1360 local_req_builder.query(&[("filters", &local_query_param.to_string())]);
1361 };
1362 if let Some(ref local_query_param) = include {
1363 local_req_builder =
1364 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1365 };
1366
1367 let mut headers = HeaderMap::new();
1369 headers.insert("Accept", HeaderValue::from_static("application/json"));
1370
1371 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1373 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1374 Err(e) => {
1375 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1376 headers.insert(
1377 reqwest::header::USER_AGENT,
1378 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1379 )
1380 }
1381 };
1382
1383 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1385 headers.insert(
1386 "DD-API-KEY",
1387 HeaderValue::from_str(local_key.key.as_str())
1388 .expect("failed to parse DD-API-KEY header"),
1389 );
1390 };
1391 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1392 headers.insert(
1393 "DD-APPLICATION-KEY",
1394 HeaderValue::from_str(local_key.key.as_str())
1395 .expect("failed to parse DD-APPLICATION-KEY header"),
1396 );
1397 };
1398
1399 local_req_builder = local_req_builder.headers(headers);
1400 let local_req = local_req_builder.build()?;
1401 log::debug!("request content: {:?}", local_req.body());
1402 let local_resp = local_client.execute(local_req).await?;
1403
1404 let local_status = local_resp.status();
1405 let local_content = local_resp.text().await?;
1406 log::debug!("response content: {}", local_content);
1407
1408 if !local_status.is_client_error() && !local_status.is_server_error() {
1409 match serde_json::from_str::<crate::datadogV2::model::MonitorNotificationRuleListResponse>(
1410 &local_content,
1411 ) {
1412 Ok(e) => {
1413 return Ok(datadog::ResponseContent {
1414 status: local_status,
1415 content: local_content,
1416 entity: Some(e),
1417 })
1418 }
1419 Err(e) => return Err(datadog::Error::Serde(e)),
1420 };
1421 } else {
1422 let local_entity: Option<GetMonitorNotificationRulesError> =
1423 serde_json::from_str(&local_content).ok();
1424 let local_error = datadog::ResponseContent {
1425 status: local_status,
1426 content: local_content,
1427 entity: local_entity,
1428 };
1429 Err(datadog::Error::ResponseError(local_error))
1430 }
1431 }
1432
1433 pub async fn get_monitor_user_template(
1435 &self,
1436 template_id: String,
1437 params: GetMonitorUserTemplateOptionalParams,
1438 ) -> Result<
1439 crate::datadogV2::model::MonitorUserTemplateResponse,
1440 datadog::Error<GetMonitorUserTemplateError>,
1441 > {
1442 match self
1443 .get_monitor_user_template_with_http_info(template_id, params)
1444 .await
1445 {
1446 Ok(response_content) => {
1447 if let Some(e) = response_content.entity {
1448 Ok(e)
1449 } else {
1450 Err(datadog::Error::Serde(serde::de::Error::custom(
1451 "response content was None",
1452 )))
1453 }
1454 }
1455 Err(err) => Err(err),
1456 }
1457 }
1458
1459 pub async fn get_monitor_user_template_with_http_info(
1461 &self,
1462 template_id: String,
1463 params: GetMonitorUserTemplateOptionalParams,
1464 ) -> Result<
1465 datadog::ResponseContent<crate::datadogV2::model::MonitorUserTemplateResponse>,
1466 datadog::Error<GetMonitorUserTemplateError>,
1467 > {
1468 let local_configuration = &self.config;
1469 let operation_id = "v2.get_monitor_user_template";
1470 if local_configuration.is_unstable_operation_enabled(operation_id) {
1471 warn!("Using unstable operation {operation_id}");
1472 } else {
1473 let local_error = datadog::UnstableOperationDisabledError {
1474 msg: "Operation 'v2.get_monitor_user_template' is not enabled".to_string(),
1475 };
1476 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1477 }
1478
1479 let with_all_versions = params.with_all_versions;
1481
1482 let local_client = &self.client;
1483
1484 let local_uri_str = format!(
1485 "{}/api/v2/monitor/template/{template_id}",
1486 local_configuration.get_operation_host(operation_id),
1487 template_id = datadog::urlencode(template_id)
1488 );
1489 let mut local_req_builder =
1490 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1491
1492 if let Some(ref local_query_param) = with_all_versions {
1493 local_req_builder =
1494 local_req_builder.query(&[("with_all_versions", &local_query_param.to_string())]);
1495 };
1496
1497 let mut headers = HeaderMap::new();
1499 headers.insert("Accept", HeaderValue::from_static("application/json"));
1500
1501 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1503 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1504 Err(e) => {
1505 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1506 headers.insert(
1507 reqwest::header::USER_AGENT,
1508 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1509 )
1510 }
1511 };
1512
1513 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1515 headers.insert(
1516 "DD-API-KEY",
1517 HeaderValue::from_str(local_key.key.as_str())
1518 .expect("failed to parse DD-API-KEY header"),
1519 );
1520 };
1521 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1522 headers.insert(
1523 "DD-APPLICATION-KEY",
1524 HeaderValue::from_str(local_key.key.as_str())
1525 .expect("failed to parse DD-APPLICATION-KEY header"),
1526 );
1527 };
1528
1529 local_req_builder = local_req_builder.headers(headers);
1530 let local_req = local_req_builder.build()?;
1531 log::debug!("request content: {:?}", local_req.body());
1532 let local_resp = local_client.execute(local_req).await?;
1533
1534 let local_status = local_resp.status();
1535 let local_content = local_resp.text().await?;
1536 log::debug!("response content: {}", local_content);
1537
1538 if !local_status.is_client_error() && !local_status.is_server_error() {
1539 match serde_json::from_str::<crate::datadogV2::model::MonitorUserTemplateResponse>(
1540 &local_content,
1541 ) {
1542 Ok(e) => {
1543 return Ok(datadog::ResponseContent {
1544 status: local_status,
1545 content: local_content,
1546 entity: Some(e),
1547 })
1548 }
1549 Err(e) => return Err(datadog::Error::Serde(e)),
1550 };
1551 } else {
1552 let local_entity: Option<GetMonitorUserTemplateError> =
1553 serde_json::from_str(&local_content).ok();
1554 let local_error = datadog::ResponseContent {
1555 status: local_status,
1556 content: local_content,
1557 entity: local_entity,
1558 };
1559 Err(datadog::Error::ResponseError(local_error))
1560 }
1561 }
1562
1563 pub async fn list_monitor_config_policies(
1565 &self,
1566 ) -> Result<
1567 crate::datadogV2::model::MonitorConfigPolicyListResponse,
1568 datadog::Error<ListMonitorConfigPoliciesError>,
1569 > {
1570 match self.list_monitor_config_policies_with_http_info().await {
1571 Ok(response_content) => {
1572 if let Some(e) = response_content.entity {
1573 Ok(e)
1574 } else {
1575 Err(datadog::Error::Serde(serde::de::Error::custom(
1576 "response content was None",
1577 )))
1578 }
1579 }
1580 Err(err) => Err(err),
1581 }
1582 }
1583
1584 pub async fn list_monitor_config_policies_with_http_info(
1586 &self,
1587 ) -> Result<
1588 datadog::ResponseContent<crate::datadogV2::model::MonitorConfigPolicyListResponse>,
1589 datadog::Error<ListMonitorConfigPoliciesError>,
1590 > {
1591 let local_configuration = &self.config;
1592 let operation_id = "v2.list_monitor_config_policies";
1593
1594 let local_client = &self.client;
1595
1596 let local_uri_str = format!(
1597 "{}/api/v2/monitor/policy",
1598 local_configuration.get_operation_host(operation_id)
1599 );
1600 let mut local_req_builder =
1601 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1602
1603 let mut headers = HeaderMap::new();
1605 headers.insert("Accept", HeaderValue::from_static("application/json"));
1606
1607 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1609 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1610 Err(e) => {
1611 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1612 headers.insert(
1613 reqwest::header::USER_AGENT,
1614 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1615 )
1616 }
1617 };
1618
1619 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1621 headers.insert(
1622 "DD-API-KEY",
1623 HeaderValue::from_str(local_key.key.as_str())
1624 .expect("failed to parse DD-API-KEY header"),
1625 );
1626 };
1627 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1628 headers.insert(
1629 "DD-APPLICATION-KEY",
1630 HeaderValue::from_str(local_key.key.as_str())
1631 .expect("failed to parse DD-APPLICATION-KEY header"),
1632 );
1633 };
1634
1635 local_req_builder = local_req_builder.headers(headers);
1636 let local_req = local_req_builder.build()?;
1637 log::debug!("request content: {:?}", local_req.body());
1638 let local_resp = local_client.execute(local_req).await?;
1639
1640 let local_status = local_resp.status();
1641 let local_content = local_resp.text().await?;
1642 log::debug!("response content: {}", local_content);
1643
1644 if !local_status.is_client_error() && !local_status.is_server_error() {
1645 match serde_json::from_str::<crate::datadogV2::model::MonitorConfigPolicyListResponse>(
1646 &local_content,
1647 ) {
1648 Ok(e) => {
1649 return Ok(datadog::ResponseContent {
1650 status: local_status,
1651 content: local_content,
1652 entity: Some(e),
1653 })
1654 }
1655 Err(e) => return Err(datadog::Error::Serde(e)),
1656 };
1657 } else {
1658 let local_entity: Option<ListMonitorConfigPoliciesError> =
1659 serde_json::from_str(&local_content).ok();
1660 let local_error = datadog::ResponseContent {
1661 status: local_status,
1662 content: local_content,
1663 entity: local_entity,
1664 };
1665 Err(datadog::Error::ResponseError(local_error))
1666 }
1667 }
1668
1669 pub async fn list_monitor_user_templates(
1671 &self,
1672 ) -> Result<
1673 crate::datadogV2::model::MonitorUserTemplateListResponse,
1674 datadog::Error<ListMonitorUserTemplatesError>,
1675 > {
1676 match self.list_monitor_user_templates_with_http_info().await {
1677 Ok(response_content) => {
1678 if let Some(e) = response_content.entity {
1679 Ok(e)
1680 } else {
1681 Err(datadog::Error::Serde(serde::de::Error::custom(
1682 "response content was None",
1683 )))
1684 }
1685 }
1686 Err(err) => Err(err),
1687 }
1688 }
1689
1690 pub async fn list_monitor_user_templates_with_http_info(
1692 &self,
1693 ) -> Result<
1694 datadog::ResponseContent<crate::datadogV2::model::MonitorUserTemplateListResponse>,
1695 datadog::Error<ListMonitorUserTemplatesError>,
1696 > {
1697 let local_configuration = &self.config;
1698 let operation_id = "v2.list_monitor_user_templates";
1699 if local_configuration.is_unstable_operation_enabled(operation_id) {
1700 warn!("Using unstable operation {operation_id}");
1701 } else {
1702 let local_error = datadog::UnstableOperationDisabledError {
1703 msg: "Operation 'v2.list_monitor_user_templates' is not enabled".to_string(),
1704 };
1705 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1706 }
1707
1708 let local_client = &self.client;
1709
1710 let local_uri_str = format!(
1711 "{}/api/v2/monitor/template",
1712 local_configuration.get_operation_host(operation_id)
1713 );
1714 let mut local_req_builder =
1715 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1716
1717 let mut headers = HeaderMap::new();
1719 headers.insert("Accept", HeaderValue::from_static("application/json"));
1720
1721 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1723 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1724 Err(e) => {
1725 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1726 headers.insert(
1727 reqwest::header::USER_AGENT,
1728 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1729 )
1730 }
1731 };
1732
1733 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1735 headers.insert(
1736 "DD-API-KEY",
1737 HeaderValue::from_str(local_key.key.as_str())
1738 .expect("failed to parse DD-API-KEY header"),
1739 );
1740 };
1741 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1742 headers.insert(
1743 "DD-APPLICATION-KEY",
1744 HeaderValue::from_str(local_key.key.as_str())
1745 .expect("failed to parse DD-APPLICATION-KEY header"),
1746 );
1747 };
1748
1749 local_req_builder = local_req_builder.headers(headers);
1750 let local_req = local_req_builder.build()?;
1751 log::debug!("request content: {:?}", local_req.body());
1752 let local_resp = local_client.execute(local_req).await?;
1753
1754 let local_status = local_resp.status();
1755 let local_content = local_resp.text().await?;
1756 log::debug!("response content: {}", local_content);
1757
1758 if !local_status.is_client_error() && !local_status.is_server_error() {
1759 match serde_json::from_str::<crate::datadogV2::model::MonitorUserTemplateListResponse>(
1760 &local_content,
1761 ) {
1762 Ok(e) => {
1763 return Ok(datadog::ResponseContent {
1764 status: local_status,
1765 content: local_content,
1766 entity: Some(e),
1767 })
1768 }
1769 Err(e) => return Err(datadog::Error::Serde(e)),
1770 };
1771 } else {
1772 let local_entity: Option<ListMonitorUserTemplatesError> =
1773 serde_json::from_str(&local_content).ok();
1774 let local_error = datadog::ResponseContent {
1775 status: local_status,
1776 content: local_content,
1777 entity: local_entity,
1778 };
1779 Err(datadog::Error::ResponseError(local_error))
1780 }
1781 }
1782
1783 pub async fn update_monitor_config_policy(
1785 &self,
1786 policy_id: String,
1787 body: crate::datadogV2::model::MonitorConfigPolicyEditRequest,
1788 ) -> Result<
1789 crate::datadogV2::model::MonitorConfigPolicyResponse,
1790 datadog::Error<UpdateMonitorConfigPolicyError>,
1791 > {
1792 match self
1793 .update_monitor_config_policy_with_http_info(policy_id, body)
1794 .await
1795 {
1796 Ok(response_content) => {
1797 if let Some(e) = response_content.entity {
1798 Ok(e)
1799 } else {
1800 Err(datadog::Error::Serde(serde::de::Error::custom(
1801 "response content was None",
1802 )))
1803 }
1804 }
1805 Err(err) => Err(err),
1806 }
1807 }
1808
1809 pub async fn update_monitor_config_policy_with_http_info(
1811 &self,
1812 policy_id: String,
1813 body: crate::datadogV2::model::MonitorConfigPolicyEditRequest,
1814 ) -> Result<
1815 datadog::ResponseContent<crate::datadogV2::model::MonitorConfigPolicyResponse>,
1816 datadog::Error<UpdateMonitorConfigPolicyError>,
1817 > {
1818 let local_configuration = &self.config;
1819 let operation_id = "v2.update_monitor_config_policy";
1820
1821 let local_client = &self.client;
1822
1823 let local_uri_str = format!(
1824 "{}/api/v2/monitor/policy/{policy_id}",
1825 local_configuration.get_operation_host(operation_id),
1826 policy_id = datadog::urlencode(policy_id)
1827 );
1828 let mut local_req_builder =
1829 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1830
1831 let mut headers = HeaderMap::new();
1833 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1834 headers.insert("Accept", HeaderValue::from_static("application/json"));
1835
1836 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1838 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1839 Err(e) => {
1840 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1841 headers.insert(
1842 reqwest::header::USER_AGENT,
1843 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1844 )
1845 }
1846 };
1847
1848 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1850 headers.insert(
1851 "DD-API-KEY",
1852 HeaderValue::from_str(local_key.key.as_str())
1853 .expect("failed to parse DD-API-KEY header"),
1854 );
1855 };
1856 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1857 headers.insert(
1858 "DD-APPLICATION-KEY",
1859 HeaderValue::from_str(local_key.key.as_str())
1860 .expect("failed to parse DD-APPLICATION-KEY header"),
1861 );
1862 };
1863
1864 let output = Vec::new();
1866 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1867 if body.serialize(&mut ser).is_ok() {
1868 if let Some(content_encoding) = headers.get("Content-Encoding") {
1869 match content_encoding.to_str().unwrap_or_default() {
1870 "gzip" => {
1871 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1872 let _ = enc.write_all(ser.into_inner().as_slice());
1873 match enc.finish() {
1874 Ok(buf) => {
1875 local_req_builder = local_req_builder.body(buf);
1876 }
1877 Err(e) => return Err(datadog::Error::Io(e)),
1878 }
1879 }
1880 "deflate" => {
1881 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1882 let _ = enc.write_all(ser.into_inner().as_slice());
1883 match enc.finish() {
1884 Ok(buf) => {
1885 local_req_builder = local_req_builder.body(buf);
1886 }
1887 Err(e) => return Err(datadog::Error::Io(e)),
1888 }
1889 }
1890 "zstd1" => {
1891 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1892 let _ = enc.write_all(ser.into_inner().as_slice());
1893 match enc.finish() {
1894 Ok(buf) => {
1895 local_req_builder = local_req_builder.body(buf);
1896 }
1897 Err(e) => return Err(datadog::Error::Io(e)),
1898 }
1899 }
1900 _ => {
1901 local_req_builder = local_req_builder.body(ser.into_inner());
1902 }
1903 }
1904 } else {
1905 local_req_builder = local_req_builder.body(ser.into_inner());
1906 }
1907 }
1908
1909 local_req_builder = local_req_builder.headers(headers);
1910 let local_req = local_req_builder.build()?;
1911 log::debug!("request content: {:?}", local_req.body());
1912 let local_resp = local_client.execute(local_req).await?;
1913
1914 let local_status = local_resp.status();
1915 let local_content = local_resp.text().await?;
1916 log::debug!("response content: {}", local_content);
1917
1918 if !local_status.is_client_error() && !local_status.is_server_error() {
1919 match serde_json::from_str::<crate::datadogV2::model::MonitorConfigPolicyResponse>(
1920 &local_content,
1921 ) {
1922 Ok(e) => {
1923 return Ok(datadog::ResponseContent {
1924 status: local_status,
1925 content: local_content,
1926 entity: Some(e),
1927 })
1928 }
1929 Err(e) => return Err(datadog::Error::Serde(e)),
1930 };
1931 } else {
1932 let local_entity: Option<UpdateMonitorConfigPolicyError> =
1933 serde_json::from_str(&local_content).ok();
1934 let local_error = datadog::ResponseContent {
1935 status: local_status,
1936 content: local_content,
1937 entity: local_entity,
1938 };
1939 Err(datadog::Error::ResponseError(local_error))
1940 }
1941 }
1942
1943 pub async fn update_monitor_notification_rule(
1945 &self,
1946 rule_id: String,
1947 body: crate::datadogV2::model::MonitorNotificationRuleUpdateRequest,
1948 ) -> Result<
1949 crate::datadogV2::model::MonitorNotificationRuleResponse,
1950 datadog::Error<UpdateMonitorNotificationRuleError>,
1951 > {
1952 match self
1953 .update_monitor_notification_rule_with_http_info(rule_id, body)
1954 .await
1955 {
1956 Ok(response_content) => {
1957 if let Some(e) = response_content.entity {
1958 Ok(e)
1959 } else {
1960 Err(datadog::Error::Serde(serde::de::Error::custom(
1961 "response content was None",
1962 )))
1963 }
1964 }
1965 Err(err) => Err(err),
1966 }
1967 }
1968
1969 pub async fn update_monitor_notification_rule_with_http_info(
1971 &self,
1972 rule_id: String,
1973 body: crate::datadogV2::model::MonitorNotificationRuleUpdateRequest,
1974 ) -> Result<
1975 datadog::ResponseContent<crate::datadogV2::model::MonitorNotificationRuleResponse>,
1976 datadog::Error<UpdateMonitorNotificationRuleError>,
1977 > {
1978 let local_configuration = &self.config;
1979 let operation_id = "v2.update_monitor_notification_rule";
1980
1981 let local_client = &self.client;
1982
1983 let local_uri_str = format!(
1984 "{}/api/v2/monitor/notification_rule/{rule_id}",
1985 local_configuration.get_operation_host(operation_id),
1986 rule_id = datadog::urlencode(rule_id)
1987 );
1988 let mut local_req_builder =
1989 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1990
1991 let mut headers = HeaderMap::new();
1993 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1994 headers.insert("Accept", HeaderValue::from_static("application/json"));
1995
1996 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1998 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1999 Err(e) => {
2000 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2001 headers.insert(
2002 reqwest::header::USER_AGENT,
2003 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2004 )
2005 }
2006 };
2007
2008 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2010 headers.insert(
2011 "DD-API-KEY",
2012 HeaderValue::from_str(local_key.key.as_str())
2013 .expect("failed to parse DD-API-KEY header"),
2014 );
2015 };
2016 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2017 headers.insert(
2018 "DD-APPLICATION-KEY",
2019 HeaderValue::from_str(local_key.key.as_str())
2020 .expect("failed to parse DD-APPLICATION-KEY header"),
2021 );
2022 };
2023
2024 let output = Vec::new();
2026 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2027 if body.serialize(&mut ser).is_ok() {
2028 if let Some(content_encoding) = headers.get("Content-Encoding") {
2029 match content_encoding.to_str().unwrap_or_default() {
2030 "gzip" => {
2031 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2032 let _ = enc.write_all(ser.into_inner().as_slice());
2033 match enc.finish() {
2034 Ok(buf) => {
2035 local_req_builder = local_req_builder.body(buf);
2036 }
2037 Err(e) => return Err(datadog::Error::Io(e)),
2038 }
2039 }
2040 "deflate" => {
2041 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2042 let _ = enc.write_all(ser.into_inner().as_slice());
2043 match enc.finish() {
2044 Ok(buf) => {
2045 local_req_builder = local_req_builder.body(buf);
2046 }
2047 Err(e) => return Err(datadog::Error::Io(e)),
2048 }
2049 }
2050 "zstd1" => {
2051 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2052 let _ = enc.write_all(ser.into_inner().as_slice());
2053 match enc.finish() {
2054 Ok(buf) => {
2055 local_req_builder = local_req_builder.body(buf);
2056 }
2057 Err(e) => return Err(datadog::Error::Io(e)),
2058 }
2059 }
2060 _ => {
2061 local_req_builder = local_req_builder.body(ser.into_inner());
2062 }
2063 }
2064 } else {
2065 local_req_builder = local_req_builder.body(ser.into_inner());
2066 }
2067 }
2068
2069 local_req_builder = local_req_builder.headers(headers);
2070 let local_req = local_req_builder.build()?;
2071 log::debug!("request content: {:?}", local_req.body());
2072 let local_resp = local_client.execute(local_req).await?;
2073
2074 let local_status = local_resp.status();
2075 let local_content = local_resp.text().await?;
2076 log::debug!("response content: {}", local_content);
2077
2078 if !local_status.is_client_error() && !local_status.is_server_error() {
2079 match serde_json::from_str::<crate::datadogV2::model::MonitorNotificationRuleResponse>(
2080 &local_content,
2081 ) {
2082 Ok(e) => {
2083 return Ok(datadog::ResponseContent {
2084 status: local_status,
2085 content: local_content,
2086 entity: Some(e),
2087 })
2088 }
2089 Err(e) => return Err(datadog::Error::Serde(e)),
2090 };
2091 } else {
2092 let local_entity: Option<UpdateMonitorNotificationRuleError> =
2093 serde_json::from_str(&local_content).ok();
2094 let local_error = datadog::ResponseContent {
2095 status: local_status,
2096 content: local_content,
2097 entity: local_entity,
2098 };
2099 Err(datadog::Error::ResponseError(local_error))
2100 }
2101 }
2102
2103 pub async fn update_monitor_user_template(
2105 &self,
2106 template_id: String,
2107 body: crate::datadogV2::model::MonitorUserTemplateUpdateRequest,
2108 ) -> Result<
2109 crate::datadogV2::model::MonitorUserTemplateResponse,
2110 datadog::Error<UpdateMonitorUserTemplateError>,
2111 > {
2112 match self
2113 .update_monitor_user_template_with_http_info(template_id, body)
2114 .await
2115 {
2116 Ok(response_content) => {
2117 if let Some(e) = response_content.entity {
2118 Ok(e)
2119 } else {
2120 Err(datadog::Error::Serde(serde::de::Error::custom(
2121 "response content was None",
2122 )))
2123 }
2124 }
2125 Err(err) => Err(err),
2126 }
2127 }
2128
2129 pub async fn update_monitor_user_template_with_http_info(
2131 &self,
2132 template_id: String,
2133 body: crate::datadogV2::model::MonitorUserTemplateUpdateRequest,
2134 ) -> Result<
2135 datadog::ResponseContent<crate::datadogV2::model::MonitorUserTemplateResponse>,
2136 datadog::Error<UpdateMonitorUserTemplateError>,
2137 > {
2138 let local_configuration = &self.config;
2139 let operation_id = "v2.update_monitor_user_template";
2140 if local_configuration.is_unstable_operation_enabled(operation_id) {
2141 warn!("Using unstable operation {operation_id}");
2142 } else {
2143 let local_error = datadog::UnstableOperationDisabledError {
2144 msg: "Operation 'v2.update_monitor_user_template' is not enabled".to_string(),
2145 };
2146 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2147 }
2148
2149 let local_client = &self.client;
2150
2151 let local_uri_str = format!(
2152 "{}/api/v2/monitor/template/{template_id}",
2153 local_configuration.get_operation_host(operation_id),
2154 template_id = datadog::urlencode(template_id)
2155 );
2156 let mut local_req_builder =
2157 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
2158
2159 let mut headers = HeaderMap::new();
2161 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2162 headers.insert("Accept", HeaderValue::from_static("application/json"));
2163
2164 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2166 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2167 Err(e) => {
2168 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2169 headers.insert(
2170 reqwest::header::USER_AGENT,
2171 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2172 )
2173 }
2174 };
2175
2176 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2178 headers.insert(
2179 "DD-API-KEY",
2180 HeaderValue::from_str(local_key.key.as_str())
2181 .expect("failed to parse DD-API-KEY header"),
2182 );
2183 };
2184 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2185 headers.insert(
2186 "DD-APPLICATION-KEY",
2187 HeaderValue::from_str(local_key.key.as_str())
2188 .expect("failed to parse DD-APPLICATION-KEY header"),
2189 );
2190 };
2191
2192 let output = Vec::new();
2194 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2195 if body.serialize(&mut ser).is_ok() {
2196 if let Some(content_encoding) = headers.get("Content-Encoding") {
2197 match content_encoding.to_str().unwrap_or_default() {
2198 "gzip" => {
2199 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2200 let _ = enc.write_all(ser.into_inner().as_slice());
2201 match enc.finish() {
2202 Ok(buf) => {
2203 local_req_builder = local_req_builder.body(buf);
2204 }
2205 Err(e) => return Err(datadog::Error::Io(e)),
2206 }
2207 }
2208 "deflate" => {
2209 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2210 let _ = enc.write_all(ser.into_inner().as_slice());
2211 match enc.finish() {
2212 Ok(buf) => {
2213 local_req_builder = local_req_builder.body(buf);
2214 }
2215 Err(e) => return Err(datadog::Error::Io(e)),
2216 }
2217 }
2218 "zstd1" => {
2219 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2220 let _ = enc.write_all(ser.into_inner().as_slice());
2221 match enc.finish() {
2222 Ok(buf) => {
2223 local_req_builder = local_req_builder.body(buf);
2224 }
2225 Err(e) => return Err(datadog::Error::Io(e)),
2226 }
2227 }
2228 _ => {
2229 local_req_builder = local_req_builder.body(ser.into_inner());
2230 }
2231 }
2232 } else {
2233 local_req_builder = local_req_builder.body(ser.into_inner());
2234 }
2235 }
2236
2237 local_req_builder = local_req_builder.headers(headers);
2238 let local_req = local_req_builder.build()?;
2239 log::debug!("request content: {:?}", local_req.body());
2240 let local_resp = local_client.execute(local_req).await?;
2241
2242 let local_status = local_resp.status();
2243 let local_content = local_resp.text().await?;
2244 log::debug!("response content: {}", local_content);
2245
2246 if !local_status.is_client_error() && !local_status.is_server_error() {
2247 match serde_json::from_str::<crate::datadogV2::model::MonitorUserTemplateResponse>(
2248 &local_content,
2249 ) {
2250 Ok(e) => {
2251 return Ok(datadog::ResponseContent {
2252 status: local_status,
2253 content: local_content,
2254 entity: Some(e),
2255 })
2256 }
2257 Err(e) => return Err(datadog::Error::Serde(e)),
2258 };
2259 } else {
2260 let local_entity: Option<UpdateMonitorUserTemplateError> =
2261 serde_json::from_str(&local_content).ok();
2262 let local_error = datadog::ResponseContent {
2263 status: local_status,
2264 content: local_content,
2265 entity: local_entity,
2266 };
2267 Err(datadog::Error::ResponseError(local_error))
2268 }
2269 }
2270
2271 pub async fn validate_existing_monitor_user_template(
2273 &self,
2274 template_id: String,
2275 body: crate::datadogV2::model::MonitorUserTemplateUpdateRequest,
2276 ) -> Result<(), datadog::Error<ValidateExistingMonitorUserTemplateError>> {
2277 match self
2278 .validate_existing_monitor_user_template_with_http_info(template_id, body)
2279 .await
2280 {
2281 Ok(_) => Ok(()),
2282 Err(err) => Err(err),
2283 }
2284 }
2285
2286 pub async fn validate_existing_monitor_user_template_with_http_info(
2288 &self,
2289 template_id: String,
2290 body: crate::datadogV2::model::MonitorUserTemplateUpdateRequest,
2291 ) -> Result<
2292 datadog::ResponseContent<()>,
2293 datadog::Error<ValidateExistingMonitorUserTemplateError>,
2294 > {
2295 let local_configuration = &self.config;
2296 let operation_id = "v2.validate_existing_monitor_user_template";
2297 if local_configuration.is_unstable_operation_enabled(operation_id) {
2298 warn!("Using unstable operation {operation_id}");
2299 } else {
2300 let local_error = datadog::UnstableOperationDisabledError {
2301 msg: "Operation 'v2.validate_existing_monitor_user_template' is not enabled"
2302 .to_string(),
2303 };
2304 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2305 }
2306
2307 let local_client = &self.client;
2308
2309 let local_uri_str = format!(
2310 "{}/api/v2/monitor/template/{template_id}/validate",
2311 local_configuration.get_operation_host(operation_id),
2312 template_id = datadog::urlencode(template_id)
2313 );
2314 let mut local_req_builder =
2315 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2316
2317 let mut headers = HeaderMap::new();
2319 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2320 headers.insert("Accept", HeaderValue::from_static("*/*"));
2321
2322 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2324 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2325 Err(e) => {
2326 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2327 headers.insert(
2328 reqwest::header::USER_AGENT,
2329 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2330 )
2331 }
2332 };
2333
2334 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2336 headers.insert(
2337 "DD-API-KEY",
2338 HeaderValue::from_str(local_key.key.as_str())
2339 .expect("failed to parse DD-API-KEY header"),
2340 );
2341 };
2342 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2343 headers.insert(
2344 "DD-APPLICATION-KEY",
2345 HeaderValue::from_str(local_key.key.as_str())
2346 .expect("failed to parse DD-APPLICATION-KEY header"),
2347 );
2348 };
2349
2350 let output = Vec::new();
2352 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2353 if body.serialize(&mut ser).is_ok() {
2354 if let Some(content_encoding) = headers.get("Content-Encoding") {
2355 match content_encoding.to_str().unwrap_or_default() {
2356 "gzip" => {
2357 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2358 let _ = enc.write_all(ser.into_inner().as_slice());
2359 match enc.finish() {
2360 Ok(buf) => {
2361 local_req_builder = local_req_builder.body(buf);
2362 }
2363 Err(e) => return Err(datadog::Error::Io(e)),
2364 }
2365 }
2366 "deflate" => {
2367 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2368 let _ = enc.write_all(ser.into_inner().as_slice());
2369 match enc.finish() {
2370 Ok(buf) => {
2371 local_req_builder = local_req_builder.body(buf);
2372 }
2373 Err(e) => return Err(datadog::Error::Io(e)),
2374 }
2375 }
2376 "zstd1" => {
2377 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2378 let _ = enc.write_all(ser.into_inner().as_slice());
2379 match enc.finish() {
2380 Ok(buf) => {
2381 local_req_builder = local_req_builder.body(buf);
2382 }
2383 Err(e) => return Err(datadog::Error::Io(e)),
2384 }
2385 }
2386 _ => {
2387 local_req_builder = local_req_builder.body(ser.into_inner());
2388 }
2389 }
2390 } else {
2391 local_req_builder = local_req_builder.body(ser.into_inner());
2392 }
2393 }
2394
2395 local_req_builder = local_req_builder.headers(headers);
2396 let local_req = local_req_builder.build()?;
2397 log::debug!("request content: {:?}", local_req.body());
2398 let local_resp = local_client.execute(local_req).await?;
2399
2400 let local_status = local_resp.status();
2401 let local_content = local_resp.text().await?;
2402 log::debug!("response content: {}", local_content);
2403
2404 if !local_status.is_client_error() && !local_status.is_server_error() {
2405 Ok(datadog::ResponseContent {
2406 status: local_status,
2407 content: local_content,
2408 entity: None,
2409 })
2410 } else {
2411 let local_entity: Option<ValidateExistingMonitorUserTemplateError> =
2412 serde_json::from_str(&local_content).ok();
2413 let local_error = datadog::ResponseContent {
2414 status: local_status,
2415 content: local_content,
2416 entity: local_entity,
2417 };
2418 Err(datadog::Error::ResponseError(local_error))
2419 }
2420 }
2421
2422 pub async fn validate_monitor_user_template(
2424 &self,
2425 body: crate::datadogV2::model::MonitorUserTemplateCreateRequest,
2426 ) -> Result<(), datadog::Error<ValidateMonitorUserTemplateError>> {
2427 match self
2428 .validate_monitor_user_template_with_http_info(body)
2429 .await
2430 {
2431 Ok(_) => Ok(()),
2432 Err(err) => Err(err),
2433 }
2434 }
2435
2436 pub async fn validate_monitor_user_template_with_http_info(
2438 &self,
2439 body: crate::datadogV2::model::MonitorUserTemplateCreateRequest,
2440 ) -> Result<datadog::ResponseContent<()>, datadog::Error<ValidateMonitorUserTemplateError>>
2441 {
2442 let local_configuration = &self.config;
2443 let operation_id = "v2.validate_monitor_user_template";
2444 if local_configuration.is_unstable_operation_enabled(operation_id) {
2445 warn!("Using unstable operation {operation_id}");
2446 } else {
2447 let local_error = datadog::UnstableOperationDisabledError {
2448 msg: "Operation 'v2.validate_monitor_user_template' is not enabled".to_string(),
2449 };
2450 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
2451 }
2452
2453 let local_client = &self.client;
2454
2455 let local_uri_str = format!(
2456 "{}/api/v2/monitor/template/validate",
2457 local_configuration.get_operation_host(operation_id)
2458 );
2459 let mut local_req_builder =
2460 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2461
2462 let mut headers = HeaderMap::new();
2464 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2465 headers.insert("Accept", HeaderValue::from_static("*/*"));
2466
2467 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2469 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2470 Err(e) => {
2471 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2472 headers.insert(
2473 reqwest::header::USER_AGENT,
2474 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2475 )
2476 }
2477 };
2478
2479 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2481 headers.insert(
2482 "DD-API-KEY",
2483 HeaderValue::from_str(local_key.key.as_str())
2484 .expect("failed to parse DD-API-KEY header"),
2485 );
2486 };
2487 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2488 headers.insert(
2489 "DD-APPLICATION-KEY",
2490 HeaderValue::from_str(local_key.key.as_str())
2491 .expect("failed to parse DD-APPLICATION-KEY header"),
2492 );
2493 };
2494
2495 let output = Vec::new();
2497 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2498 if body.serialize(&mut ser).is_ok() {
2499 if let Some(content_encoding) = headers.get("Content-Encoding") {
2500 match content_encoding.to_str().unwrap_or_default() {
2501 "gzip" => {
2502 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2503 let _ = enc.write_all(ser.into_inner().as_slice());
2504 match enc.finish() {
2505 Ok(buf) => {
2506 local_req_builder = local_req_builder.body(buf);
2507 }
2508 Err(e) => return Err(datadog::Error::Io(e)),
2509 }
2510 }
2511 "deflate" => {
2512 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2513 let _ = enc.write_all(ser.into_inner().as_slice());
2514 match enc.finish() {
2515 Ok(buf) => {
2516 local_req_builder = local_req_builder.body(buf);
2517 }
2518 Err(e) => return Err(datadog::Error::Io(e)),
2519 }
2520 }
2521 "zstd1" => {
2522 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2523 let _ = enc.write_all(ser.into_inner().as_slice());
2524 match enc.finish() {
2525 Ok(buf) => {
2526 local_req_builder = local_req_builder.body(buf);
2527 }
2528 Err(e) => return Err(datadog::Error::Io(e)),
2529 }
2530 }
2531 _ => {
2532 local_req_builder = local_req_builder.body(ser.into_inner());
2533 }
2534 }
2535 } else {
2536 local_req_builder = local_req_builder.body(ser.into_inner());
2537 }
2538 }
2539
2540 local_req_builder = local_req_builder.headers(headers);
2541 let local_req = local_req_builder.build()?;
2542 log::debug!("request content: {:?}", local_req.body());
2543 let local_resp = local_client.execute(local_req).await?;
2544
2545 let local_status = local_resp.status();
2546 let local_content = local_resp.text().await?;
2547 log::debug!("response content: {}", local_content);
2548
2549 if !local_status.is_client_error() && !local_status.is_server_error() {
2550 Ok(datadog::ResponseContent {
2551 status: local_status,
2552 content: local_content,
2553 entity: None,
2554 })
2555 } else {
2556 let local_entity: Option<ValidateMonitorUserTemplateError> =
2557 serde_json::from_str(&local_content).ok();
2558 let local_error = datadog::ResponseContent {
2559 status: local_status,
2560 content: local_content,
2561 entity: local_entity,
2562 };
2563 Err(datadog::Error::ResponseError(local_error))
2564 }
2565 }
2566}