misc updates and fixes

This commit is contained in:
Paul Lecuq 2022-01-17 17:57:57 +01:00
parent 0dc914beb5
commit 72d12319c1
4 changed files with 25 additions and 11 deletions

View File

@ -14,8 +14,9 @@ zabbixlaunch is a application that take control over a launchpad mini, and draw
"server": "https://zabbix.acme.com/api_jsonrpc.php", "server": "https://zabbix.acme.com/api_jsonrpc.php",
"username": "bob", "username": "bob",
"password": "password", "password": "password",
"authtoken": "token", "sloweffect": true,
"limit": 20 "refresh": 2,
"limit": 100
} }
``` ```
@ -48,7 +49,7 @@ cargo build --release
## License ## License
```text ```text
Copyright (c) 2021 PaulBSD Copyright (c) 2021, 2022 PaulBSD
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

8
config.json.sample Normal file
View File

@ -0,0 +1,8 @@
{
"server": "https://zabbix.acme.com/api_jsonrpc.php",
"username": "bob",
"password": "password",
"sloweffect": true,
"refresh": 2,
"limit": 100
}

View File

@ -81,7 +81,7 @@ fn test(ctx: &mut Context) {
pub fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) { pub fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
println!("Refresh rate is {} seconds", ctx.cfg.refresh.unwrap()); println!("Refresh rate is {} seconds", ctx.cfg.refresh.unwrap());
loop { loop {
ctx.hotreload(); let mut max = 0;
let zabbix_data = match get_zabbix_problems(&ctx.cfg) { let zabbix_data = match get_zabbix_problems(&ctx.cfg) {
Ok(zabbix_data) => zabbix_data, Ok(zabbix_data) => zabbix_data,
Err(_) => { Err(_) => {
@ -92,7 +92,7 @@ pub fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
}; };
ctx.datamatrix.compute(&zabbix_data); ctx.datamatrix.compute(&zabbix_data);
clear(canvas); clear(canvas);
let mut max = 0;
for (i, j) in ctx.datamatrix.layout.iter().enumerate() { for (i, j) in ctx.datamatrix.layout.iter().enumerate() {
let p = Pad { let p = Pad {
x: ((i as i32) % MATRIX_WIDTH), x: ((i as i32) % MATRIX_WIDTH),
@ -106,15 +106,16 @@ pub fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
_ => Color::GREEN, _ => Color::GREEN,
}; };
canvas[p] = c; canvas[p] = c;
max += 1;
if max >= MATRIX_SIZE {
break;
}
if ctx.cfg.sloweffect.unwrap() { if ctx.cfg.sloweffect.unwrap() {
sleep(Duration::from_millis(15)); sleep(Duration::from_millis(15));
} }
canvas.flush().unwrap(); canvas.flush().unwrap();
max += 1;
if max >= MATRIX_SIZE {
break;
}
} }
ctx.hotreload();
} }
} }
@ -141,8 +142,8 @@ fn effect(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
} }
fn clear(canvas: &mut CanvasLayout) { fn clear(canvas: &mut CanvasLayout) {
for a in 0..8 { for a in 0..MATRIX_WIDTH {
for b in 0..9 { for b in 0..MATRIX_WIDTH+1 {
canvas[Pad { x: a, y: b }] = Color { canvas[Pad { x: a, y: b }] = Color {
r: ZERO_COLOR, r: ZERO_COLOR,
g: ZERO_COLOR, g: ZERO_COLOR,

View File

@ -26,6 +26,10 @@ impl DataMatrix {
let severity = res["priority"].as_str().unwrap().parse::<i64>().unwrap(); let severity = res["priority"].as_str().unwrap().parse::<i64>().unwrap();
self.layout.push(ZabbixProblems { status: severity }); self.layout.push(ZabbixProblems { status: severity });
} }
// test
/*for i in 0..1000 {
self.layout.push(ZabbixProblems { status: 5 });
}*/
} }
} }