Compare commits
3 Commits
master
...
launchpad_
Author | SHA1 | Date | |
---|---|---|---|
a7dc0a83cd | |||
ecdbdb8960 | |||
0832f25fe6 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
/testdata
|
||||
/target
|
||||
/config.json
|
||||
|
||||
|
1185
Cargo.lock
generated
1185
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -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.3"
|
||||
clap = { version = "4.5" }
|
||||
embedded-graphics = { version = "0.8", optional = true }
|
||||
launchy = { git = "https://github.com/paulbsd/launchy", branch = "develop-launchpad-mini-mk3" }
|
||||
nix = "0.26"
|
||||
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"
|
||||
serde_json = { version = "1.0" }
|
||||
nix = { version = "0.29", features = ["inotify"] }
|
||||
|
@ -25,7 +25,7 @@ pub enum Mode {
|
||||
Effect,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub struct Context {
|
||||
pub cfg: Config,
|
||||
configfile: String,
|
||||
|
@ -8,8 +8,6 @@ use std::time::Duration;
|
||||
const MATRIX_WIDTH: i32 = 8;
|
||||
const MATRIX_SIZE: i32 = MATRIX_WIDTH * MATRIX_WIDTH;
|
||||
const REQUEST_TIMEOUT: i32 = 5;
|
||||
const ZERO_COLOR: f32 = 0.;
|
||||
const ONE_COLOR: f32 = 1.;
|
||||
const SLOWEFFECT_FACTOR: f32 = 800.0;
|
||||
|
||||
pub fn run(ctx: &mut Context) {
|
||||
@ -35,7 +33,7 @@ pub fn run(ctx: &mut Context) {
|
||||
|
||||
fn initpad() -> (CanvasLayout<'static>, CanvasLayoutPoller) {
|
||||
let (mut canvas, poller) = launchy::CanvasLayout::new_polling();
|
||||
match canvas.add_by_guess_rotated::<launchy::mini::Canvas>(0, 0, launchy::Rotation::None) {
|
||||
match canvas.add_by_guess::<launchy::mini_mk3::Canvas>(0, 0) {
|
||||
Ok(_) => {
|
||||
println!("Connected to device using USB");
|
||||
clear(&mut canvas);
|
||||
@ -44,6 +42,9 @@ fn initpad() -> (CanvasLayout<'static>, CanvasLayoutPoller) {
|
||||
eprintln!("Failed to connect to device, check USB connection {err}",);
|
||||
}
|
||||
};
|
||||
canvas[Pad { x: 0, y: 0 }] = Color::BLUE;
|
||||
canvas.flush().unwrap();
|
||||
sleep(Duration::from_millis(100));
|
||||
(canvas, poller)
|
||||
}
|
||||
|
||||
@ -104,9 +105,10 @@ fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
|
||||
};
|
||||
canvas[p] = match j.status {
|
||||
5 => Color::RED,
|
||||
4 => Color::from_hue(0.05),
|
||||
3 => Color::from_hue(0.1),
|
||||
2 => Color::from_hue(1.22),
|
||||
4 => Color::new(1., 0.2, 0.),
|
||||
3 => Color::new(1., 0.4, 0.),
|
||||
2 => Color::new(1., 0.6, 0.),
|
||||
1 => Color::BLUE,
|
||||
_ => Color::GREEN,
|
||||
};
|
||||
if ctx.cfg.sloweffect.unwrap() {
|
||||
@ -152,11 +154,7 @@ fn effect(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
|
||||
fn clear(canvas: &mut CanvasLayout) {
|
||||
for a in 0..MATRIX_WIDTH {
|
||||
for b in 0..MATRIX_WIDTH + 1 {
|
||||
canvas[Pad { x: a, y: b }] = Color {
|
||||
r: ZERO_COLOR,
|
||||
g: ZERO_COLOR,
|
||||
b: ONE_COLOR,
|
||||
};
|
||||
canvas[Pad { x: a, y: b }] = Color::BLACK;
|
||||
}
|
||||
}
|
||||
canvas.flush().unwrap();
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user