icinga2_api/types/common/
checkable.rs

1//! Checkable - shared attributes between hosts and services
2//!
3//! [Definition in Icinga Source Code](https://github.com/Icinga/icinga2/blob/master/lib/icinga/checkable.ti)
4
5use serde::Deserialize;
6use serde::Serialize;
7
8use crate::serde::{
9    deserialize_empty_string_or_parse, deserialize_empty_string_or_string,
10    deserialize_icinga_timestamp, deserialize_optional_icinga_timestamp,
11    deserialize_optional_seconds_as_duration, serialize_icinga_timestamp,
12    serialize_none_as_empty_string, serialize_none_as_empty_string_or_to_string,
13    serialize_optional_duration_as_seconds, serialize_optional_icinga_timestamp,
14};
15use crate::types::enums::acknowledgement_type::IcingaAcknowledgementType;
16use crate::types::enums::host_or_service_state::IcingaHostOrServiceState;
17use crate::types::enums::state_type::IcingaStateType;
18use crate::types::names::IcingaCheckCommandName;
19use crate::types::names::IcingaEndpointName;
20use crate::types::names::IcingaEventCommandName;
21use crate::types::names::IcingaTimePeriodName;
22
23use super::check_result::IcingaCheckResult;
24use super::custom_var_object::CustomVarHolder;
25use super::custom_var_object::IcingaCustomVarObject;
26
27/// shared attributes on any checkable object (host and service)
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
29pub struct IcingaCheckable {
30    /// shared config object and custom variable fields
31    #[serde(flatten)]
32    pub custom_var: IcingaCustomVarObject,
33    /// the type of acknowledgement (includes None)
34    pub acknowledgement: IcingaAcknowledgementType,
35    /// when the acknowledgement expires
36    #[serde(
37        serialize_with = "serialize_optional_icinga_timestamp",
38        deserialize_with = "deserialize_optional_icinga_timestamp"
39    )]
40    pub acknowledgement_expiry: Option<time::OffsetDateTime>,
41    /// when the acknowledgement last changed
42    #[serde(
43        serialize_with = "serialize_optional_icinga_timestamp",
44        deserialize_with = "deserialize_optional_icinga_timestamp"
45    )]
46    pub acknowledgement_last_change: Option<time::OffsetDateTime>,
47    /// URL for actions for the checkable (host or service)
48    #[serde(
49        serialize_with = "serialize_none_as_empty_string",
50        deserialize_with = "deserialize_empty_string_or_string"
51    )]
52    pub action_url: Option<String>,
53    /// the current check attempt number
54    pub check_attempt: u64,
55    /// the name of the check command
56    pub check_command: IcingaCheckCommandName,
57    /// the interval used for checks when the host/service is in a HARD state
58    #[serde(default)]
59    #[serde(
60        serialize_with = "serialize_optional_duration_as_seconds",
61        deserialize_with = "deserialize_optional_seconds_as_duration"
62    )]
63    pub check_interval: Option<time::Duration>,
64    /// name of a time period when this host/service is checked
65    #[serde(
66        serialize_with = "serialize_none_as_empty_string_or_to_string",
67        deserialize_with = "deserialize_empty_string_or_parse"
68    )]
69    pub check_period: Option<IcingaTimePeriodName>,
70    /// check timeout
71    #[serde(default)]
72    #[serde(
73        serialize_with = "serialize_optional_duration_as_seconds",
74        deserialize_with = "deserialize_optional_seconds_as_duration"
75    )]
76    pub check_timeout: Option<time::Duration>,
77    /// the endpoint the command is executed on
78    #[serde(
79        serialize_with = "serialize_none_as_empty_string_or_to_string",
80        deserialize_with = "deserialize_empty_string_or_parse"
81    )]
82    pub command_endpoint: Option<IcingaEndpointName>,
83    /// number of active downtimes on the host/service
84    pub downtime_depth: u64,
85    /// whether active checks are enabled
86    pub enable_active_checks: bool,
87    /// enabled event handlers for this host/service
88    pub enable_event_handler: bool,
89    /// whether flap detection is enabled
90    pub enable_flapping: bool,
91    /// whether notifications are enabled
92    pub enable_notifications: bool,
93    /// whether passive checks are enabled
94    pub enable_passive_checks: bool,
95    /// whether performance data processing is enabled
96    pub enable_perfdata: bool,
97    /// the name of an event command that should be executed every time the host/service state changes or the host/service is in a SOFT state
98    #[serde(
99        serialize_with = "serialize_none_as_empty_string_or_to_string",
100        deserialize_with = "deserialize_empty_string_or_parse"
101    )]
102    pub event_command: Option<IcingaEventCommandName>,
103    /// contains the state of execute-command executions
104    pub executions: Option<()>,
105    /// whether the host/service is flapping between states
106    pub flapping: bool,
107    /// current flapping value in percent
108    pub flapping_current: f64,
109    /// a list of states that should be ignored during flapping calculations
110    #[serde(default)]
111    pub flapping_ignore_states: Option<Vec<IcingaHostOrServiceState>>,
112    /// when the last flapping change occurred
113    #[serde(
114        serialize_with = "serialize_optional_icinga_timestamp",
115        deserialize_with = "deserialize_optional_icinga_timestamp"
116    )]
117    pub flapping_last_change: Option<time::OffsetDateTime>,
118    /// deprecated and has no effect, replaced by flapping_threshold_low and flapping_threshold_high
119    pub flapping_threshold: f64,
120    /// the flapping lower bound in percent for a host/service to be considered flapping
121    pub flapping_threshold_low: f64,
122    /// the flapping upper bound in percent for a host/service to be considered flapping
123    pub flapping_threshold_high: f64,
124    /// force the next check (execute it now)
125    pub force_next_check: bool,
126    /// force next notification (send it now)
127    pub force_next_notification: bool,
128    /// whether the host/service problem is handled (downtime or acknowledgement)
129    pub handled: bool,
130    /// icon image for the host/service
131    #[serde(
132        serialize_with = "serialize_none_as_empty_string",
133        deserialize_with = "deserialize_empty_string_or_string"
134    )]
135    pub icon_image: Option<String>,
136    /// icon image alt text for the host/service
137    #[serde(
138        serialize_with = "serialize_none_as_empty_string",
139        deserialize_with = "deserialize_empty_string_or_string"
140    )]
141    pub icon_image_alt: Option<String>,
142    /// when the last check occurred
143    #[serde(
144        serialize_with = "serialize_icinga_timestamp",
145        deserialize_with = "deserialize_icinga_timestamp"
146    )]
147    pub last_check: time::OffsetDateTime,
148    /// the result of the last check
149    pub last_check_result: IcingaCheckResult,
150    /// when the last hard state change occurred
151    #[serde(
152        serialize_with = "serialize_icinga_timestamp",
153        deserialize_with = "deserialize_icinga_timestamp"
154    )]
155    pub last_hard_state_change: time::OffsetDateTime,
156    /// whether the host/service was reachable when the last check occurred
157    pub last_reachable: bool,
158    /// when the last state change occurred
159    #[serde(
160        serialize_with = "serialize_optional_icinga_timestamp",
161        deserialize_with = "deserialize_optional_icinga_timestamp"
162    )]
163    pub last_state_change: Option<time::OffsetDateTime>,
164    /// the previous state type (soft/hard)
165    pub last_state_type: IcingaStateType,
166    /// when the last UNREACHABLE state occurred
167    #[serde(
168        serialize_with = "serialize_optional_icinga_timestamp",
169        deserialize_with = "deserialize_optional_icinga_timestamp"
170    )]
171    pub last_state_unreachable: Option<time::OffsetDateTime>,
172    /// the number of times the host/service is checked before changing into a new hard state
173    pub max_check_attempts: u64,
174    /// when the next check occurs
175    #[serde(
176        serialize_with = "serialize_optional_icinga_timestamp",
177        deserialize_with = "deserialize_optional_icinga_timestamp"
178    )]
179    pub next_check: Option<time::OffsetDateTime>,
180    /// when the next check update is to be expected
181    #[serde(
182        serialize_with = "serialize_optional_icinga_timestamp",
183        deserialize_with = "deserialize_optional_icinga_timestamp"
184    )]
185    pub next_update: Option<time::OffsetDateTime>,
186    /// notes for the host/service
187    #[serde(
188        serialize_with = "serialize_none_as_empty_string",
189        deserialize_with = "deserialize_empty_string_or_string"
190    )]
191    pub notes: Option<String>,
192    /// URL for notes for the host/service
193    #[serde(
194        serialize_with = "serialize_none_as_empty_string",
195        deserialize_with = "deserialize_empty_string_or_string"
196    )]
197    pub notes_url: Option<String>,
198    /// when the previous state change occurred
199    #[serde(
200        serialize_with = "serialize_optional_icinga_timestamp",
201        deserialize_with = "deserialize_optional_icinga_timestamp"
202    )]
203    pub previous_state_change: Option<time::OffsetDateTime>,
204    /// whether the host/service is considered to be in a problem state type (not up)
205    pub problem: bool,
206    /// the interval used for checks when the host/service is in a SOFT state
207    #[serde(default)]
208    #[serde(
209        serialize_with = "serialize_optional_duration_as_seconds",
210        deserialize_with = "deserialize_optional_seconds_as_duration"
211    )]
212    pub retry_interval: Option<time::Duration>,
213    /// pre-calculated value, higher means more severe
214    pub severity: u64,
215    /// the current state type (soft/hard)
216    pub state_type: IcingaStateType,
217    /// treat all state changes as HARD changes
218    pub volatile: bool,
219}
220
221impl CustomVarHolder for IcingaCheckable {
222    fn custom_var_value(&self, name: &str) -> Option<&serde_json::Value> {
223        self.custom_var.custom_var_value(name)
224    }
225}