Compare commits

...

3 Commits

Author SHA1 Message Date
a7dc0a83cd updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-30 22:24:39 +01:00
ecdbdb8960 feat: remove deprecated "auth" option
All checks were successful
continuous-integration/drone/push Build is passing
2024-09-01 18:30:45 +02:00
0832f25fe6 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-11 17:35:37 +02:00
5 changed files with 909 additions and 413 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/testdata
/target
/config.json

1287
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -9,10 +9,10 @@ repository = "https://git.paulbsd.com/paulbsd/zabbixlaunch"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "4.1"
embedded-graphics = { version = "0.7", optional = true }
clap = { version = "4.5" }
embedded-graphics = { version = "0.8", optional = true }
launchy = { git = "https://github.com/paulbsd/launchy", branch = "develop-launchpad-mini-mk3" }
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls"] }
reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "rustls-tls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
nix = "0.26"
serde_json = { version = "1.0" }
nix = { version = "0.29", features = ["inotify"] }

View File

@ -25,7 +25,7 @@ pub enum Mode {
Effect,
}
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct Context {
pub cfg: Config,
configfile: String,

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
})
}