Skip to main content

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    #[serde(default, skip_serializing_if = "Option::is_none")]
28    next_check: Option<time::OffsetDateTime>,
29    /// 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.
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    force: Option<bool>,
32    /// filter to target which host and/or service check to reschedule
33    #[builder(default, setter(strip_option, into))]
34    #[serde(flatten)]
35    filter: Option<IcingaFilter>,
36}
37
38impl RescheduleCheck {
39    /// create a new builder for this endpoint
40    ///
41    /// this is usually the first step to calling this REST API endpoint
42    #[must_use]
43    pub fn builder() -> RescheduleCheckBuilder {
44        RescheduleCheckBuilder::default()
45    }
46}
47
48impl RescheduleCheckBuilder {
49    /// makes sure the filter object type is valid for this call (either Host or Service)
50    ///
51    /// # Errors
52    ///
53    /// this returns an error if the filter field object type is not Host or Service
54    pub fn validate(&self) -> Result<(), crate::error::Error> {
55        if let Some(Some(filter)) = &self.filter {
56            if filter.object_type != IcingaObjectType::Host
57                && filter.object_type != IcingaObjectType::Service
58            {
59                Err(crate::error::Error::FilterObjectTypeMismatch(
60                    vec![IcingaObjectType::Host, IcingaObjectType::Service],
61                    filter.object_type.to_owned(),
62                ))
63            } else {
64                Ok(())
65            }
66        } else {
67            Ok(())
68        }
69    }
70}
71
72impl RestApiEndpoint for RescheduleCheck {
73    type RequestBody = Self;
74
75    fn method(&self) -> Result<reqwest::Method, crate::error::Error> {
76        Ok(reqwest::Method::POST)
77    }
78
79    fn url(&self, base_url: &url::Url) -> Result<url::Url, crate::error::Error> {
80        base_url
81            .join("v1/actions/reschedule-check")
82            .map_err(crate::error::Error::CouldNotParseUrlFragment)
83    }
84
85    fn request_body(
86        &self,
87    ) -> Result<Option<std::borrow::Cow<'_, Self::RequestBody>>, crate::error::Error>
88    where
89        Self::RequestBody: Clone + serde::Serialize + std::fmt::Debug,
90    {
91        Ok(Some(std::borrow::Cow::Borrowed(self)))
92    }
93}
94
95impl RestApiResponse<RescheduleCheck> for ResultsWrapper<StatusResponse> {}