icinga2_api/api/action/
acknowledge_problem.rs1use serde::{Deserialize, Serialize};
6
7use crate::serde::{deserialize_optional_icinga_timestamp, serialize_optional_icinga_timestamp};
8use crate::types::action::StatusResponse;
9use crate::types::enums::object_type::IcingaObjectType;
10use crate::types::filter::IcingaFilter;
11use crate::types::query::ResultsWrapper;
12use crate::types::rest::{RestApiEndpoint, RestApiResponse};
13
14#[derive(Debug, Clone, derive_builder::Builder, Serialize, Deserialize)]
16#[builder(
17 build_fn(error = "crate::error::Error", validate = "Self::validate"),
18 derive(Debug)
19)]
20pub struct AcknowledgeProblem {
21 author: String,
23 comment: String,
25 #[serde(
27 serialize_with = "serialize_optional_icinga_timestamp",
28 deserialize_with = "deserialize_optional_icinga_timestamp"
29 )]
30 expiry: Option<time::OffsetDateTime>,
31 sticky: Option<bool>,
33 notify: Option<bool>,
35 persistent: Option<bool>,
37 #[builder(default, setter(strip_option, into))]
39 #[serde(flatten)]
40 filter: Option<IcingaFilter>,
41}
42
43impl AcknowledgeProblem {
44 #[must_use]
48 pub fn builder() -> AcknowledgeProblemBuilder {
49 AcknowledgeProblemBuilder::default()
50 }
51}
52
53impl AcknowledgeProblemBuilder {
54 pub fn validate(&self) -> Result<(), crate::error::Error> {
60 if let Some(Some(filter)) = &self.filter {
61 if filter.object_type != IcingaObjectType::Host
62 && filter.object_type != IcingaObjectType::Service
63 {
64 Err(crate::error::Error::FilterObjectTypeMismatch(
65 vec![IcingaObjectType::Host, IcingaObjectType::Service],
66 filter.object_type.to_owned(),
67 ))
68 } else {
69 Ok(())
70 }
71 } else {
72 Ok(())
73 }
74 }
75}
76
77impl RestApiEndpoint for AcknowledgeProblem {
78 type RequestBody = AcknowledgeProblem;
79
80 fn method(&self) -> Result<reqwest::Method, crate::error::Error> {
81 Ok(reqwest::Method::POST)
82 }
83
84 fn url(&self, base_url: &url::Url) -> Result<url::Url, crate::error::Error> {
85 base_url
86 .join("v1/actions/acknowledge-problem")
87 .map_err(crate::error::Error::CouldNotParseUrlFragment)
88 }
89
90 fn request_body(
91 &self,
92 ) -> Result<Option<std::borrow::Cow<Self::RequestBody>>, crate::error::Error>
93 where
94 Self::RequestBody: Clone + serde::Serialize + std::fmt::Debug,
95 {
96 Ok(Some(std::borrow::Cow::Borrowed(self)))
97 }
98}
99
100impl RestApiResponse<AcknowledgeProblem> for ResultsWrapper<StatusResponse> {}