-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_monitors.rs
2233 lines (2084 loc) · 97.5 KB
/
api_monitors.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use crate::datadog;
use async_stream::try_stream;
use flate2::{
write::{GzEncoder, ZlibEncoder},
Compression,
};
use futures_core::stream::Stream;
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
use std::io::Write;
/// DeleteMonitorOptionalParams is a struct for passing parameters to the method [`MonitorsAPI::delete_monitor`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct DeleteMonitorOptionalParams {
/// Delete the monitor even if it's referenced by other resources (for example SLO, composite monitor).
pub force: Option<String>,
}
impl DeleteMonitorOptionalParams {
/// Delete the monitor even if it's referenced by other resources (for example SLO, composite monitor).
pub fn force(mut self, value: String) -> Self {
self.force = Some(value);
self
}
}
/// GetMonitorOptionalParams is a struct for passing parameters to the method [`MonitorsAPI::get_monitor`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetMonitorOptionalParams {
/// When specified, shows additional information about the group states. Choose one or more from `all`, `alert`, `warn`, and `no data`.
pub group_states: Option<String>,
/// If this argument is set to true, then the returned data includes all current active downtimes for the monitor.
pub with_downtimes: Option<bool>,
}
impl GetMonitorOptionalParams {
/// When specified, shows additional information about the group states. Choose one or more from `all`, `alert`, `warn`, and `no data`.
pub fn group_states(mut self, value: String) -> Self {
self.group_states = Some(value);
self
}
/// If this argument is set to true, then the returned data includes all current active downtimes for the monitor.
pub fn with_downtimes(mut self, value: bool) -> Self {
self.with_downtimes = Some(value);
self
}
}
/// ListMonitorsOptionalParams is a struct for passing parameters to the method [`MonitorsAPI::list_monitors`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListMonitorsOptionalParams {
/// When specified, shows additional information about the group states.
/// Choose one or more from `all`, `alert`, `warn`, and `no data`.
pub group_states: Option<String>,
/// A string to filter monitors by name.
pub name: Option<String>,
/// A comma separated list indicating what tags, if any, should be used to filter the list of monitors by scope.
/// For example, `host:host0`.
pub tags: Option<String>,
/// A comma separated list indicating what service and/or custom tags, if any, should be used to filter the list of monitors.
/// Tags created in the Datadog UI automatically have the service key prepended. For example, `service:my-app`.
pub monitor_tags: Option<String>,
/// If this argument is set to true, then the returned data includes all current active downtimes for each monitor.
pub with_downtimes: Option<bool>,
/// Use this parameter for paginating through large sets of monitors. Start with a value of zero, make a request, set the value to the last ID of result set, and then repeat until the response is empty.
pub id_offset: Option<i64>,
/// The page to start paginating from. If this argument is not specified, the request returns all monitors without pagination.
pub page: Option<i64>,
/// The number of monitors to return per page. If the page argument is not specified, the default behavior returns all monitors without a `page_size` limit. However, if page is specified and `page_size` is not, the argument defaults to 100.
pub page_size: Option<i32>,
}
impl ListMonitorsOptionalParams {
/// When specified, shows additional information about the group states.
/// Choose one or more from `all`, `alert`, `warn`, and `no data`.
pub fn group_states(mut self, value: String) -> Self {
self.group_states = Some(value);
self
}
/// A string to filter monitors by name.
pub fn name(mut self, value: String) -> Self {
self.name = Some(value);
self
}
/// A comma separated list indicating what tags, if any, should be used to filter the list of monitors by scope.
/// For example, `host:host0`.
pub fn tags(mut self, value: String) -> Self {
self.tags = Some(value);
self
}
/// A comma separated list indicating what service and/or custom tags, if any, should be used to filter the list of monitors.
/// Tags created in the Datadog UI automatically have the service key prepended. For example, `service:my-app`.
pub fn monitor_tags(mut self, value: String) -> Self {
self.monitor_tags = Some(value);
self
}
/// If this argument is set to true, then the returned data includes all current active downtimes for each monitor.
pub fn with_downtimes(mut self, value: bool) -> Self {
self.with_downtimes = Some(value);
self
}
/// Use this parameter for paginating through large sets of monitors. Start with a value of zero, make a request, set the value to the last ID of result set, and then repeat until the response is empty.
pub fn id_offset(mut self, value: i64) -> Self {
self.id_offset = Some(value);
self
}
/// The page to start paginating from. If this argument is not specified, the request returns all monitors without pagination.
pub fn page(mut self, value: i64) -> Self {
self.page = Some(value);
self
}
/// The number of monitors to return per page. If the page argument is not specified, the default behavior returns all monitors without a `page_size` limit. However, if page is specified and `page_size` is not, the argument defaults to 100.
pub fn page_size(mut self, value: i32) -> Self {
self.page_size = Some(value);
self
}
}
/// SearchMonitorGroupsOptionalParams is a struct for passing parameters to the method [`MonitorsAPI::search_monitor_groups`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct SearchMonitorGroupsOptionalParams {
/// After entering a search query on the [Triggered Monitors page][1], use the query parameter value in the
/// URL of the page as a value for this parameter. For more information, see the [Manage Monitors documentation][2].
///
/// The query can contain any number of space-separated monitor attributes, for instance: `query="type:metric group_status:alert"`.
///
/// [1]: <https://app.datadoghq.com/monitors/triggered>
/// [2]: /monitors/manage/#triggered-monitors
pub query: Option<String>,
/// Page to start paginating from.
pub page: Option<i64>,
/// Number of monitors to return per page.
pub per_page: Option<i64>,
/// String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:
///
/// * `name`
/// * `status`
/// * `tags`
pub sort: Option<String>,
}
impl SearchMonitorGroupsOptionalParams {
/// After entering a search query on the [Triggered Monitors page][1], use the query parameter value in the
/// URL of the page as a value for this parameter. For more information, see the [Manage Monitors documentation][2].
///
/// The query can contain any number of space-separated monitor attributes, for instance: `query="type:metric group_status:alert"`.
///
/// [1]: <https://app.datadoghq.com/monitors/triggered>
/// [2]: /monitors/manage/#triggered-monitors
pub fn query(mut self, value: String) -> Self {
self.query = Some(value);
self
}
/// Page to start paginating from.
pub fn page(mut self, value: i64) -> Self {
self.page = Some(value);
self
}
/// Number of monitors to return per page.
pub fn per_page(mut self, value: i64) -> Self {
self.per_page = Some(value);
self
}
/// String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:
///
/// * `name`
/// * `status`
/// * `tags`
pub fn sort(mut self, value: String) -> Self {
self.sort = Some(value);
self
}
}
/// SearchMonitorsOptionalParams is a struct for passing parameters to the method [`MonitorsAPI::search_monitors`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct SearchMonitorsOptionalParams {
/// After entering a search query in your [Manage Monitor page][1] use the query parameter value in the
/// URL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]
/// page to learn more.
///
/// The query can contain any number of space-separated monitor attributes, for instance `query="type:metric status:alert"`.
///
/// [1]: <https://app.datadoghq.com/monitors/manage>
/// [2]: /monitors/manage/#find-the-monitors
pub query: Option<String>,
/// Page to start paginating from.
pub page: Option<i64>,
/// Number of monitors to return per page.
pub per_page: Option<i64>,
/// String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:
///
/// * `name`
/// * `status`
/// * `tags`
pub sort: Option<String>,
}
impl SearchMonitorsOptionalParams {
/// After entering a search query in your [Manage Monitor page][1] use the query parameter value in the
/// URL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]
/// page to learn more.
///
/// The query can contain any number of space-separated monitor attributes, for instance `query="type:metric status:alert"`.
///
/// [1]: <https://app.datadoghq.com/monitors/manage>
/// [2]: /monitors/manage/#find-the-monitors
pub fn query(mut self, value: String) -> Self {
self.query = Some(value);
self
}
/// Page to start paginating from.
pub fn page(mut self, value: i64) -> Self {
self.page = Some(value);
self
}
/// Number of monitors to return per page.
pub fn per_page(mut self, value: i64) -> Self {
self.per_page = Some(value);
self
}
/// String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:
///
/// * `name`
/// * `status`
/// * `tags`
pub fn sort(mut self, value: String) -> Self {
self.sort = Some(value);
self
}
}
/// CheckCanDeleteMonitorError is a struct for typed errors of method [`MonitorsAPI::check_can_delete_monitor`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CheckCanDeleteMonitorError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
CheckCanDeleteMonitorResponse(crate::datadogV1::model::CheckCanDeleteMonitorResponse),
UnknownValue(serde_json::Value),
}
/// CreateMonitorError is a struct for typed errors of method [`MonitorsAPI::create_monitor`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateMonitorError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// DeleteMonitorError is a struct for typed errors of method [`MonitorsAPI::delete_monitor`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteMonitorError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// GetMonitorError is a struct for typed errors of method [`MonitorsAPI::get_monitor`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMonitorError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// ListMonitorsError is a struct for typed errors of method [`MonitorsAPI::list_monitors`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListMonitorsError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// SearchMonitorGroupsError is a struct for typed errors of method [`MonitorsAPI::search_monitor_groups`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchMonitorGroupsError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// SearchMonitorsError is a struct for typed errors of method [`MonitorsAPI::search_monitors`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchMonitorsError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// UpdateMonitorError is a struct for typed errors of method [`MonitorsAPI::update_monitor`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateMonitorError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// ValidateExistingMonitorError is a struct for typed errors of method [`MonitorsAPI::validate_existing_monitor`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ValidateExistingMonitorError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// ValidateMonitorError is a struct for typed errors of method [`MonitorsAPI::validate_monitor`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ValidateMonitorError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// [Monitors](<https://docs.datadoghq.com/monitors>) allow you to watch a metric or check that you care about and
/// notifies your team when a defined threshold has exceeded.
///
/// For more information, see [Creating Monitors](<https://docs.datadoghq.com/monitors/create/types/>).
#[derive(Debug, Clone)]
pub struct MonitorsAPI {
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
}
impl Default for MonitorsAPI {
fn default() -> Self {
Self::with_config(datadog::Configuration::default())
}
}
impl MonitorsAPI {
pub fn new() -> Self {
Self::default()
}
pub fn with_config(config: datadog::Configuration) -> Self {
let mut reqwest_client_builder = reqwest::Client::builder();
if let Some(proxy_url) = &config.proxy_url {
let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}
let mut middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
if config.enable_retry {
struct RetryableStatus;
impl reqwest_retry::RetryableStrategy for RetryableStatus {
fn handle(
&self,
res: &Result<reqwest::Response, reqwest_middleware::Error>,
) -> Option<reqwest_retry::Retryable> {
match res {
Ok(success) => reqwest_retry::default_on_request_success(success),
Err(_) => None,
}
}
}
let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
.build_with_max_retries(config.max_retries);
let retry_middleware =
reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
backoff_policy,
RetryableStatus,
);
middleware_client_builder = middleware_client_builder.with(retry_middleware);
}
let client = middleware_client_builder.build();
Self { config, client }
}
pub fn with_client_and_config(
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
) -> Self {
Self { config, client }
}
/// Check if the given monitors can be deleted.
pub async fn check_can_delete_monitor(
&self,
monitor_ids: Vec<i64>,
) -> Result<
crate::datadogV1::model::CheckCanDeleteMonitorResponse,
datadog::Error<CheckCanDeleteMonitorError>,
> {
match self
.check_can_delete_monitor_with_http_info(monitor_ids)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
/// Check if the given monitors can be deleted.
pub async fn check_can_delete_monitor_with_http_info(
&self,
monitor_ids: Vec<i64>,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::CheckCanDeleteMonitorResponse>,
datadog::Error<CheckCanDeleteMonitorError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.check_can_delete_monitor";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/monitor/can_delete",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
local_req_builder = local_req_builder.query(&[(
"monitor_ids",
&monitor_ids
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
// build headers
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
// build user agent
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
// build auth
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::CheckCanDeleteMonitorResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CheckCanDeleteMonitorError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
/// Create a monitor using the specified options.
///
/// #### Monitor Types
///
/// The type of monitor chosen from:
///
/// - anomaly: `query alert`
/// - APM: `query alert` or `trace-analytics alert`
/// - composite: `composite`
/// - custom: `service check`
/// - forecast: `query alert`
/// - host: `service check`
/// - integration: `query alert` or `service check`
/// - live process: `process alert`
/// - logs: `log alert`
/// - metric: `query alert`
/// - network: `service check`
/// - outlier: `query alert`
/// - process: `service check`
/// - rum: `rum alert`
/// - SLO: `slo alert`
/// - watchdog: `event-v2 alert`
/// - event-v2: `event-v2 alert`
/// - audit: `audit alert`
/// - error-tracking: `error-tracking alert`
/// - database-monitoring: `database-monitoring alert`
/// - network-performance: `network-performance alert`
/// - cloud cost: `cost alert`
///
/// **Notes**:
/// - Synthetic monitors are created through the Synthetics API. See the [Synthetics API](<https://docs.datadoghq.com/api/latest/synthetics/>) documentation for more information.
/// - Log monitors require an unscoped App Key.
///
/// #### Query Types
///
/// ##### Metric Alert Query
///
/// Example: `time_aggr(time_window):space_aggr:metric{tags} [by {key}] operator #`
///
/// - `time_aggr`: avg, sum, max, min, change, or pct_change
/// - `time_window`: `last_#m` (with `#` between 1 and 10080 depending on the monitor type) or `last_#h`(with `#` between 1 and 168 depending on the monitor type) or `last_1d`, or `last_1w`
/// - `space_aggr`: avg, sum, min, or max
/// - `tags`: one or more tags (comma-separated), or *
/// - `key`: a 'key' in key:value tag syntax; defines a separate alert for each tag in the group (multi-alert)
/// - `operator`: <, <=, >, >=, ==, or !=
/// - `#`: an integer or decimal number used to set the threshold
///
/// If you are using the `_change_` or `_pct_change_` time aggregator, instead use `change_aggr(time_aggr(time_window),
/// timeshift):space_aggr:metric{tags} [by {key}] operator #` with:
///
/// - `change_aggr` change, pct_change
/// - `time_aggr` avg, sum, max, min [Learn more](<https://docs.datadoghq.com/monitors/create/types/#define-the-conditions>)
/// - `time_window` last\_#m (between 1 and 2880 depending on the monitor type), last\_#h (between 1 and 48 depending on the monitor type), or last_#d (1 or 2)
/// - `timeshift` #m_ago (5, 10, 15, or 30), #h_ago (1, 2, or 4), or 1d_ago
///
/// Use this to create an outlier monitor using the following query:
/// `avg(last_30m):outliers(avg:system.cpu.user{role:es-events-data} by {host}, 'dbscan', 7) > 0`
///
/// ##### Service Check Query
///
/// Example: `"check".over(tags).last(count).by(group).count_by_status()`
///
/// - `check` name of the check, for example `datadog.agent.up`
/// - `tags` one or more quoted tags (comma-separated), or "*". for example: `.over("env:prod", "role:db")`; `over` cannot be blank.
/// - `count` must be at greater than or equal to your max threshold (defined in the `options`). It is limited to 100.
/// For example, if you've specified to notify on 1 critical, 3 ok, and 2 warn statuses, `count` should be at least 3.
/// - `group` must be specified for check monitors. Per-check grouping is already explicitly known for some service checks.
/// For example, Postgres integration monitors are tagged by `db`, `host`, and `port`, and Network monitors by `host`, `instance`, and `url`. See [Service Checks](<https://docs.datadoghq.com/api/latest/service-checks/>) documentation for more information.
///
/// ##### Event Alert Query
///
/// **Note:** The Event Alert Query has been replaced by the Event V2 Alert Query. For more information, see the [Event Migration guide](<https://docs.datadoghq.com/service_management/events/guides/migrating_to_new_events_features/>).
///
/// ##### Event V2 Alert Query
///
/// Example: `events(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### Process Alert Query
///
/// Example: `processes(search).over(tags).rollup('count').last(timeframe) operator #`
///
/// - `search` free text search string for querying processes.
/// Matching processes match results on the [Live Processes](<https://docs.datadoghq.com/infrastructure/process/?tab=linuxwindows>) page.
/// - `tags` one or more tags (comma-separated)
/// - `timeframe` the timeframe to roll up the counts. Examples: 10m, 4h. Supported timeframes: s, m, h and d
/// - `operator` <, <=, >, >=, ==, or !=
/// - `#` an integer or decimal number used to set the threshold
///
/// ##### Logs Alert Query
///
/// Example: `logs(query).index(index_name).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `index_name` For multi-index organizations, the log index in which the request is performed.
/// - `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### Composite Query
///
/// Example: `12345 && 67890`, where `12345` and `67890` are the IDs of non-composite monitors
///
/// * `name` [*required*, *default* = **dynamic, based on query**]: The name of the alert.
/// * `message` [*required*, *default* = **dynamic, based on query**]: A message to include with notifications for this monitor.
/// Email notifications can be sent to specific users by using the same '@username' notation as events.
/// * `tags` [*optional*, *default* = **empty list**]: A list of tags to associate with your monitor.
/// When getting all monitor details via the API, use the `monitor_tags` argument to filter results by these tags.
/// It is only available via the API and isn't visible or editable in the Datadog UI.
///
/// ##### SLO Alert Query
///
/// Example: `error_budget("slo_id").over("time_window") operator #`
///
/// - `slo_id`: The alphanumeric SLO ID of the SLO you are configuring the alert for.
/// - `time_window`: The time window of the SLO target you wish to alert on. Valid options: `7d`, `30d`, `90d`.
/// - `operator`: `>=` or `>`
///
/// ##### Audit Alert Query
///
/// Example: `audits(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### CI Pipelines Alert Query
///
/// Example: `ci-pipelines(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### CI Tests Alert Query
///
/// Example: `ci-tests(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### Error Tracking Alert Query
///
/// "New issue" example: `error-tracking(query).source(issue_source).new().rollup(rollup_method[, measure]).by(group_by).last(time_window) operator #`
/// "High impact issue" example: `error-tracking(query).source(issue_source).impact().rollup(rollup_method[, measure]).by(group_by).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `issue_source` The issue source - supports `all`, `browser`, `mobile` and `backend` and defaults to `all` if omitted.
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality` and defaults to `count` if omitted.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `group by` Comma-separated list of attributes to group by - should contain at least `issue.id`.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// **Database Monitoring Alert Query**
///
/// Example: `database-monitoring(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// **Network Performance Alert Query**
///
/// Example: `network-performance(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// **Cost Alert Query**
///
/// Example: `formula(query).timeframe_type(time_window).function(parameter) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `timeframe_type` The timeframe type to evaluate the cost
/// - for `forecast` supports `current`
/// - for `change`, `anomaly`, `threshold` supports `last`
/// - `time_window` - supports daily roll-up e.g. `7d`
/// - `function` - [optional, defaults to `threshold` monitor if omitted] supports `change`, `anomaly`, `forecast`
/// - `parameter` Specify the parameter of the type
/// - for `change`:
/// - supports `relative`, `absolute`
/// - [optional] supports `#`, where `#` is an integer or decimal number used to set the threshold
/// - for `anomaly`:
/// - supports `direction=both`, `direction=above`, `direction=below`
/// - [optional] supports `threshold=#`, where `#` is an integer or decimal number used to set the threshold
/// - `operator`
/// - for `threshold` supports `<`, `<=`, `>`, `>=`, `==`, or `!=`
/// - for `change` supports `>`, `<`
/// - for `anomaly` supports `>=`
/// - for `forecast` supports `>`
/// - `#` an integer or decimal number used to set the threshold.
pub async fn create_monitor(
&self,
body: crate::datadogV1::model::Monitor,
) -> Result<crate::datadogV1::model::Monitor, datadog::Error<CreateMonitorError>> {
match self.create_monitor_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
/// Create a monitor using the specified options.
///
/// #### Monitor Types
///
/// The type of monitor chosen from:
///
/// - anomaly: `query alert`
/// - APM: `query alert` or `trace-analytics alert`
/// - composite: `composite`
/// - custom: `service check`
/// - forecast: `query alert`
/// - host: `service check`
/// - integration: `query alert` or `service check`
/// - live process: `process alert`
/// - logs: `log alert`
/// - metric: `query alert`
/// - network: `service check`
/// - outlier: `query alert`
/// - process: `service check`
/// - rum: `rum alert`
/// - SLO: `slo alert`
/// - watchdog: `event-v2 alert`
/// - event-v2: `event-v2 alert`
/// - audit: `audit alert`
/// - error-tracking: `error-tracking alert`
/// - database-monitoring: `database-monitoring alert`
/// - network-performance: `network-performance alert`
/// - cloud cost: `cost alert`
///
/// **Notes**:
/// - Synthetic monitors are created through the Synthetics API. See the [Synthetics API](<https://docs.datadoghq.com/api/latest/synthetics/>) documentation for more information.
/// - Log monitors require an unscoped App Key.
///
/// #### Query Types
///
/// ##### Metric Alert Query
///
/// Example: `time_aggr(time_window):space_aggr:metric{tags} [by {key}] operator #`
///
/// - `time_aggr`: avg, sum, max, min, change, or pct_change
/// - `time_window`: `last_#m` (with `#` between 1 and 10080 depending on the monitor type) or `last_#h`(with `#` between 1 and 168 depending on the monitor type) or `last_1d`, or `last_1w`
/// - `space_aggr`: avg, sum, min, or max
/// - `tags`: one or more tags (comma-separated), or *
/// - `key`: a 'key' in key:value tag syntax; defines a separate alert for each tag in the group (multi-alert)
/// - `operator`: <, <=, >, >=, ==, or !=
/// - `#`: an integer or decimal number used to set the threshold
///
/// If you are using the `_change_` or `_pct_change_` time aggregator, instead use `change_aggr(time_aggr(time_window),
/// timeshift):space_aggr:metric{tags} [by {key}] operator #` with:
///
/// - `change_aggr` change, pct_change
/// - `time_aggr` avg, sum, max, min [Learn more](<https://docs.datadoghq.com/monitors/create/types/#define-the-conditions>)
/// - `time_window` last\_#m (between 1 and 2880 depending on the monitor type), last\_#h (between 1 and 48 depending on the monitor type), or last_#d (1 or 2)
/// - `timeshift` #m_ago (5, 10, 15, or 30), #h_ago (1, 2, or 4), or 1d_ago
///
/// Use this to create an outlier monitor using the following query:
/// `avg(last_30m):outliers(avg:system.cpu.user{role:es-events-data} by {host}, 'dbscan', 7) > 0`
///
/// ##### Service Check Query
///
/// Example: `"check".over(tags).last(count).by(group).count_by_status()`
///
/// - `check` name of the check, for example `datadog.agent.up`
/// - `tags` one or more quoted tags (comma-separated), or "*". for example: `.over("env:prod", "role:db")`; `over` cannot be blank.
/// - `count` must be at greater than or equal to your max threshold (defined in the `options`). It is limited to 100.
/// For example, if you've specified to notify on 1 critical, 3 ok, and 2 warn statuses, `count` should be at least 3.
/// - `group` must be specified for check monitors. Per-check grouping is already explicitly known for some service checks.
/// For example, Postgres integration monitors are tagged by `db`, `host`, and `port`, and Network monitors by `host`, `instance`, and `url`. See [Service Checks](<https://docs.datadoghq.com/api/latest/service-checks/>) documentation for more information.
///
/// ##### Event Alert Query
///
/// **Note:** The Event Alert Query has been replaced by the Event V2 Alert Query. For more information, see the [Event Migration guide](<https://docs.datadoghq.com/service_management/events/guides/migrating_to_new_events_features/>).
///
/// ##### Event V2 Alert Query
///
/// Example: `events(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### Process Alert Query
///
/// Example: `processes(search).over(tags).rollup('count').last(timeframe) operator #`
///
/// - `search` free text search string for querying processes.
/// Matching processes match results on the [Live Processes](<https://docs.datadoghq.com/infrastructure/process/?tab=linuxwindows>) page.
/// - `tags` one or more tags (comma-separated)
/// - `timeframe` the timeframe to roll up the counts. Examples: 10m, 4h. Supported timeframes: s, m, h and d
/// - `operator` <, <=, >, >=, ==, or !=
/// - `#` an integer or decimal number used to set the threshold
///
/// ##### Logs Alert Query
///
/// Example: `logs(query).index(index_name).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `index_name` For multi-index organizations, the log index in which the request is performed.
/// - `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### Composite Query
///
/// Example: `12345 && 67890`, where `12345` and `67890` are the IDs of non-composite monitors
///
/// * `name` [*required*, *default* = **dynamic, based on query**]: The name of the alert.
/// * `message` [*required*, *default* = **dynamic, based on query**]: A message to include with notifications for this monitor.
/// Email notifications can be sent to specific users by using the same '@username' notation as events.
/// * `tags` [*optional*, *default* = **empty list**]: A list of tags to associate with your monitor.
/// When getting all monitor details via the API, use the `monitor_tags` argument to filter results by these tags.
/// It is only available via the API and isn't visible or editable in the Datadog UI.
///
/// ##### SLO Alert Query
///
/// Example: `error_budget("slo_id").over("time_window") operator #`
///
/// - `slo_id`: The alphanumeric SLO ID of the SLO you are configuring the alert for.
/// - `time_window`: The time window of the SLO target you wish to alert on. Valid options: `7d`, `30d`, `90d`.
/// - `operator`: `>=` or `>`
///
/// ##### Audit Alert Query
///
/// Example: `audits(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### CI Pipelines Alert Query
///
/// Example: `ci-pipelines(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### CI Tests Alert Query
///
/// Example: `ci-tests(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// ##### Error Tracking Alert Query
///
/// "New issue" example: `error-tracking(query).source(issue_source).new().rollup(rollup_method[, measure]).by(group_by).last(time_window) operator #`
/// "High impact issue" example: `error-tracking(query).source(issue_source).impact().rollup(rollup_method[, measure]).by(group_by).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `issue_source` The issue source - supports `all`, `browser`, `mobile` and `backend` and defaults to `all` if omitted.
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality` and defaults to `count` if omitted.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `group by` Comma-separated list of attributes to group by - should contain at least `issue.id`.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// **Database Monitoring Alert Query**
///
/// Example: `database-monitoring(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// **Network Performance Alert Query**
///
/// Example: `network-performance(query).rollup(rollup_method[, measure]).last(time_window) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.
/// - `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
/// - `time_window` #m (between 1 and 2880), #h (between 1 and 48).
/// - `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.
/// - `#` an integer or decimal number used to set the threshold.
///
/// **Cost Alert Query**
///
/// Example: `formula(query).timeframe_type(time_window).function(parameter) operator #`
///
/// - `query` The search query - following the [Log search syntax](<https://docs.datadoghq.com/logs/search_syntax/>).
/// - `timeframe_type` The timeframe type to evaluate the cost
/// - for `forecast` supports `current`
/// - for `change`, `anomaly`, `threshold` supports `last`
/// - `time_window` - supports daily roll-up e.g. `7d`
/// - `function` - [optional, defaults to `threshold` monitor if omitted] supports `change`, `anomaly`, `forecast`
/// - `parameter` Specify the parameter of the type
/// - for `change`:
/// - supports `relative`, `absolute`
/// - [optional] supports `#`, where `#` is an integer or decimal number used to set the threshold
/// - for `anomaly`:
/// - supports `direction=both`, `direction=above`, `direction=below`
/// - [optional] supports `threshold=#`, where `#` is an integer or decimal number used to set the threshold
/// - `operator`
/// - for `threshold` supports `<`, `<=`, `>`, `>=`, `==`, or `!=`
/// - for `change` supports `>`, `<`
/// - for `anomaly` supports `>=`
/// - for `forecast` supports `>`
/// - `#` an integer or decimal number used to set the threshold.
pub async fn create_monitor_with_http_info(
&self,
body: crate::datadogV1::model::Monitor,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::Monitor>,
datadog::Error<CreateMonitorError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.create_monitor";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v1/monitor",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
// build headers
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
// build user agent
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};