updated zabbixlaunch
This commit is contained in:
parent
aeb42422d8
commit
81093fa97b
@ -8,7 +8,7 @@ use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper,
|
|||||||
|
|
||||||
|
|
||||||
pub const MATRIX_WIDTH: i32 = 8;
|
pub const MATRIX_WIDTH: i32 = 8;
|
||||||
pub const MATRIX_SIZE: i32 = MATRIX_WIDTH*MATRIX_WIDTH;
|
pub const MATRIX_SIZE: i32 = MATRIX_WIDTH * MATRIX_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
pub fn initpad() -> (CanvasLayout<'static>, CanvasLayoutPoller) {
|
pub fn initpad() -> (CanvasLayout<'static>, CanvasLayoutPoller) {
|
||||||
@ -38,14 +38,20 @@ pub fn _input(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
|
|||||||
pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut Config) {
|
pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut Config) {
|
||||||
println!("Refresh rate is {} seconds", cfg.refresh.unwrap());
|
println!("Refresh rate is {} seconds", cfg.refresh.unwrap());
|
||||||
loop {
|
loop {
|
||||||
let zabbix_data = get_zabbix_problems(cfg);
|
let zabbix_data_result = get_zabbix_problems(cfg);
|
||||||
|
let zabbix_data = match zabbix_data_result {
|
||||||
|
Ok(zabbix_data) => zabbix_data,
|
||||||
|
Err(_) => {
|
||||||
|
println!("Error requesting service");
|
||||||
|
sleep(Duration::from_secs(10));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
datamatrix.compute(&zabbix_data);
|
datamatrix.compute(&zabbix_data);
|
||||||
clear(canvas);
|
clear(canvas);
|
||||||
let mut x = 0i32;
|
let mut max = 0;
|
||||||
let mut y = 1i32;
|
for (i,j) in datamatrix.layout.iter().enumerate() {
|
||||||
let mut xx = 0i32;
|
let p = Pad { x: ((i as i32) % MATRIX_WIDTH ), y: ((i as i32) / MATRIX_WIDTH )+1 };
|
||||||
for j in datamatrix.layout.iter() {
|
|
||||||
let p = Pad { x: x, y: y };
|
|
||||||
let c = match j.status {
|
let c = match j.status {
|
||||||
5 => Color::RED,
|
5 => Color::RED,
|
||||||
4 => Color::from_hue(0.05),
|
4 => Color::from_hue(0.05),
|
||||||
@ -54,13 +60,8 @@ pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut
|
|||||||
_ => Color::GREEN,
|
_ => Color::GREEN,
|
||||||
};
|
};
|
||||||
canvas[p] = c;
|
canvas[p] = c;
|
||||||
x += 1;
|
max += 1;
|
||||||
xx += 1;
|
if max >= MATRIX_SIZE {
|
||||||
if x % MATRIX_WIDTH == 0 {
|
|
||||||
y += 1;
|
|
||||||
x = 0;
|
|
||||||
};
|
|
||||||
if xx >= MATRIX_SIZE {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if cfg.sloweffect.unwrap() {
|
if cfg.sloweffect.unwrap() {
|
||||||
|
@ -16,17 +16,20 @@ pub fn get_zabbix_authtoken(cfg: &mut Config) {
|
|||||||
cfg.authtoken = Some(values["result"].as_str().unwrap().to_string());
|
cfg.authtoken = Some(values["result"].as_str().unwrap().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_zabbix_problems(cfg: &mut Config) -> Value {
|
pub fn get_zabbix_problems(cfg: &mut Config) -> Result<Value, reqwest::Error> {
|
||||||
let body = query_triggers(
|
let body = query_triggers(
|
||||||
&cfg.authtoken.as_ref().unwrap_or(&String::from("")),
|
&cfg.authtoken.as_ref().unwrap_or(&String::from("")),
|
||||||
);
|
);
|
||||||
let resp = reqwest::blocking::Client::new()
|
let resp = reqwest::blocking::Client::new()
|
||||||
.post(&cfg.server)
|
.post(&cfg.server)
|
||||||
.json(&body)
|
.json(&body)
|
||||||
.send()
|
.send();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
resp.json().unwrap()
|
//let res = match resp {
|
||||||
|
// Ok(res) => res.json()
|
||||||
|
//};
|
||||||
|
|
||||||
|
Ok(resp.unwrap().json().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query_auth_token(zabbix_username: &String, zabbix_password: &String) -> Value {
|
pub fn query_auth_token(zabbix_username: &String, zabbix_password: &String) -> Value {
|
||||||
|
Loading…
Reference in New Issue
Block a user