@@ -167,6 +167,14 @@ pub enum EditGlobalVariableError {
167
167
UnknownValue ( serde_json:: Value ) ,
168
168
}
169
169
170
+ /// FetchUptimesError is a struct for typed errors of method [`SyntheticsAPI::fetch_uptimes`]
171
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
172
+ #[ serde( untagged) ]
173
+ pub enum FetchUptimesError {
174
+ APIErrorResponse ( crate :: datadogV1:: model:: APIErrorResponse ) ,
175
+ UnknownValue ( serde_json:: Value ) ,
176
+ }
177
+
170
178
/// GetAPITestError is a struct for typed errors of method [`SyntheticsAPI::get_api_test`]
171
179
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
172
180
#[ serde( untagged) ]
@@ -1695,6 +1703,157 @@ impl SyntheticsAPI {
1695
1703
}
1696
1704
}
1697
1705
1706
+ /// Fetch uptime for multiple Synthetic tests by ID.
1707
+ pub async fn fetch_uptimes (
1708
+ & self ,
1709
+ body : crate :: datadogV1:: model:: SyntheticsFetchUptimesPayload ,
1710
+ ) -> Result < Vec < crate :: datadogV1:: model:: SyntheticsTestUptime > , datadog:: Error < FetchUptimesError > >
1711
+ {
1712
+ match self . fetch_uptimes_with_http_info ( body) . await {
1713
+ Ok ( response_content) => {
1714
+ if let Some ( e) = response_content. entity {
1715
+ Ok ( e)
1716
+ } else {
1717
+ Err ( datadog:: Error :: Serde ( serde:: de:: Error :: custom (
1718
+ "response content was None" ,
1719
+ ) ) )
1720
+ }
1721
+ }
1722
+ Err ( err) => Err ( err) ,
1723
+ }
1724
+ }
1725
+
1726
+ /// Fetch uptime for multiple Synthetic tests by ID.
1727
+ pub async fn fetch_uptimes_with_http_info (
1728
+ & self ,
1729
+ body : crate :: datadogV1:: model:: SyntheticsFetchUptimesPayload ,
1730
+ ) -> Result <
1731
+ datadog:: ResponseContent < Vec < crate :: datadogV1:: model:: SyntheticsTestUptime > > ,
1732
+ datadog:: Error < FetchUptimesError > ,
1733
+ > {
1734
+ let local_configuration = & self . config ;
1735
+ let operation_id = "v1.fetch_uptimes" ;
1736
+
1737
+ let local_client = & self . client ;
1738
+
1739
+ let local_uri_str = format ! (
1740
+ "{}/api/v1/synthetics/tests/uptimes" ,
1741
+ local_configuration. get_operation_host( operation_id)
1742
+ ) ;
1743
+ let mut local_req_builder =
1744
+ local_client. request ( reqwest:: Method :: POST , local_uri_str. as_str ( ) ) ;
1745
+
1746
+ // build headers
1747
+ let mut headers = HeaderMap :: new ( ) ;
1748
+ headers. insert ( "Content-Type" , HeaderValue :: from_static ( "application/json" ) ) ;
1749
+ headers. insert ( "Accept" , HeaderValue :: from_static ( "application/json" ) ) ;
1750
+
1751
+ // build user agent
1752
+ match HeaderValue :: from_str ( local_configuration. user_agent . as_str ( ) ) {
1753
+ Ok ( user_agent) => headers. insert ( reqwest:: header:: USER_AGENT , user_agent) ,
1754
+ Err ( e) => {
1755
+ log:: warn!( "Failed to parse user agent header: {e}, falling back to default" ) ;
1756
+ headers. insert (
1757
+ reqwest:: header:: USER_AGENT ,
1758
+ HeaderValue :: from_static ( datadog:: DEFAULT_USER_AGENT . as_str ( ) ) ,
1759
+ )
1760
+ }
1761
+ } ;
1762
+
1763
+ // build auth
1764
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "apiKeyAuth" ) {
1765
+ headers. insert (
1766
+ "DD-API-KEY" ,
1767
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
1768
+ . expect ( "failed to parse DD-API-KEY header" ) ,
1769
+ ) ;
1770
+ } ;
1771
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "appKeyAuth" ) {
1772
+ headers. insert (
1773
+ "DD-APPLICATION-KEY" ,
1774
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
1775
+ . expect ( "failed to parse DD-APPLICATION-KEY header" ) ,
1776
+ ) ;
1777
+ } ;
1778
+
1779
+ // build body parameters
1780
+ let output = Vec :: new ( ) ;
1781
+ let mut ser = serde_json:: Serializer :: with_formatter ( output, datadog:: DDFormatter ) ;
1782
+ if body. serialize ( & mut ser) . is_ok ( ) {
1783
+ if let Some ( content_encoding) = headers. get ( "Content-Encoding" ) {
1784
+ match content_encoding. to_str ( ) . unwrap_or_default ( ) {
1785
+ "gzip" => {
1786
+ let mut enc = GzEncoder :: new ( Vec :: new ( ) , Compression :: default ( ) ) ;
1787
+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
1788
+ match enc. finish ( ) {
1789
+ Ok ( buf) => {
1790
+ local_req_builder = local_req_builder. body ( buf) ;
1791
+ }
1792
+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
1793
+ }
1794
+ }
1795
+ "deflate" => {
1796
+ let mut enc = ZlibEncoder :: new ( Vec :: new ( ) , Compression :: default ( ) ) ;
1797
+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
1798
+ match enc. finish ( ) {
1799
+ Ok ( buf) => {
1800
+ local_req_builder = local_req_builder. body ( buf) ;
1801
+ }
1802
+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
1803
+ }
1804
+ }
1805
+ "zstd1" => {
1806
+ let mut enc = zstd:: stream:: Encoder :: new ( Vec :: new ( ) , 0 ) . unwrap ( ) ;
1807
+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
1808
+ match enc. finish ( ) {
1809
+ Ok ( buf) => {
1810
+ local_req_builder = local_req_builder. body ( buf) ;
1811
+ }
1812
+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
1813
+ }
1814
+ }
1815
+ _ => {
1816
+ local_req_builder = local_req_builder. body ( ser. into_inner ( ) ) ;
1817
+ }
1818
+ }
1819
+ } else {
1820
+ local_req_builder = local_req_builder. body ( ser. into_inner ( ) ) ;
1821
+ }
1822
+ }
1823
+
1824
+ local_req_builder = local_req_builder. headers ( headers) ;
1825
+ let local_req = local_req_builder. build ( ) ?;
1826
+ log:: debug!( "request content: {:?}" , local_req. body( ) ) ;
1827
+ let local_resp = local_client. execute ( local_req) . await ?;
1828
+
1829
+ let local_status = local_resp. status ( ) ;
1830
+ let local_content = local_resp. text ( ) . await ?;
1831
+ log:: debug!( "response content: {}" , local_content) ;
1832
+
1833
+ if !local_status. is_client_error ( ) && !local_status. is_server_error ( ) {
1834
+ match serde_json:: from_str :: < Vec < crate :: datadogV1:: model:: SyntheticsTestUptime > > (
1835
+ & local_content,
1836
+ ) {
1837
+ Ok ( e) => {
1838
+ return Ok ( datadog:: ResponseContent {
1839
+ status : local_status,
1840
+ content : local_content,
1841
+ entity : Some ( e) ,
1842
+ } )
1843
+ }
1844
+ Err ( e) => return Err ( datadog:: Error :: Serde ( e) ) ,
1845
+ } ;
1846
+ } else {
1847
+ let local_entity: Option < FetchUptimesError > = serde_json:: from_str ( & local_content) . ok ( ) ;
1848
+ let local_error = datadog:: ResponseContent {
1849
+ status : local_status,
1850
+ content : local_content,
1851
+ entity : local_entity,
1852
+ } ;
1853
+ Err ( datadog:: Error :: ResponseError ( local_error) )
1854
+ }
1855
+ }
1856
+
1698
1857
/// Get the detailed configuration associated with
1699
1858
/// a Synthetic API test.
1700
1859
pub async fn get_api_test (
0 commit comments