Compare commits

...

20 Commits

Author SHA1 Message Date
f2bb375972 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-12 22:45:54 +02:00
872e17f6f2 Merge few changes from branch 'launchpad_mini_mk3'
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-10 19:37:03 +01:00
e30efa1d9a fix: api json data & launchy remote repository
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-10 19:25:19 +01:00
9f07930013 updated dependencies 2023-02-10 18:28:13 +01:00
b73fc7a7c2 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-16 11:42:30 +02:00
ef60d4bda9 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-04 15:33:56 +02:00
c128a7dce5 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-27 14:39:44 +02:00
50a2da488d updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-22 19:20:01 +02:00
Paul Lecuq
f6e801dc58 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-16 14:29:27 +02:00
Paul Lecuq
f3a1d5c900 updated zabbixlaunch 2022-05-16 14:29:19 +02:00
Paul Lecuq
ca349dc187 updated README.md
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-10 12:59:24 +02:00
Paul Lecuq
ccf9fd587d updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-10 12:53:44 +02:00
Paul Lecuq
ec23da0565 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-10 12:50:58 +02:00
bf03adb549 updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-08 19:49:27 +02:00
Paul Lecuq
f18f25727d updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-04 19:04:29 +02:00
Paul Lecuq
e364dc7540 update to version 1.0.1
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-29 17:35:33 +02:00
Paul Lecuq
463795385d updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-21 17:31:01 +02:00
Paul Lecuq
95322749fe updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-11 10:19:14 +02:00
e9973e109f Merge branch 'master' of ssh://git.paulbsd.com:2222/paulbsd/zabbixlaunch
All checks were successful
continuous-integration/drone/push Build is passing
2022-03-26 12:07:47 +01:00
e7850c8d72 updated .drone.yml 2022-03-26 12:07:33 +01:00
7 changed files with 551 additions and 322 deletions

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -1,5 +1,7 @@
# zabbixlaunch
[![Build Status](https://drone.paulbsd.com/api/badges/paulbsd/zabbixlaunch/status.svg)](https://drone.paulbsd.com/paulbsd/zabbixlaunch)
## Summary
zabbixlaunch is a application that take control over a launchpad mini, and draw problems handled by Zabbix

View File

@ -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()
}

View File

@ -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);
}
}

View File

@ -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