Compare commits
3 Commits
master
...
launchpad_
Author | SHA1 | Date | |
---|---|---|---|
a7dc0a83cd | |||
ecdbdb8960 | |||
0832f25fe6 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
/testdata
|
||||||
/target
|
/target
|
||||||
/config.json
|
/config.json
|
||||||
|
|
||||||
|
1287
Cargo.lock
generated
1287
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@ -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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "4.1"
|
clap = { version = "4.5" }
|
||||||
embedded-graphics = { version = "0.7", optional = true }
|
embedded-graphics = { version = "0.8", optional = true }
|
||||||
launchy = { git = "https://github.com/paulbsd/launchy", branch = "develop-launchpad-mini-mk3" }
|
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 = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = { version = "1.0" }
|
||||||
nix = "0.26"
|
nix = { version = "0.29", features = ["inotify"] }
|
||||||
|
@ -25,7 +25,7 @@ pub enum Mode {
|
|||||||
Effect,
|
Effect,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug)]
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub cfg: Config,
|
pub cfg: Config,
|
||||||
configfile: String,
|
configfile: String,
|
||||||
|
@ -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