Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
f2bb375972 | |||
872e17f6f2 | |||
e30efa1d9a | |||
9f07930013 | |||
b73fc7a7c2 | |||
ef60d4bda9 | |||
c128a7dce5 | |||
50a2da488d | |||
|
f6e801dc58 | ||
|
f3a1d5c900 | ||
|
ca349dc187 | ||
|
ccf9fd587d | ||
|
ec23da0565 | ||
bf03adb549 | |||
|
f18f25727d | ||
|
e364dc7540 | ||
|
463795385d | ||
|
95322749fe | ||
e9973e109f | |||
e7850c8d72 |
16
.drone.yml
16
.drone.yml
@ -17,5 +17,21 @@ steps:
|
||||
- apt-get update -y
|
||||
- apt-get install libasound2-dev -y
|
||||
- cargo build --release --verbose --all
|
||||
- cd target/release
|
||||
- tar -czvf zabbixlaunch-${DRONE_TAG}.tar.gz zabbixlaunch
|
||||
when:
|
||||
event: tag
|
||||
- name: publish
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
base_url: https://git.paulbsd.com
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
files: "target/release/*.tar.gz"
|
||||
checksum:
|
||||
- sha256
|
||||
- sha512
|
||||
environment:
|
||||
PLUGIN_TITLE: ""
|
||||
when:
|
||||
event: tag
|
||||
|
743
Cargo.lock
generated
743
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
15
Cargo.toml
15
Cargo.toml
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "zabbixlaunch"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
edition = "2021"
|
||||
authors = ["PaulBSD <paul@paulbsd.com>"]
|
||||
description = "Lights up Launchpad mini using Zabbix data"
|
||||
@ -9,15 +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 = "3"
|
||||
embedded-graphics = { version = "0.7", optional = true }
|
||||
launchy = { git = "https://github.com/kangalioo/launchy", branch = "master" }
|
||||
clap = "4.3"
|
||||
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"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
nix = "0.23"
|
||||
|
||||
[profile.release]
|
||||
debug = 0
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
|
@ -1,5 +1,7 @@
|
||||
# zabbixlaunch
|
||||
|
||||
[](https://drone.paulbsd.com/paulbsd/zabbixlaunch)
|
||||
|
||||
## Summary
|
||||
|
||||
zabbixlaunch is a application that take control over a launchpad mini, and draw problems handled by Zabbix
|
||||
|
@ -11,34 +11,53 @@ use std::string::String;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ReloadFrequency {
|
||||
High = 50,
|
||||
Medium = 20,
|
||||
Low = 10,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Mode {
|
||||
Draw,
|
||||
Test,
|
||||
Input,
|
||||
Effect,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Context {
|
||||
pub cfg: Config,
|
||||
configfile: String,
|
||||
inotify: Inotify,
|
||||
pub datamatrix: DataMatrix,
|
||||
pub mode: String,
|
||||
pub mode: Option<Mode>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new() -> Self {
|
||||
let cli = Context::argparse();
|
||||
let argp: ArgMatches = Context::argparse();
|
||||
|
||||
let configfile = cli.value_of("config").unwrap_or("config.json").to_string();
|
||||
let configfile = argp
|
||||
.get_one::<String>("config")
|
||||
.unwrap_or(&"config.json".to_string())
|
||||
.to_string();
|
||||
|
||||
let mut ctx = Context {
|
||||
cfg: Config::new(),
|
||||
configfile: configfile,
|
||||
inotify: Inotify::init(InitFlags::IN_NONBLOCK).unwrap(),
|
||||
datamatrix: DataMatrix::new(),
|
||||
mode: cli.value_of("mode").unwrap_or("draw").to_string(),
|
||||
mode: match argp.get_one::<String>("mode").unwrap().as_str() {
|
||||
"draw" => Some(Mode::Draw),
|
||||
"test" => Some(Mode::Test),
|
||||
"input" => Some(Mode::Input),
|
||||
"effect" => Some(Mode::Effect),
|
||||
_ => {
|
||||
println!("No valid mode choosen");
|
||||
None
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
println!("Loading {configfile} file ...", configfile = ctx.configfile);
|
||||
@ -67,7 +86,6 @@ impl Context {
|
||||
.long("config")
|
||||
.value_name("FILE")
|
||||
.default_value("/etc/zabbixlaunch/config.json")
|
||||
.takes_value(true)
|
||||
.help("Sets a custom config file"),
|
||||
)
|
||||
.arg(
|
||||
@ -76,16 +94,10 @@ impl Context {
|
||||
.long("mode")
|
||||
.value_name("mode")
|
||||
.default_value("draw")
|
||||
.possible_values(&["draw", "test", "input", "effect"])
|
||||
.takes_value(true)
|
||||
.value_parser(["draw", "test", "input", "effect"])
|
||||
.help("Sets a when running"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("debug")
|
||||
.short('d')
|
||||
.takes_value(false)
|
||||
.help("Enable debugging"),
|
||||
)
|
||||
.arg(Arg::new("debug").short('d').help("Enable debugging"))
|
||||
.get_matches()
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::config::Context;
|
||||
use crate::config::{Context, Mode};
|
||||
use crate::zabbix::api::get_zabbix_problems;
|
||||
use launchy::Color;
|
||||
use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, Pad};
|
||||
@ -13,23 +13,22 @@ const ONE_COLOR: f32 = 1.;
|
||||
const SLOWEFFECT_FACTOR: f32 = 800.0;
|
||||
|
||||
pub fn run(ctx: &mut Context) {
|
||||
match ctx.mode.as_str() {
|
||||
"draw" => {
|
||||
match ctx.mode {
|
||||
Some(Mode::Draw) => {
|
||||
let (mut canvas, mut _poller) = initpad();
|
||||
draw(&mut canvas, ctx);
|
||||
}
|
||||
"input" => {
|
||||
Some(Mode::Input) => {
|
||||
let (mut canvas, mut poller) = initpad();
|
||||
input(&mut canvas, &mut poller);
|
||||
}
|
||||
"effect" => {
|
||||
Some(Mode::Effect) => {
|
||||
let (mut canvas, mut poller) = initpad();
|
||||
effect(&mut canvas, &mut poller)
|
||||
}
|
||||
"test" => test(ctx),
|
||||
_ => {
|
||||
Some(Mode::Test) => test(ctx),
|
||||
None => {
|
||||
println!("No valid option choosen for mode");
|
||||
std::process::exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,14 +102,13 @@ fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
|
||||
x: ((i as i32) % MATRIX_WIDTH),
|
||||
y: ((i as i32) / MATRIX_WIDTH) + 1,
|
||||
};
|
||||
let c = match j.status {
|
||||
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),
|
||||
_ => Color::GREEN,
|
||||
};
|
||||
canvas[p] = c;
|
||||
if ctx.cfg.sloweffect.unwrap() {
|
||||
sleep(Duration::from_millis(
|
||||
(SLOWEFFECT_FACTOR * (1.0 / ctx.datamatrix.layout.len() as f32)) as u64,
|
||||
@ -127,24 +125,27 @@ fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
|
||||
}
|
||||
|
||||
fn effect(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:?}", msg = msg.pad())
|
||||
loop {
|
||||
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:?}", msg = msg.pad())
|
||||
}
|
||||
canvas.flush().unwrap();
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
canvas.flush().unwrap();
|
||||
|
||||
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);
|
||||
});
|
||||
clear(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ fn build_query_auth_token(zabbix_username: &String, zabbix_password: &String) ->
|
||||
"jsonrpc": ZABBIX_API_VERSION,
|
||||
"method": zabbix_api_function,
|
||||
"params": {
|
||||
"user": zabbix_username,
|
||||
"username": zabbix_username,
|
||||
"password": zabbix_password
|
||||
},
|
||||
"id": ZABBIX_API_ID
|
||||
|
Loading…
Reference in New Issue
Block a user