initial commit
This commit is contained in:
commit
8685112ad2
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
/config.json
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "launchy"]
|
||||||
|
path = launchy
|
||||||
|
url = https://github.com/kangalioo/launchy
|
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug",
|
||||||
|
"program": "${workspaceFolder}/<your program>",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
1192
Cargo.lock
generated
Normal file
1192
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "zabbixlaunch"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
launchy = { path = "launchy" }
|
||||||
|
embedded-graphics = { version = "0.7", optional = true }
|
||||||
|
ctrlc = "3.2.0"
|
||||||
|
serde_json = "1.0.67"
|
||||||
|
serde = { version = "1.0.130", features = ["derive"] }
|
||||||
|
reqwest = { version = "0.11.4", features = ["blocking","json"] }
|
1
launchy
Submodule
1
launchy
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f066a4f8a2616dcb7b2b9b2b06f30136a80fef35
|
32
src/api/mod.rs
Normal file
32
src/api/mod.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
|
pub fn query_auth_token(username: &String, password: &String) -> Value {
|
||||||
|
json!({
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "user.login",
|
||||||
|
"params": {
|
||||||
|
"user": username,
|
||||||
|
"password": password
|
||||||
|
},
|
||||||
|
"id": 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn query_problems(token: &String, limit: Option<i8>) -> Value {
|
||||||
|
json!({
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "problem.get",
|
||||||
|
"params": {
|
||||||
|
"output": "extend",
|
||||||
|
"selectAcknowledges": "extend",
|
||||||
|
"selectTags": "extend",
|
||||||
|
"selectSuppressionData": "extend",
|
||||||
|
"recent": "true",
|
||||||
|
"sortfield": ["eventid"],
|
||||||
|
"sortorder": "DESC",
|
||||||
|
"limit": limit.unwrap_or(10)
|
||||||
|
},
|
||||||
|
"auth": token,
|
||||||
|
"id": 1
|
||||||
|
})
|
||||||
|
}
|
27
src/config/mod.rs
Normal file
27
src/config/mod.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use std::{fs::File, io::Read};
|
||||||
|
use std::string::String;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub server: String,
|
||||||
|
pub username: String,
|
||||||
|
pub password: String,
|
||||||
|
pub authtoken: String,
|
||||||
|
pub limit: i8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn save(&self, configfile: &'static str) {
|
||||||
|
let file = File::create(configfile).unwrap();
|
||||||
|
serde_json::to_writer_pretty(file, &self).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read(configfile: &'static str) -> Config {
|
||||||
|
let mut file = File::open(configfile).unwrap();
|
||||||
|
let mut contents = String::new();
|
||||||
|
file.read_to_string(&mut contents).unwrap();
|
||||||
|
let config: Config = serde_json::from_str(contents.as_str()).unwrap();
|
||||||
|
config
|
||||||
|
}
|
82
src/main.rs
Normal file
82
src/main.rs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
mod config;
|
||||||
|
mod api;
|
||||||
|
|
||||||
|
use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, Pad};
|
||||||
|
use launchy::{Color};
|
||||||
|
use config::Config;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let (mut canvas, mut poller) = initpad();
|
||||||
|
let mut cfg = config::read("config.json");
|
||||||
|
get_zabbix_authtoken(&mut cfg);
|
||||||
|
get_zabbix_problems(&mut cfg);
|
||||||
|
clear(&mut canvas);
|
||||||
|
testinput(&mut canvas, &mut poller);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_zabbix_authtoken(cfg: &mut Config) {
|
||||||
|
let body = api::query_auth_token(&cfg.username, &cfg.password);
|
||||||
|
let response = reqwest::blocking::Client::new()
|
||||||
|
.post(&cfg.server)
|
||||||
|
.json(&body)
|
||||||
|
.send()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let values: Value = response
|
||||||
|
.json()
|
||||||
|
.unwrap();
|
||||||
|
cfg.authtoken = values["result"].as_str().unwrap().to_string();
|
||||||
|
//cfg.save("config.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_zabbix_problems(cfg: &mut Config) {
|
||||||
|
let body = api::query_problems(&cfg.authtoken, Some(cfg.limit));
|
||||||
|
let response = reqwest::blocking::Client::new()
|
||||||
|
.post(&cfg.server)
|
||||||
|
.json(&body)
|
||||||
|
.send()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let values: Value = response
|
||||||
|
.json()
|
||||||
|
.unwrap();
|
||||||
|
for i in values["result"].as_array().unwrap() {
|
||||||
|
println!("{}", i);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn initpad() -> (CanvasLayout<'static>, CanvasLayoutPoller) {
|
||||||
|
let (mut canvas, poller) = launchy::CanvasLayout::new_polling();
|
||||||
|
canvas.add_by_guess_rotated::<launchy::mini::Canvas>(10, 18, launchy::Rotation::UpsideDown).unwrap();
|
||||||
|
(canvas, poller)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn testinput(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
|
||||||
|
for color in (0u64..).map(|f| Color::red_green_color(f as f32 / 60.0 / 2.5)) {
|
||||||
|
for msg in poller.iter_for_millis(17).filter(|msg| msg.is_press()) {
|
||||||
|
canvas[msg.pad()] = color;
|
||||||
|
println!("{:?}", msg.pad())
|
||||||
|
}
|
||||||
|
let _res =canvas.flush();
|
||||||
|
|
||||||
|
canvas.iter().for_each(|pad| {
|
||||||
|
let surrounding_color = pad.neighbors_5().iter()
|
||||||
|
.map(|&p| canvas.get(p).unwrap_or(Color::GREEN))
|
||||||
|
.sum::<Color>() / 5.0 / 1.05;
|
||||||
|
|
||||||
|
canvas[pad] = canvas[pad].mix(surrounding_color, 0.4);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn clear(canvas: &mut CanvasLayout) {
|
||||||
|
for a in 3..11 {
|
||||||
|
for b in 10..18 {
|
||||||
|
canvas[Pad { x: a, y: b }] = Color{r: 0f32, g: 0f32, b:1f32};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let _res =canvas.flush();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user