Compare commits

..

No commits in common. "master" and "1.0.0" have entirely different histories.

7 changed files with 318 additions and 547 deletions

View File

@ -17,21 +17,5 @@ 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

735
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.1"
version = "1.0.0"
edition = "2021"
authors = ["PaulBSD <paul@paulbsd.com>"]
description = "Lights up Launchpad mini using Zabbix data"
@ -9,10 +9,15 @@ 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 = "4.3"
embedded-graphics = { version = "0.8", optional = true }
launchy = { git = "https://github.com/paulbsd/launchy", branch = "develop-launchpad-mini-mk3" }
nix = "0.26"
clap = "3"
embedded-graphics = { version = "0.7", optional = true }
launchy = { git = "https://github.com/kangalioo/launchy", branch = "master" }
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,7 +1,5 @@
# 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,53 +11,34 @@ 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: Option<Mode>,
pub mode: String,
}
impl Context {
pub fn new() -> Self {
let argp: ArgMatches = Context::argparse();
let cli = Context::argparse();
let configfile = argp
.get_one::<String>("config")
.unwrap_or(&"config.json".to_string())
.to_string();
let configfile = cli.value_of("config").unwrap_or("config.json").to_string();
let mut ctx = Context {
cfg: Config::new(),
configfile: configfile,
inotify: Inotify::init(InitFlags::IN_NONBLOCK).unwrap(),
datamatrix: DataMatrix::new(),
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
}
},
mode: cli.value_of("mode").unwrap_or("draw").to_string(),
};
println!("Loading {configfile} file ...", configfile = ctx.configfile);
@ -86,6 +67,7 @@ impl Context {
.long("config")
.value_name("FILE")
.default_value("/etc/zabbixlaunch/config.json")
.takes_value(true)
.help("Sets a custom config file"),
)
.arg(
@ -94,10 +76,16 @@ impl Context {
.long("mode")
.value_name("mode")
.default_value("draw")
.value_parser(["draw", "test", "input", "effect"])
.possible_values(&["draw", "test", "input", "effect"])
.takes_value(true)
.help("Sets a when running"),
)
.arg(Arg::new("debug").short('d').help("Enable debugging"))
.arg(
Arg::new("debug")
.short('d')
.takes_value(false)
.help("Enable debugging"),
)
.get_matches()
}

View File

@ -1,4 +1,4 @@
use crate::config::{Context, Mode};
use crate::config::Context;
use crate::zabbix::api::get_zabbix_problems;
use launchy::Color;
use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, Pad};
@ -13,22 +13,23 @@ const ONE_COLOR: f32 = 1.;
const SLOWEFFECT_FACTOR: f32 = 800.0;
pub fn run(ctx: &mut Context) {
match ctx.mode {
Some(Mode::Draw) => {
match ctx.mode.as_str() {
"draw" => {
let (mut canvas, mut _poller) = initpad();
draw(&mut canvas, ctx);
}
Some(Mode::Input) => {
"input" => {
let (mut canvas, mut poller) = initpad();
input(&mut canvas, &mut poller);
}
Some(Mode::Effect) => {
"effect" => {
let (mut canvas, mut poller) = initpad();
effect(&mut canvas, &mut poller)
}
Some(Mode::Test) => test(ctx),
None => {
"test" => test(ctx),
_ => {
println!("No valid option choosen for mode");
std::process::exit(1)
}
}
}
@ -102,13 +103,14 @@ fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
x: ((i as i32) % MATRIX_WIDTH),
y: ((i as i32) / MATRIX_WIDTH) + 1,
};
canvas[p] = match j.status {
let c = 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,
@ -125,27 +127,24 @@ fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
}
fn effect(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
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);
});
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())
}
clear(canvas);
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);
});
}
}

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": {
"username": zabbix_username,
"user": zabbix_username,
"password": zabbix_password
},
"id": ZABBIX_API_ID