opsview/
lib.rs

1#![warn(missing_docs)]
2#![recursion_limit = "1024"]
3//! # Rust Opsview API Client library
4//!
5//! The `opsview` crate provides a Rust interface to the [Opsview REST
6//! API](https://docs.itrsgroup.com/docs/opsview/current/rest-api/rest-api-background/api-introduction/index.html).
7//!
8//! ## Example
9//! ```rust,no_run
10//! use opsview::prelude::*;
11//! use opsview::client::OpsviewClient;
12//! use opsview::config::{Host, HostGroup, HostCheckCommand, MonitoringCluster};
13//!
14//! #[tokio::main]
15//! async fn main() {
16//!    // Create a new OpsviewClient instance.
17//!    let client = OpsviewClient::builder()
18//!        .url("https://opsview.example.com/")
19//!        .username("admin")
20//!        .password("initial")
21//!        .ignore_cert(false) // Set to true if using a self-signed certificate.
22//!        .build()
23//!        .await
24//!        .unwrap();
25//!
26//!    // Build a new `HostGroup` configuration object.
27//!    let mut host_group = HostGroup::builder()
28//!        .name("My Hostgroup")
29//!        .parent(HostGroup::minimal("Opsview").unwrap())
30//!        .build()
31//!        .unwrap();
32//!
33//!    // If it exists already, then fetch it.
34//!    if host_group.exists(&client).await.unwrap() {
35//!        host_group = host_group.fetch(&client, None).await.unwrap();
36//!    } else {
37//!        host_group.create(&client).await.unwrap();
38//!    }
39//!
40//!    // Build a new `HostCheckCommand` configuration object.
41//!    let mut host_check_command = HostCheckCommand::minimal("ping").unwrap();
42//!
43//!    // If it exists already, then fetch it.
44//!    if host_check_command.exists(&client).await.unwrap() {
45//!        host_check_command = host_check_command.fetch(&client, None).await.unwrap();
46//!    } else {
47//!        host_check_command.create(&client).await.unwrap();
48//!    }
49//!
50//!    // Build a new `Host` configuration object.
51//!    let host = Host::builder()
52//!        .name("My_Host")
53//!        .hostgroup(host_group)
54//!        .check_command(host_check_command)
55//!        .ip("192.168.1.100")
56//!        .monitored_by(MonitoringCluster::minimal("Master Monitoring Server").unwrap())
57//!        .build()
58//!        .unwrap();
59//!
60//!    // Create the host if it doesn't exist already.
61//!    if !host.exists(&client).await.unwrap() {
62//!        host.create(&client).await.unwrap();
63//!    }
64//!
65//!    // Apply the changes and logout.
66//!    client.apply_changes().await.unwrap();
67//!    client.logout().await.unwrap();
68//! }
69//! ```
70
71/// The `client` module contains the `OpsviewClient` struct and methods for interacting with the
72/// Opsview API using this Client.
73pub mod client;
74
75/// The `config` module contains most of the structs and methods for interacting with the Opsview
76/// via the REST API /config endpoint.
77pub mod config;
78
79/// The `error` module contains the `OpsviewClientError` enum , the `OpsviewConfigError`, and
80/// methods for handling errors
81pub mod error;
82
83/// The `instance` module contains the `OpsviewInstance` struct and methods for interacting with
84/// an Opsview instance at large.
85pub mod instance;
86
87/// The `prelude` module contains the most commonly used types and traits from the `opsview` crate.
88pub mod prelude;
89pub use prelude::*;
90
91/// The `util` module contains utility functions and types used throughout the `opsview` crate.
92pub mod util;
93
94/// The `state` module contains the `HostState` and `ServiceCheckState` enums.
95pub mod state;