icinga2_api/api/query/monitoring_objects/
service.rs1crate::types::query::query_with_joins!(
6 ListServices,
7 ListServicesBuilder,
8 monitoring_objects,
9 service,
10 IcingaService,
11 IcingaServiceJoinTypes,
12 IcingaServiceJoins,
13 IcingaObjectType::Service,
14 "v1/objects/services"
15);
16
17#[cfg(test)]
18mod test {
19 use super::*;
20 use std::error::Error;
21 use tracing_test::traced_test;
22
23 use crate::api::blocking::Icinga2;
24
25 #[traced_test]
26 #[test]
27 fn test_services() -> Result<(), Box<dyn Error>> {
28 dotenvy::dotenv()?;
29 let icinga2 = Icinga2::from_config_file(std::path::Path::new(&std::env::var(
30 "ICINGA_TEST_INSTANCE_CONFIG",
31 )?))?;
32 let api_endpoint = ListServices::builder()
33 .joins(IcingaJoins::AllJoins)
34 .meta([IcingaMetadataType::UsedBy, IcingaMetadataType::Location])
35 .build()?;
36 let _response: ResultsWrapper<
37 QueryResultObjectWithJoins<IcingaService, IcingaServiceJoins>,
38 > = icinga2.rest(api_endpoint)?;
39 Ok(())
40 }
41
42 #[traced_test]
43 #[test]
44 fn test_services_partial_host_join() -> Result<(), Box<dyn Error>> {
45 dotenvy::dotenv()?;
46 let icinga2 = Icinga2::from_config_file(std::path::Path::new(&std::env::var(
47 "ICINGA_TEST_INSTANCE_CONFIG",
48 )?))?;
49 let mut partial = BTreeMap::new();
50 partial.insert(IcingaServiceJoinTypes::Host, vec!["name"]);
51 let api_endpoint = ListServices::builder()
52 .joins(IcingaJoins::SpecificJoins {
53 full: vec![],
54 partial,
55 })
56 .meta([IcingaMetadataType::UsedBy, IcingaMetadataType::Location])
57 .build()?;
58 let _response: ResultsWrapper<
59 QueryResultObjectWithJoins<IcingaService, IcingaServiceJoins>,
60 > = icinga2.rest(api_endpoint)?;
61 Ok(())
62 }
63
64 #[traced_test]
65 #[test]
66 fn test_services_filtered() -> Result<(), Box<dyn Error>> {
67 dotenvy::dotenv()?;
68 let icinga2 = Icinga2::from_config_file(std::path::Path::new(&std::env::var(
69 "ICINGA_TEST_INSTANCE_CONFIG",
70 )?))?;
71 let api_endpoint = ListServices::builder()
72 .filter(IcingaFilter {
73 object_type: IcingaObjectType::Service,
74 filter: "service.state == ServiceUnknown && service.vars.serviceSeverity == filter_severity".to_string(),
75 filter_vars: BTreeMap::from([("filter_severity".to_string(), serde_json::json!("imminent"))]),
76 })
77 .build()?;
78 let _response: ResultsWrapper<
79 QueryResultObjectWithJoins<IcingaService, IcingaServiceJoins>,
80 > = icinga2.rest(api_endpoint)?;
81 Ok(())
82 }
83}