updated zabbixlaunch
This commit is contained in:
parent
aeb42422d8
commit
81093fa97b
@ -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) {
|
||||
println!("Refresh rate is {} seconds", cfg.refresh.unwrap());
|
||||
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);
|
||||
clear(canvas);
|
||||
let mut x = 0i32;
|
||||
let mut y = 1i32;
|
||||
let mut xx = 0i32;
|
||||
for j in datamatrix.layout.iter() {
|
||||
let p = Pad { x: x, y: y };
|
||||
let mut max = 0;
|
||||
for (i,j) in datamatrix.layout.iter().enumerate() {
|
||||
let p = Pad { x: ((i as i32) % MATRIX_WIDTH ), y: ((i as i32) / MATRIX_WIDTH )+1 };
|
||||
let c = match j.status {
|
||||
5 => Color::RED,
|
||||
4 => Color::from_hue(0.05),
|
||||
@ -54,13 +60,8 @@ pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut
|
||||
_ => Color::GREEN,
|
||||
};
|
||||
canvas[p] = c;
|
||||
x += 1;
|
||||
xx += 1;
|
||||
if x % MATRIX_WIDTH == 0 {
|
||||
y += 1;
|
||||
x = 0;
|
||||
};
|
||||
if xx >= MATRIX_SIZE {
|
||||
max += 1;
|
||||
if max >= MATRIX_SIZE {
|
||||
break;
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
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(
|
||||
&cfg.authtoken.as_ref().unwrap_or(&String::from("")),
|
||||
);
|
||||
let resp = reqwest::blocking::Client::new()
|
||||
.post(&cfg.server)
|
||||
.json(&body)
|
||||
.send()
|
||||
.unwrap();
|
||||
.send();
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user