Skip to main content

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