Compare commits
No commits in common. "20d0c76e7a5d61892edaf1e7969cbd8d86fea8a0" and "62fca534a1caa4e7389cac54ab4c4d8a85d9c8cc" have entirely different histories.
20d0c76e7a
...
62fca534a1
@ -3,11 +3,10 @@ use std::fmt::Display;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::api::rules::contactgroups::HostContactGroups;
|
||||
use crate::api::rules::snmp::SnmpCommunity;
|
||||
use crate::api::{BulkReadDomainExtension, BulkUpdateDomainExtension, DomainExtension};
|
||||
use crate::api::{BulkReadDomainExtention, BulkUpdateDomainExtention, DomainExtention};
|
||||
use crate::{ApiClient, Client, Result};
|
||||
|
||||
pub const ROOT_FOLDER: &str = "/";
|
||||
@ -40,33 +39,15 @@ pub struct FolderAttributes {
|
||||
/// this attribute is not optional when queried from the api.
|
||||
/// It cannot be filled in when creating a new folder.
|
||||
pub meta_data: Option<MetaData>,
|
||||
// Additional attributes that can be used to categorize hosts. every tag is part of a tag_group
|
||||
// NOTE that checkmk always returns taggroups prefixed with "tag_"
|
||||
#[serde(default, flatten, skip_serializing_if = "HashMap::is_empty")]
|
||||
#[serde(flatten, skip_serializing_if = "HashMap::is_empty")]
|
||||
/// Additional attributes that can be used to categorize hosts. every tag is part of a tag_group
|
||||
/// NOTE that checkmk always returns taggroups prefixed with "tag_"
|
||||
pub tags: HashMap<String, String>,
|
||||
|
||||
|
||||
// these fields are used to prevent tags from taking them up
|
||||
#[serde(default)]
|
||||
management_snmp_community: Option<SnmpCommunity>,
|
||||
#[serde(default, skip_serializing)]
|
||||
management_address: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
management_protocol: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
management_ipmi_credentials: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
network_scan: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
network_scan_result: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
waiting_for_discovery: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
inventory_failed: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
locked_attributes: Value,
|
||||
#[serde(default, skip_serializing)]
|
||||
locked_by: Value,
|
||||
// TODO: to be implemented
|
||||
// #[serde(flatten, default)]
|
||||
// pub networkscan: NetworkScan,
|
||||
// #[serde(flatten, default)]
|
||||
// pub management: ManagementProtocol,
|
||||
}
|
||||
|
||||
impl FolderAttributes {
|
||||
@ -112,7 +93,7 @@ impl FolderAttributes {
|
||||
|
||||
pub fn add_tag(&mut self, taggroup: impl Display, tagvalue: String) {
|
||||
self.tags
|
||||
.insert(format!("tag_{taggroup}"), tagvalue);
|
||||
.insert(format!("tag_{taggroup}"), tagvalue.to_string());
|
||||
}
|
||||
pub fn with_tag(mut self, taggroup: impl Display, tagvalue: String) -> Self {
|
||||
self.add_tag(taggroup, tagvalue);
|
||||
@ -128,7 +109,7 @@ pub struct MetaData {
|
||||
pub created_by: Option<String>,
|
||||
}
|
||||
|
||||
impl DomainExtension for FolderConfig {
|
||||
impl DomainExtention for FolderConfig {
|
||||
const DOMAIN_TYPE: super::DomainType = super::DomainType::FolderConfig;
|
||||
|
||||
type CreationRequest = FolderCreationRequest;
|
||||
@ -246,10 +227,10 @@ impl FolderDeleteQuery {
|
||||
pub enum FolderDeleteMode {
|
||||
#[default]
|
||||
Recursive,
|
||||
AbortOnNonEmpty,
|
||||
AbotyOnNonEmpty,
|
||||
}
|
||||
|
||||
impl BulkReadDomainExtension for FolderConfig {
|
||||
impl BulkReadDomainExtention for FolderConfig {
|
||||
type BulkReadQuery = FolderBulkReadQuery;
|
||||
}
|
||||
|
||||
@ -265,7 +246,7 @@ impl FolderBulkReadQuery {
|
||||
}
|
||||
}
|
||||
|
||||
impl BulkUpdateDomainExtension for FolderConfig {
|
||||
impl BulkUpdateDomainExtention for FolderConfig {
|
||||
type BulkUpdateRequest = FolderBulkUpdateRequest;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::api::folders::FolderAttributes;
|
||||
use crate::api::{
|
||||
BulkCreateDomainExtension, BulkDeleteDomainExtension, BulkReadDomainExtension,
|
||||
BulkUpdateDomainExtension, DomainExtension,
|
||||
BulkCreateDomainExtention, BulkDeleteDomainExtention, BulkReadDomainExtention,
|
||||
BulkUpdateDomainExtention, DomainExtention,
|
||||
};
|
||||
use crate::{ApiClient, Client};
|
||||
|
||||
@ -18,32 +16,14 @@ impl Client {
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct HostConfig {
|
||||
pub folder: String,
|
||||
pub attributes: HostAttributes,
|
||||
pub effective_attributes: HostAttributes,
|
||||
pub attributes: FolderAttributes,
|
||||
pub effective_attributes: FolderAttributes,
|
||||
pub is_cluster: bool,
|
||||
pub is_offline: bool,
|
||||
pub cluster_nodes: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct HostAttributes {
|
||||
#[serde(default)]
|
||||
alias: Option<String>,
|
||||
#[serde(default)]
|
||||
ipaddress: Option<String>,
|
||||
#[serde(default)]
|
||||
ipv6address: Option<String>,
|
||||
#[serde(default)]
|
||||
additional_ipv4addresses: Vec<Ipv4Addr>,
|
||||
#[serde(default)]
|
||||
additional_ipv6addresses: Vec<Ipv6Addr>,
|
||||
|
||||
#[serde(flatten, default)]
|
||||
folder_attributes: FolderAttributes
|
||||
}
|
||||
|
||||
impl DomainExtension for HostConfig {
|
||||
impl DomainExtention for HostConfig {
|
||||
const DOMAIN_TYPE: super::DomainType = super::DomainType::HostConfig;
|
||||
|
||||
type CreationRequest = HostCreationRequest;
|
||||
@ -55,7 +35,7 @@ impl DomainExtension for HostConfig {
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct HostCreationRequest {
|
||||
pub host_name: String,
|
||||
pub hostname: String,
|
||||
pub folder: String,
|
||||
pub attributes: FolderAttributes,
|
||||
}
|
||||
@ -80,7 +60,7 @@ pub struct HostUpdateRequest {
|
||||
impl HostCreationRequest {
|
||||
pub fn new(hostname: String, folder: String, attributes: FolderAttributes) -> Self {
|
||||
HostCreationRequest {
|
||||
host_name: hostname,
|
||||
hostname,
|
||||
folder,
|
||||
attributes,
|
||||
}
|
||||
@ -125,14 +105,14 @@ impl HostUpdateRequest {
|
||||
}
|
||||
}
|
||||
|
||||
impl BulkCreateDomainExtension for HostConfig {}
|
||||
impl BulkReadDomainExtension for HostConfig {
|
||||
impl BulkCreateDomainExtention for HostConfig {}
|
||||
impl BulkReadDomainExtention for HostConfig {
|
||||
type BulkReadQuery = HostBulkReadQuery;
|
||||
}
|
||||
impl BulkUpdateDomainExtension for HostConfig {
|
||||
impl BulkUpdateDomainExtention for HostConfig {
|
||||
type BulkUpdateRequest = HostBulkUpdateRequest;
|
||||
}
|
||||
impl BulkDeleteDomainExtension for HostConfig {}
|
||||
impl BulkDeleteDomainExtention for HostConfig {}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize)]
|
||||
pub struct HostBulkReadQuery {
|
||||
|
||||
@ -81,7 +81,7 @@ pub(crate) struct DomainCollection<E> {
|
||||
// pub extensions: Option<E>,
|
||||
}
|
||||
|
||||
pub trait DomainExtension: DeserializeOwned + Serialize {
|
||||
pub trait DomainExtention: DeserializeOwned + Serialize {
|
||||
const DOMAIN_TYPE: DomainType;
|
||||
|
||||
type CreationRequest: Serialize;
|
||||
@ -91,14 +91,14 @@ pub trait DomainExtension: DeserializeOwned + Serialize {
|
||||
type DeleteQuery: Serialize;
|
||||
}
|
||||
|
||||
// these are essential tags for domain extensions to signal that bulk operations are possible
|
||||
// not every extension supports bulk operations. and not all extensions that do support all of them
|
||||
// these are essentials tags for domain extentions to signal that bulk operations are possible
|
||||
// not every extention supports bulk operations. and not all extentions that do support all of them
|
||||
// and those that do tend to have a bit different types
|
||||
pub trait BulkCreateDomainExtension: DomainExtension {}
|
||||
pub trait BulkReadDomainExtension: DomainExtension {
|
||||
pub trait BulkCreateDomainExtention: DomainExtention {}
|
||||
pub trait BulkReadDomainExtention: DomainExtention {
|
||||
type BulkReadQuery: Serialize;
|
||||
}
|
||||
pub trait BulkUpdateDomainExtension: DomainExtension {
|
||||
pub trait BulkUpdateDomainExtention: DomainExtention {
|
||||
type BulkUpdateRequest: Serialize;
|
||||
}
|
||||
pub trait BulkDeleteDomainExtension: DomainExtension {}
|
||||
pub trait BulkDeleteDomainExtention: DomainExtention {}
|
||||
|
||||
@ -5,6 +5,6 @@ pub struct HostContactGroups {
|
||||
groups: Vec<String>,
|
||||
r#use: bool,
|
||||
use_for_services: bool,
|
||||
recurse_use: bool,
|
||||
recurse_perms: bool,
|
||||
recuse_use: bool,
|
||||
recuse_perms: bool,
|
||||
}
|
||||
|
||||
@ -11,8 +11,8 @@ use serde::de::DeserializeOwned;
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
use crate::api::{
|
||||
BulkCreateDomainExtension, BulkDeleteDomainExtension, BulkReadDomainExtension,
|
||||
BulkUpdateDomainExtension, DomainCollection, DomainExtension, DomainObject, DomainType,
|
||||
BulkCreateDomainExtention, BulkDeleteDomainExtention, BulkReadDomainExtention,
|
||||
BulkUpdateDomainExtention, DomainCollection, DomainExtention, DomainObject, DomainType,
|
||||
};
|
||||
use crate::{Error, Result};
|
||||
|
||||
@ -26,8 +26,8 @@ pub(crate) struct InnerClient {
|
||||
|
||||
#[derive(Default, PartialEq, Eq)]
|
||||
enum SslStrategy {
|
||||
NoSsl,
|
||||
IgnoreHostname,
|
||||
NoSll,
|
||||
IngoreHostname,
|
||||
IgnoreCertificate,
|
||||
#[default]
|
||||
Strict,
|
||||
@ -96,7 +96,7 @@ pub enum ClientBuildError {
|
||||
#[error("failed to build client: {0}")]
|
||||
BuildClient(#[from] reqwest::Error),
|
||||
#[error(
|
||||
"invalid credentials. these can only consist of visible ASCII characters (i.e. (32-127))"
|
||||
"invalid credentials. thise can only consist of visibly ASCII characters (ie. (32-127))"
|
||||
)]
|
||||
InvalidCredentials(#[from] reqwest::header::InvalidHeaderValue),
|
||||
}
|
||||
@ -107,14 +107,14 @@ impl ClientBuilder<RequiresNothing> {
|
||||
self
|
||||
}
|
||||
pub fn without_ssl(mut self) -> Self {
|
||||
self.ssl = SslStrategy::NoSsl;
|
||||
self.ssl = SslStrategy::NoSll;
|
||||
self
|
||||
}
|
||||
pub fn ignore_hostname_verification(mut self) -> Self {
|
||||
self.ssl = SslStrategy::IgnoreHostname;
|
||||
self.ssl = SslStrategy::IngoreHostname;
|
||||
self
|
||||
}
|
||||
pub fn ignore_certificate_verification(mut self) -> Self {
|
||||
pub fn ignore_certificate_veritifcation(mut self) -> Self {
|
||||
self.ssl = SslStrategy::IgnoreCertificate;
|
||||
self
|
||||
}
|
||||
@ -128,7 +128,7 @@ impl ClientBuilder<RequiresNothing> {
|
||||
}
|
||||
|
||||
fn protocol(&self) -> &str {
|
||||
if self.ssl == SslStrategy::NoSsl {
|
||||
if self.ssl == SslStrategy::NoSll {
|
||||
"http"
|
||||
} else {
|
||||
"https"
|
||||
@ -137,7 +137,7 @@ impl ClientBuilder<RequiresNothing> {
|
||||
fn port(&self) -> u16 {
|
||||
if self.port != 0 {
|
||||
self.port
|
||||
} else if self.ssl == SslStrategy::NoSsl {
|
||||
} else if self.ssl == SslStrategy::NoSll {
|
||||
80
|
||||
} else {
|
||||
443
|
||||
@ -165,7 +165,7 @@ impl ClientBuilder<RequiresNothing> {
|
||||
let mut builder = reqwest::ClientBuilder::new()
|
||||
.default_headers(headers)
|
||||
.danger_accept_invalid_certs(self.ssl == SslStrategy::IgnoreCertificate)
|
||||
.danger_accept_invalid_hostnames(self.ssl == SslStrategy::IgnoreHostname);
|
||||
.danger_accept_invalid_hostnames(self.ssl == SslStrategy::IngoreHostname);
|
||||
|
||||
if let Some(sock) = self.resolve {
|
||||
builder = builder.resolve(&self.hostname, sock);
|
||||
@ -181,7 +181,7 @@ impl ClientBuilder<RequiresNothing> {
|
||||
};
|
||||
|
||||
// checkmk api struggles with more than 10 requests at a time
|
||||
// not sure if this has been improved since 2.2
|
||||
// not sure if this has been inproved since 2.2
|
||||
let semaphore = Semaphore::new(10);
|
||||
|
||||
Ok(Client(Arc::new(InnerClient {
|
||||
@ -282,7 +282,7 @@ impl InnerClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn create_domain_object<E: DomainExtension>(
|
||||
pub(crate) async fn create_domain_object<E: DomainExtention>(
|
||||
&self,
|
||||
body: &E::CreationRequest,
|
||||
query: &E::CreationQuery,
|
||||
@ -297,7 +297,7 @@ impl InnerClient {
|
||||
|
||||
self.invoke_api(request).await
|
||||
}
|
||||
pub(crate) async fn read_domain_object<E: DomainExtension>(
|
||||
pub(crate) async fn read_domain_object<E: DomainExtention>(
|
||||
&self,
|
||||
id: impl Display,
|
||||
query: &E::ReadQuery,
|
||||
@ -311,7 +311,7 @@ impl InnerClient {
|
||||
|
||||
self.query_api(request).await
|
||||
}
|
||||
pub(crate) async fn update_domain_object<E: DomainExtension>(
|
||||
pub(crate) async fn update_domain_object<E: DomainExtention>(
|
||||
&self,
|
||||
id: impl Display,
|
||||
request: &E::UpdateRequest,
|
||||
@ -328,7 +328,7 @@ impl InnerClient {
|
||||
|
||||
self.invoke_api(request).await
|
||||
}
|
||||
pub(crate) async fn delete_domain_object<E: DomainExtension>(
|
||||
pub(crate) async fn delete_domain_object<E: DomainExtention>(
|
||||
&self,
|
||||
id: impl Display,
|
||||
query: &E::DeleteQuery,
|
||||
@ -343,13 +343,13 @@ impl InnerClient {
|
||||
self.invoke_api(request).await
|
||||
}
|
||||
|
||||
pub(crate) async fn bulk_create_domain_objects<E: BulkCreateDomainExtension>(
|
||||
pub(crate) async fn bulk_create_domain_objects<E: BulkCreateDomainExtention>(
|
||||
&self,
|
||||
entries: &[E::CreationRequest],
|
||||
query: &E::CreationQuery,
|
||||
) -> Result<()> {
|
||||
#[derive(Serialize)]
|
||||
struct Request<'a, D: BulkCreateDomainExtension> {
|
||||
struct Request<'a, D: BulkCreateDomainExtention> {
|
||||
entries: &'a [D::CreationRequest],
|
||||
}
|
||||
|
||||
@ -363,7 +363,7 @@ impl InnerClient {
|
||||
|
||||
self.invoke_api(request).await
|
||||
}
|
||||
pub(crate) async fn bulk_read_domain_objects<E: BulkReadDomainExtension>(
|
||||
pub(crate) async fn bulk_read_domain_objects<E: BulkReadDomainExtention>(
|
||||
&self,
|
||||
query: &E::BulkReadQuery,
|
||||
) -> Result<Vec<DomainObject<E>>> {
|
||||
@ -377,12 +377,12 @@ impl InnerClient {
|
||||
let response: DomainCollection<E> = self.query_api(request).await?;
|
||||
Ok(response.value)
|
||||
}
|
||||
pub(crate) async fn bulk_update_domain_objects<E: BulkUpdateDomainExtension>(
|
||||
pub(crate) async fn bulk_update_domain_objects<E: BulkUpdateDomainExtention>(
|
||||
&self,
|
||||
entries: &[E::BulkUpdateRequest],
|
||||
) -> Result<()> {
|
||||
#[derive(Serialize)]
|
||||
struct Request<'a, D: BulkUpdateDomainExtension> {
|
||||
struct Request<'a, D: BulkUpdateDomainExtention> {
|
||||
entries: &'a [D::BulkUpdateRequest],
|
||||
}
|
||||
|
||||
@ -395,7 +395,7 @@ impl InnerClient {
|
||||
|
||||
self.invoke_api(request).await
|
||||
}
|
||||
pub(crate) async fn bulk_delete_domain_objects<E: BulkDeleteDomainExtension>(
|
||||
pub(crate) async fn bulk_delete_domain_objects<E: BulkDeleteDomainExtention>(
|
||||
&self,
|
||||
entries: &[String],
|
||||
) -> Result<()> {
|
||||
@ -433,12 +433,12 @@ impl Display for BulkAction {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ApiClient<D: DomainExtension> {
|
||||
pub struct ApiClient<D: DomainExtention> {
|
||||
pub(crate) inner: Arc<InnerClient>,
|
||||
_marker: PhantomData<D>,
|
||||
}
|
||||
|
||||
impl<D: DomainExtension> From<&Client> for ApiClient<D> {
|
||||
impl<D: DomainExtention> From<&Client> for ApiClient<D> {
|
||||
fn from(value: &Client) -> Self {
|
||||
Self {
|
||||
inner: value.0.clone(),
|
||||
@ -447,7 +447,7 @@ impl<D: DomainExtension> From<&Client> for ApiClient<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DomainExtension> ApiClient<D> {
|
||||
impl<D: DomainExtention> ApiClient<D> {
|
||||
pub async fn create(
|
||||
&self,
|
||||
request: &D::CreationRequest,
|
||||
@ -469,7 +469,7 @@ impl<D: DomainExtension> ApiClient<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: BulkCreateDomainExtension> ApiClient<D> {
|
||||
impl<D: BulkCreateDomainExtention> ApiClient<D> {
|
||||
pub async fn bulk_create(
|
||||
&self,
|
||||
request: &[D::CreationRequest],
|
||||
@ -481,7 +481,7 @@ impl<D: BulkCreateDomainExtension> ApiClient<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: BulkReadDomainExtension> ApiClient<D> {
|
||||
impl<D: BulkReadDomainExtention> ApiClient<D> {
|
||||
pub async fn bulk_read(&self, query: &D::BulkReadQuery) -> Result<Vec<D>> {
|
||||
let objs = self.inner.bulk_read_domain_objects::<D>(query).await?;
|
||||
let exts = objs.into_iter().map(|obj| obj.extensions).collect();
|
||||
@ -489,13 +489,13 @@ impl<D: BulkReadDomainExtension> ApiClient<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: BulkUpdateDomainExtension> ApiClient<D> {
|
||||
impl<D: BulkUpdateDomainExtention> ApiClient<D> {
|
||||
pub async fn bulk_update(&self, entries: &[D::BulkUpdateRequest]) -> Result<()> {
|
||||
self.inner.bulk_update_domain_objects::<D>(entries).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: BulkDeleteDomainExtension> ApiClient<D> {
|
||||
impl<D: BulkDeleteDomainExtention> ApiClient<D> {
|
||||
pub async fn bulk_delete(&self, ids: &[String]) -> Result<()> {
|
||||
self.inner.bulk_delete_domain_objects::<D>(ids).await
|
||||
}
|
||||
|
||||
@ -15,14 +15,14 @@ pub enum Error {
|
||||
#[error(
|
||||
"Failed to send request: {}: {}", .0,
|
||||
.0.cause().map(|e| e.to_string())
|
||||
.unwrap_or_else(|| "Unknown Cause".to_string())
|
||||
.unwrap_or_else(|| "Uknown Cause".to_string())
|
||||
)]
|
||||
SendRequest(#[source] reqwest::Error),
|
||||
#[error("Failed to receive response-body: {0}")]
|
||||
ReceiveBody(#[source] reqwest::Error),
|
||||
#[error("Failed to deserialize response: {0}")]
|
||||
DeserializeResponse(#[source] serde_json::Error),
|
||||
#[error("Received an error from checkmk ({}): {}", .0.status, .0.detail)]
|
||||
#[error("Recieved an error from checkmk ({}): {}", .0.status, .0.detail)]
|
||||
CheckmkError(#[source] CheckmkError),
|
||||
|
||||
#[error("Checkmk site has not yet started. log in as site user and execute 'omd start'")]
|
||||
|
||||
65
src/main.rs
65
src/main.rs
@ -24,7 +24,6 @@ async fn main() -> Result<()> {
|
||||
.unwrap();
|
||||
|
||||
test_folders(client.clone()).await?;
|
||||
test_hosts(client.clone()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -49,13 +48,11 @@ async fn test_folders(client: Client) -> Result<()> {
|
||||
.create(&creq, &())
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to create folder: {e}"))?;
|
||||
|
||||
let folder = folderapi
|
||||
.read(TESTDIRQRY, &())
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to read folder: {e}"))?;
|
||||
info!("folder config on site: {folder:?}");
|
||||
|
||||
info!("updating folder");
|
||||
folderapi
|
||||
.update(TESTDIRQRY, &ureq1)
|
||||
@ -67,7 +64,6 @@ async fn test_folders(client: Client) -> Result<()> {
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to read all folders: {e}"));
|
||||
info!("folder config on site: {folders:?}");
|
||||
|
||||
folderapi
|
||||
.bulk_update(&[FolderBulkUpdateRequest::new(TESTDIRQRY.to_string(), ureq2)])
|
||||
.await
|
||||
@ -81,64 +77,3 @@ async fn test_folders(client: Client) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn test_hosts(client: Client) -> Result<()> {
|
||||
use checkmk_api::api::hosts::*;
|
||||
use checkmk_api::api::folders::FolderAttributes;
|
||||
const TESTHOST: &str = "test-host";
|
||||
info!("testing hosts");
|
||||
|
||||
let hostapi = client.host_api();
|
||||
let creq = HostCreationRequest::new(
|
||||
TESTHOST.to_string(),
|
||||
"~".to_string(),
|
||||
FolderAttributes::default().with_site("dev".to_string())
|
||||
);
|
||||
let cquery = HostCreationQuery::new(false);
|
||||
let rquery = HostReadQuery::new(true);
|
||||
let ureq1 = HostUpdateRequest::replace(
|
||||
FolderAttributes::default()
|
||||
.with_site("dev".to_string())
|
||||
.with_label("environment".to_string(), "test".to_string())
|
||||
);
|
||||
let ureq2 = HostUpdateRequest::update(
|
||||
FolderAttributes::default().with_label("purpose".to_string(), "testing".to_string())
|
||||
);
|
||||
|
||||
info!("creating test host");
|
||||
hostapi
|
||||
.create(&creq, &cquery)
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to create host: {e}"))?;
|
||||
|
||||
let host = hostapi
|
||||
.read(TESTHOST, &rquery)
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to read host: {e}"))?;
|
||||
info!("host config: {host:#?}");
|
||||
|
||||
info!("updating host");
|
||||
hostapi
|
||||
.update(TESTHOST, &ureq1)
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to update host: {e}"))?;
|
||||
|
||||
let hosts = hostapi
|
||||
.bulk_read(&HostBulkReadQuery::new().with_effective_attributes(true))
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to read all hosts: {e}"));
|
||||
info!("all hosts: {hosts:?}");
|
||||
|
||||
hostapi
|
||||
.bulk_update(&[HostBulkUpdateRequest::new(TESTHOST.to_string(), ureq2)])
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to do a bulk update of hosts: {e}"))?;
|
||||
|
||||
info!("deleting host");
|
||||
hostapi
|
||||
.delete(TESTHOST, &())
|
||||
.await
|
||||
.inspect_err(|e| error!("failed to delete host: {e}"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user