From a72fc0a09fc4742b0c6de791b30d152fe43da364 Mon Sep 17 00:00:00 2001 From: Vincent Stuyck Date: Fri, 27 Feb 2026 23:09:39 +0100 Subject: [PATCH] add hosttags --- src/api/tags.rs | 7 +++++++ src/main.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/api/tags.rs b/src/api/tags.rs index 4fcdc76..da69e79 100644 --- a/src/api/tags.rs +++ b/src/api/tags.rs @@ -3,6 +3,13 @@ use serde::{Deserialize, Serialize}; use schemars::JsonSchema; use crate::api::{BulkReadDomainExtension, DomainExtension, DomainType}; +use crate::{ApiClient, Client}; + +impl Client { + pub fn tag_api(&self) -> ApiClient { + self.into() + } +} #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] diff --git a/src/main.rs b/src/main.rs index 28e1422..cf60bbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,9 @@ async fn main() -> Result<()> { test_folders(client.clone()).await?; test_hosts(client.clone()).await?; + test_hosttags(client.clone()).await?; + info!("tests done; all pass"); Ok(()) } @@ -142,3 +144,53 @@ async fn test_hosts(client: Client) -> Result<()> { Ok(()) } + +async fn test_hosttags(client: Client) -> Result<()> { + use checkmk_api::api::tags::*; + const TESTTAG: &str = "test-tag-group"; + info!("testing hosttags"); + + let tagapi = client.tag_api(); + let creq = ExtendedTagGroup::new(TESTTAG.to_string(), "Test Tag Group".to_string()) + .with_topic("Testing".to_string()) + .with_help("A test tag group".to_string()) + .with_tag(Tag::new("test1".to_string(), "Test Tag 1".to_string())) + .with_tag(Tag::new("test2".to_string(), "Test Tag 2".to_string())); + + let ureq = TagUpdateRequest::new("Updated Test Tag Group".to_string(), false) + .with_topic("Updated Testing".to_string()) + .with_help("An updated test tag group".to_string()) + .with_tag(Tag::new("test3".to_string(), "Test Tag 3".to_string())); + + info!("creating test tag group"); + tagapi + .create(&creq, &()) + .await + .inspect_err(|e| error!("failed to create tag group: {e}"))?; + + let tag_group = tagapi + .read(TESTTAG, &()) + .await + .inspect_err(|e| error!("failed to read tag group: {e}"))?; + info!("tag group config: {tag_group:#?}"); + + info!("updating tag group"); + tagapi + .update(TESTTAG, &ureq) + .await + .inspect_err(|e| error!("failed to update tag group: {e}"))?; + + let tag_groups = tagapi + .bulk_read(&()) + .await + .inspect_err(|e| error!("failed to read all tag groups: {e}")); + info!("all tag groups: {tag_groups:?}"); + + info!("deleting tag group"); + tagapi + .delete(TESTTAG, &()) + .await + .inspect_err(|e| error!("failed to delete tag group: {e}"))?; + + Ok(()) +}