add hosttags
This commit is contained in:
parent
c39315b2b7
commit
a72fc0a09f
@ -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<TagGroup> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
|
||||
|
||||
52
src/main.rs
52
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(())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user