feat: remove deprecated "auth" option
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0832f25fe6
commit
ecdbdb8960
@ -1,4 +1,6 @@
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
use reqwest::blocking::Client;
|
||||||
|
use reqwest::header::HeaderMap;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
//use std::thread::sleep;
|
//use std::thread::sleep;
|
||||||
@ -10,10 +12,7 @@ pub const ZABBIX_API_ID: i32 = 1;
|
|||||||
/// Refresh the user token
|
/// Refresh the user token
|
||||||
pub fn get_zabbix_authtoken(cfg: &mut Config) {
|
pub fn get_zabbix_authtoken(cfg: &mut Config) {
|
||||||
let body = build_query_auth_token(&cfg.username, &cfg.password);
|
let body = build_query_auth_token(&cfg.username, &cfg.password);
|
||||||
let resp = reqwest::blocking::Client::new()
|
let resp = Client::new().post(&cfg.server).json(&body).send();
|
||||||
.post(&cfg.server)
|
|
||||||
.json(&body)
|
|
||||||
.send();
|
|
||||||
match resp {
|
match resp {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
let values: JsonValue = v.json().unwrap();
|
let values: JsonValue = v.json().unwrap();
|
||||||
@ -28,9 +27,17 @@ pub fn get_zabbix_authtoken(cfg: &mut Config) {
|
|||||||
|
|
||||||
/// Fetch Zabbix problems
|
/// Fetch Zabbix problems
|
||||||
pub fn get_zabbix_problems(cfg: &Config) -> Result<JsonValue, reqwest::Error> {
|
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 body = build_query_triggers();
|
||||||
let resp = reqwest::blocking::Client::new()
|
let mut headers = HeaderMap::new();
|
||||||
|
headers.insert(
|
||||||
|
"Authorization",
|
||||||
|
format!("Bearer {}", &cfg.authtoken.as_ref().unwrap())
|
||||||
|
.parse()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let resp = Client::new()
|
||||||
.post(&cfg.server)
|
.post(&cfg.server)
|
||||||
|
.headers(headers)
|
||||||
.json(&body)
|
.json(&body)
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
@ -98,7 +105,7 @@ fn build_query_auth_token(zabbix_username: &String, zabbix_password: &String) ->
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
/// Build the query that fetchs triggers
|
/// 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";
|
let zabbix_api_function = "trigger.get";
|
||||||
json!({
|
json!({
|
||||||
"jsonrpc": ZABBIX_API_VERSION,
|
"jsonrpc": ZABBIX_API_VERSION,
|
||||||
@ -114,7 +121,6 @@ fn build_query_triggers(zabbix_token: &String) -> JsonValue {
|
|||||||
"selectHosts": "extend",
|
"selectHosts": "extend",
|
||||||
"min_severity": 1,
|
"min_severity": 1,
|
||||||
},
|
},
|
||||||
"auth": zabbix_token,
|
|
||||||
"id": ZABBIX_API_ID
|
"id": ZABBIX_API_ID
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user