feat: remove deprecated "auth" option
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2024-09-01 18:30:45 +02:00
parent 0832f25fe6
commit ecdbdb8960

View File

@ -1,4 +1,6 @@
use crate::config::Config;
use reqwest::blocking::Client;
use reqwest::header::HeaderMap;
use serde_json::json;
use serde_json::Value as JsonValue;
//use std::thread::sleep;
@ -10,10 +12,7 @@ pub const ZABBIX_API_ID: i32 = 1;
/// Refresh the user token
pub fn get_zabbix_authtoken(cfg: &mut Config) {
let body = build_query_auth_token(&cfg.username, &cfg.password);
let resp = reqwest::blocking::Client::new()
.post(&cfg.server)
.json(&body)
.send();
let resp = Client::new().post(&cfg.server).json(&body).send();
match resp {
Ok(v) => {
let values: JsonValue = v.json().unwrap();
@ -28,9 +27,17 @@ pub fn get_zabbix_authtoken(cfg: &mut Config) {
/// Fetch Zabbix problems
pub fn get_zabbix_problems(cfg: &Config) -> Result<JsonValue, reqwest::Error> {
let body = build_query_triggers(&cfg.authtoken.as_ref().unwrap_or(&String::from("")));
let resp = reqwest::blocking::Client::new()
let body = build_query_triggers();
let mut headers = HeaderMap::new();
headers.insert(
"Authorization",
format!("Bearer {}", &cfg.authtoken.as_ref().unwrap())
.parse()
.unwrap(),
);
let resp = Client::new()
.post(&cfg.server)
.headers(headers)
.json(&body)
.send();
@ -98,7 +105,7 @@ fn build_query_auth_token(zabbix_username: &String, zabbix_password: &String) ->
}*/
/// Build the query that fetchs triggers
fn build_query_triggers(zabbix_token: &String) -> JsonValue {
fn build_query_triggers() -> JsonValue {
let zabbix_api_function = "trigger.get";
json!({
"jsonrpc": ZABBIX_API_VERSION,
@ -114,7 +121,6 @@ fn build_query_triggers(zabbix_token: &String) -> JsonValue {
"selectHosts": "extend",
"min_severity": 1,
},
"auth": zabbix_token,
"id": ZABBIX_API_ID
})
}