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