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
use serde::{Deserialize, Serialize};
use crate::serde::{deserialize_optional_icinga_timestamp, serialize_optional_icinga_timestamp};
use crate::types::action::StatusResponse;
use crate::types::enums::object_type::IcingaObjectType;
use crate::types::filter::IcingaFilter;
use crate::types::query::ResultsWrapper;
use crate::types::rest::{RestApiEndpoint, RestApiResponse};
#[derive(Debug, Clone, derive_builder::Builder, Serialize, Deserialize)]
#[builder(
build_fn(error = "crate::error::Error", validate = "Self::validate"),
derive(Debug)
)]
pub struct AcknowledgeProblem {
author: String,
comment: String,
#[serde(
serialize_with = "serialize_optional_icinga_timestamp",
deserialize_with = "deserialize_optional_icinga_timestamp"
)]
expiry: Option<time::OffsetDateTime>,
sticky: Option<bool>,
notify: Option<bool>,
persistent: Option<bool>,
#[builder(default, setter(strip_option, into))]
#[serde(flatten)]
filter: Option<IcingaFilter>,
}
impl AcknowledgeProblem {
#[must_use]
pub fn builder() -> AcknowledgeProblemBuilder {
AcknowledgeProblemBuilder::default()
}
}
impl AcknowledgeProblemBuilder {
pub fn validate(&self) -> Result<(), crate::error::Error> {
if let Some(Some(filter)) = &self.filter {
if filter.object_type != IcingaObjectType::Host
&& filter.object_type != IcingaObjectType::Service
{
Err(crate::error::Error::FilterObjectTypeMismatch(
vec![IcingaObjectType::Host, IcingaObjectType::Service],
filter.object_type.to_owned(),
))
} else {
Ok(())
}
} else {
Ok(())
}
}
}
impl RestApiEndpoint for AcknowledgeProblem {
type RequestBody = AcknowledgeProblem;
fn method(&self) -> Result<http::Method, crate::error::Error> {
Ok(http::Method::POST)
}
fn url(&self, base_url: &url::Url) -> Result<url::Url, crate::error::Error> {
base_url
.join("v1/actions/acknowledge-problem")
.map_err(crate::error::Error::CouldNotParseUrlFragment)
}
fn request_body(
&self,
) -> Result<Option<std::borrow::Cow<Self::RequestBody>>, crate::error::Error>
where
Self::RequestBody: Clone + serde::Serialize + std::fmt::Debug,
{
Ok(Some(std::borrow::Cow::Borrowed(self)))
}
}
impl RestApiResponse<AcknowledgeProblem> for ResultsWrapper<StatusResponse> {}