Skip to main content

ZabbixInstance

Struct ZabbixInstance 

Source
pub struct ZabbixInstance { /* private fields */ }
Expand description

Represents an active connection to a Zabbix server.

Implementations§

Source§

impl ZabbixInstance

Source

pub fn builder(url: &str) -> ZabbixInstanceBuilder

Creates a new ZabbixInstanceBuilder to configure the connection.

The URL should be the base URL of the Zabbix server, without the /api_jsonrpc.php suffix.

§Examples
use http_request_zabbix::ZabbixInstance;

let builder = ZabbixInstance::builder("http://localhost/zabbix");
Source§

impl ZabbixInstance

Source

pub fn id(&self) -> &str

Returns the internally generated UUID for this instance.

You can use it to identify the instance in your logs.

§Examples
use http_request_zabbix::{ZabbixInstance, AuthType};

let zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix")
    .build()
    .unwrap()
    .login(AuthType::UsernamePassword("Admin".to_string(), "zabbix".to_string()))
    .unwrap();
println!("Instance ID: {}", zabbix.id());
Source

pub fn url(&self) -> &str

Returns the Zabbix API URL this instance connects to (without the /api_jsonrpc.php suffix).

§Examples
use http_request_zabbix::{ZabbixInstance, AuthType};

let zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix")
    .build()
    .unwrap()
    .login(AuthType::UsernamePassword("Admin".to_string(), "zabbix".to_string()))
    .unwrap();
println!("Instance URL: {}", zabbix.url());
Source

pub fn logout(&mut self) -> Result<&mut Self, ZabbixError>

Logs out of the Zabbix server and invalidates the current token.

Call automatically when the instance is dropped.

§Examples
use http_request_zabbix::{ZabbixInstance, AuthType};

let mut zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix")
    .build()
    .unwrap()
    .login(AuthType::UsernamePassword("Admin".to_string(), "zabbix".to_string()))
    .unwrap();
zabbix.logout().unwrap();
Source

pub fn get_version(&self) -> Result<String, ZabbixError>

Retrieves the Zabbix server API version.

Use this method to check the version instead of directly calling zabbix_request with apiinfo.version, because this method requires no authentication.

§Examples
use http_request_zabbix::{ZabbixInstance, AuthType};

let zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix")
    .build()
    .unwrap()
    .login(AuthType::UsernamePassword("Admin".to_string(), "zabbix".to_string()))
    .unwrap();
println!("Zabbix Version: {}", zabbix.get_version().unwrap());
Source

pub fn check_version(&self, version_req: &str) -> Result<bool, ZabbixError>

Checks if the connected Zabbix server’s version matches a semantic version requirement. Example requirement: >=6.4, <7.0

You can use this method to quickly check if the connected Zabbix server’s version satisfies your requirements.

§Examples
use http_request_zabbix::{ZabbixInstance, AuthType};

let zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix")
    .build()
    .unwrap()
    .login(AuthType::UsernamePassword("Admin".to_string(), "zabbix".to_string()))
    .unwrap();
println!("Is >= 6.4: {}", zabbix.check_version(">=6.4").unwrap());
Source

pub fn zabbix_request<P: Into<ApiRequestParams>>( &self, method: &str, params: P, ) -> Result<String, ZabbixError>

Makes a raw JSON-RPC request to the Zabbix API.

params can be either a serde_json::Value (like json!({...})), a string slice &str, or a String.

§Examples
use http_request_zabbix::{ApiRequestParams, AuthType, ZabbixInstance};

let zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix").build().unwrap()
    .login(AuthType::UsernamePassword("Admin".to_string(), "zabbix".to_string())).unwrap();

let params_json = ApiRequestParams::from(serde_json::json!({"output": ["host", "name"], "limit": 1}));
let params_string = ApiRequestParams::from("{\"output\": [\"host\", \"name\"], \"limit\": 1}");

let result_json = zabbix.zabbix_request("host.get", params_json).unwrap();
let result_string = zabbix.zabbix_request("host.get", params_string).unwrap();

Trait Implementations§

Source§

impl Drop for ZabbixInstance

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,