Rust Opsview API Client Library
Introduction
The opsview crate is a Rust library designed to interact with the Opsview monitoring software. It provides a comprehensive coverage of the Opsview REST API and allows you to handle Opsview objects such as hosts, service checks, host groups, and more. The initial focus is on the client and config modules which enables the user to perform all kinds of object configuration management using this Rust library.
Project Status
This project is currently in development and is subject to change at any time. It is not yet complete.
Features
- Comprehensive coverage of Opsview objects: Hosts, Service Checks, Host Groups, etc. All objects in the configuration API are available as native Rust objects.
- Builder pattern objects for creating and configuring Opsview objects.
- Asynchronous API interactions with built-in error handling.
- Custom serialization and deserialization for Opsview API compatibility.
Why should you use this library?
This library aims to provide client side validation of as many fields as possible. That means that you can add solid error handling of any incompatible field values before even making an API call to the Opsview server and instead catch and handle the error returned by the API.
For example, let's say that your program parses a name from some file and
decides to create a Hashtag with the name My New Hashtag. You don't have to
cover all name checks on your side, you can simply try to build a Hashtag
using either of the associated builder or minimal functions and then match
the Result. No need to even connect to the Opsview API.
Example:
use Hashtag;
use *;
async
This allows you to write robust solutions with fewer errors.
Adding these checks is a priority but still a work in progress. All fields missing validation are marked with a TODO in the source code. If you find one that doesn't, please let me know.
Basic Usage
This library makes frequent use of the Builder pattern to create and configure Opsview objects.
All configuration related objects such as Hashtag, Host, ServiceCheck and
so on are represented as native Rust structs with the trait ConfigObject.
These all have the Builder trait which defines the builder() function which
will initiate a new builder object.
The standard pattern for creating a new object is to use the associated
builder() function of the type of ConfigObject that you want to create to
create a new builder, then chain the builder's methods to configure the object,
and finally call build() to create the object. Using the build() method will
give you some assurances that the ConfigObject that you are trying to create
is valid.
Note that there are no online checks when building the object, you will still have to check for existing names, etc, at some point. But it will force you to populate all required fields with valid data.
It is generally discouraged to create ConfigObject structs directly, as this
may result in invalid objects that cannot be used with the Opsview API. These
objects are primarily used for deserialization from the Opsview API.
Here's a quick example to get you started with this library:
use ;
async
async
A more complex example:
use OpsviewClient;
use ;
use *;
async
Documentation
For detailed documentation on all available modules, structs, and functions, please refer to the generated docs using:
Affiliation with ITRS Group
This project is not affiliated with ITRS Group.
Support and bug reports
Please direct any questions or bug reports to the GitHub page of the project and not to ITRS Group Support.
Testing
For testing with a live Opsview server, make sure to populate the following environment variables:
When running the ignored tests, make sure to use --test-threads=1 and that
there are no unsaved changes on the Opsview server in question.
License
Copyright © 2024 Johan Thorén johan@thoren.xyz
This project is released under the ISC license. See the LICENSE file for more details.