icinga2_api/api/action/
reschedule_check.rs

1//! API Action reschedule-check
2//!
3//! [Official Documentation](https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#reschedule-check)
4
5use 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/// REST API Endpoint for the reschedule-check call
15#[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 RescheduleCheck {
21    /// the next check will be run at this time, if omitted the current time is
22    /// used
23    #[serde(
24        serialize_with = "serialize_optional_icinga_timestamp",
25        deserialize_with = "deserialize_optional_icinga_timestamp"
26    )]
27    next_check: Option<time::OffsetDateTime>,
28    /// Defaults to false. If enabled, the checks are executed regardless of time period restrictions and checks being disabled per object or on a global basis.
29    force: Option<bool>,
30    /// filter to target which host and/or service check to reschedule
31    #[builder(default, setter(strip_option, into))]
32    #[serde(flatten)]
33    filter: Option<IcingaFilter>,
34}
35
36impl RescheduleCheck {
37    /// create a new builder for this endpoint
38    ///
39    /// this is usually the first step to calling this REST API endpoint
40    #[must_use]
41    pub fn builder() -> RescheduleCheckBuilder {
42        RescheduleCheckBuilder::default()
43    }
44}
45
46impl RescheduleCheckBuilder {
47    /// makes sure the filter object type is valid for this call (either Host or Service)
48    ///
49    /// # Errors
50    ///
51    /// this returns an error if the filter field object type is not Host or Service
52    pub fn validate(&self) -> Result<(), crate::error::Error> {
53        if let Some(Some(filter)) = &self.filter {
54            if filter.object_type != IcingaObjectType::Host
55                && filter.object_type != IcingaObjectType::Service
56            {
57                Err(crate::error::Error::FilterObjectTypeMismatch(
58                    vec![IcingaObjectType::Host, IcingaObjectType::Service],
59                    filter.object_type.to_owned(),
60                ))
61            } else {
62                Ok(())
63            }
64        } else {
65            Ok(())
66        }
67    }
68}
69
70impl RestApiEndpoint for RescheduleCheck {
71    type RequestBody = RescheduleCheck;
72
73    fn method(&self) -> Result<reqwest::Method, crate::error::Error> {
74        Ok(reqwest::Method::POST)
75    }
76
77    fn url(&self, base_url: &url::Url) -> Result<url::Url, crate::error::Error> {
78        base_url
79            .join("v1/actions/reschedule-check")
80            .map_err(crate::error::Error::CouldNotParseUrlFragment)
81    }
82
83    fn request_body(
84        &self,
85    ) -> Result<Option<std::borrow::Cow<Self::RequestBody>>, crate::error::Error>
86    where
87        Self::RequestBody: Clone + serde::Serialize + std::fmt::Debug,
88    {
89        Ok(Some(std::borrow::Cow::Borrowed(self)))
90    }
91}
92
93impl RestApiResponse<RescheduleCheck> for ResultsWrapper<StatusResponse> {}