pub struct ZabbixInstanceBuilder { /* private fields */ }Expand description
A builder for creating a ZabbixInstance.
Implementations§
Source§impl ZabbixInstanceBuilder
impl ZabbixInstanceBuilder
Sourcepub fn new(url: &str) -> Self
pub fn new(url: &str) -> Self
Creates a new builder with the given Zabbix URL.
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");Sourcepub fn danger_accept_invalid_certs(self, accept: bool) -> Self
pub fn danger_accept_invalid_certs(self, accept: bool) -> Self
Configures whether the client should verify the server’s TLS certificates.
Setting this to true is dangerous and should only be used for testing
or when using self-signed certificates in a trusted environment.
§Examples
use http_request_zabbix::ZabbixInstance;
let builder = ZabbixInstance::builder("http://localhost/zabbix/api_jsonrpc.php")
.danger_accept_invalid_certs(true);Sourcepub fn build(self) -> Result<Self, ZabbixError>
pub fn build(self) -> Result<Self, ZabbixError>
Builds the ZabbixInstance by connecting to the server and verifying the API version.
This method will make an initial unauthenticated request to the Zabbix server
to determine its version (using apiinfo.version). This is required because
Zabbix >= 6.4 changed the authentication flow (using Bearer tokens instead of
passing auth in the request body).
§Examples
use http_request_zabbix::ZabbixInstance;
let zabbix_result = ZabbixInstance::builder("http://zabbix.example.com/api_jsonrpc.php")
.danger_accept_invalid_certs(true)
.build();
assert!(zabbix_result.is_ok());Sourcepub fn login(self, auth_type: AuthType) -> Result<ZabbixInstance, ZabbixError>
pub fn login(self, auth_type: AuthType) -> Result<ZabbixInstance, ZabbixError>
Logs in to the Zabbix server using the provided authentication type.
§Arguments
auth_type- The authentication type to use for logging in.
§Examples
use http_request_zabbix::{ZabbixInstance, AuthType};
let auth_type = AuthType::UsernamePassword("Admin".to_string(), "zabbix".to_string());
let zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix")
.build()
.unwrap()
.login(auth_type)
.unwrap();use http_request_zabbix::{ZabbixInstance, AuthType};
let auth_type = AuthType::Token("817dc89d0ae1...".to_string());
let zabbix = ZabbixInstance::builder("http://zabbix.example.com/zabbix")
.build()
.unwrap()
.login(auth_type)
.unwrap();