icinga2_api/types/monitoring_objects/
notification.rs

1//! Notification
2//!
3//! [Official Documentation](https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#notification)
4//!
5//! [Definition in Icinga Source](https://github.com/Icinga/icinga2/blob/master/lib/icinga/notification.ti)
6
7use std::collections::BTreeMap;
8
9use serde::{Deserialize, Serialize};
10
11use crate::serde::{
12    deserialize_optional_icinga_timestamp, deserialize_optional_seconds_as_duration,
13    serialize_optional_duration_as_seconds, serialize_optional_icinga_timestamp,
14};
15use crate::types::common::custom_var_object::CustomVarHolder;
16use crate::types::enums::notification_filter::IcingaNotificationFilter;
17use crate::types::enums::notification_type::IcingaNotificationType;
18use crate::types::{
19    common::custom_var_object::IcingaCustomVarObject,
20    enums::object_type::IcingaObjectType,
21    names::{
22        IcingaEndpointName, IcingaHostName, IcingaNotificationCommandName, IcingaServiceName,
23        IcingaTimePeriodName, IcingaUserGroupName, IcingaUserName,
24    },
25};
26
27/// an icinga notification
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
29pub struct IcingaNotification {
30    /// type of icinga object, should always be Notification for this
31    #[serde(rename = "type")]
32    pub object_type: IcingaObjectType,
33    /// shared config object and custom variable fields
34    #[serde(flatten)]
35    pub custom_var: IcingaCustomVarObject,
36    /// the notification command to call
37    pub command: Option<IcingaNotificationCommandName>,
38    /// the renotification interval
39    #[serde(
40        serialize_with = "serialize_optional_duration_as_seconds",
41        deserialize_with = "deserialize_optional_seconds_as_duration"
42    )]
43    pub interval: Option<time::Duration>,
44    /// the name of the time period when this notification is active
45    pub period: Option<IcingaTimePeriodName>,
46    /// the users to notify
47    pub users: Option<Vec<IcingaUserName>>,
48    /// the user groups to notify
49    pub user_groups: Option<Vec<IcingaUserGroupName>>,
50    /// A dictionary containing begin and end attributes for the notification.
51    pub times: Option<BTreeMap<String, serde_json::Value>>,
52    /// A list of type filters when this notification should be triggered. By default everything is matched.
53    pub types: Option<Vec<IcingaNotificationType>>,
54    /// A list of state filters when this notification should be triggered. By default everything is matched. Note that the states filter is ignored for notifications of type Acknowledgement!
55    pub states: Option<Vec<IcingaNotificationFilter>>,
56    /// The name of the host this notification belongs to.
57    pub host_name: IcingaHostName,
58    /// The short name of the service this notification belongs to. If omitted, this notification object is treated as host notification.
59    pub service_name: Option<IcingaServiceName>,
60    /// the users notified by this notification
61    pub notified_problem_users: Option<Vec<IcingaUserName>>,
62    /// do not send any more notifications for this issue
63    pub no_more_notifications: Option<bool>,
64    /// when was this notification last sent
65    #[serde(
66        serialize_with = "serialize_optional_icinga_timestamp",
67        deserialize_with = "deserialize_optional_icinga_timestamp"
68    )]
69    pub last_notification: Option<time::OffsetDateTime>,
70    /// when will this notification be sent next
71    #[serde(
72        serialize_with = "serialize_optional_icinga_timestamp",
73        deserialize_with = "deserialize_optional_icinga_timestamp"
74    )]
75    pub next_notification: Option<time::OffsetDateTime>,
76    /// the number of notifications sent out
77    pub notification_number: u64,
78    /// the last notification that was about a problem (as opposed to acknowledgement or end of problem)
79    #[serde(
80        serialize_with = "serialize_optional_icinga_timestamp",
81        deserialize_with = "deserialize_optional_icinga_timestamp"
82    )]
83    pub last_problem_notification: Option<time::OffsetDateTime>,
84    /// the command endpoint for the notification command
85    pub command_endpoint: Option<IcingaEndpointName>,
86}
87
88impl CustomVarHolder for IcingaNotification {
89    fn custom_var_value(&self, name: &str) -> Option<&serde_json::Value> {
90        self.custom_var.custom_var_value(name)
91    }
92}