diff --git a/Cargo.toml b/Cargo.toml index 2014b3d..44eaf45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zbx_sender" -version = "0.1.0" +version = "0.1.1" authors = ["Alexander Andreev "] description = "Implementation of Zabbix Sender Client." homepage = "https://github.com/andreevlex/zbx-sender-rs" diff --git a/examples/bulk_sender.rs b/examples/bulk_sender.rs index b8a5510..948c838 100644 --- a/examples/bulk_sender.rs +++ b/examples/bulk_sender.rs @@ -1,7 +1,7 @@ extern crate zbx_sender; -use zbx_sender::{Response, Result, SendValue, Sender}; use std::env; +use zbx_sender::{Response, Result, SendValue, Sender}; fn send(command: &str) -> Result { let sender = Sender::new(command.to_owned(), 10051); @@ -25,7 +25,16 @@ fn main() { }; match send(&command) { - Ok(response) => println!("{:?}", response), + Ok(response) => { + println!("{:?}", response); + println!( + "processed: {}; failed: {}; total: {}; seconds spent: {}", + response.processed_cnt(), + response.failed_cnt(), + response.total_cnt(), + response.seconds_spent() + ); + } Err(e) => println!("Error {}", e), } } diff --git a/examples/sender.rs b/examples/sender.rs index d5b200d..db8c6a6 100644 --- a/examples/sender.rs +++ b/examples/sender.rs @@ -1,7 +1,7 @@ extern crate zbx_sender; -use zbx_sender::{Response, Result, Sender}; use std::env; +use zbx_sender::{Response, Result, Sender}; fn send_one_value(command: &str) -> Result { let sender = Sender::new(command.to_owned(), 10051); diff --git a/src/lib.rs b/src/lib.rs index 2c8b19d..e539177 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,8 @@ #[macro_use] extern crate serde_derive; extern crate byteorder; -extern crate serde_json; extern crate regex; +extern crate serde_json; #[macro_use] extern crate failure; @@ -17,10 +17,10 @@ mod error; pub use error::Result; -use std::io::prelude::*; +use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::io; +use std::io::prelude::*; use std::net::TcpStream; -use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; const ZBX_HDR: &'static [u8; 5] = b"ZBXD\x01"; const ZBX_HDR_SIZE: usize = 13; @@ -178,7 +178,7 @@ impl Response { pub fn processed_cnt(&self) -> i32 { if let Some(result) = self.get_value_from_info("processed") { if let Ok(int_value) = result.parse::() { - return int_value + return int_value; } } -1 //Return a invalid number @@ -188,7 +188,7 @@ impl Response { pub fn failed_cnt(&self) -> i32 { if let Some(result) = self.get_value_from_info("failed") { if let Ok(int_value) = result.parse::() { - return int_value + return int_value; } } -1 //Return a invalid number @@ -198,7 +198,7 @@ impl Response { pub fn total_cnt(&self) -> i32 { if let Some(result) = self.get_value_from_info("total") { if let Ok(int_value) = result.parse::() { - return int_value + return int_value; } } -1 //Return a invalid number @@ -208,19 +208,17 @@ impl Response { pub fn seconds_spent(&self) -> f32 { if let Some(result) = self.get_value_from_info("seconds_spent") { if let Ok(float_value) = result.parse::() { - return float_value + return float_value; } } -1.0 //Return a invalid number } fn get_value_from_info(&self, name: &str) -> Option { - let reg = regex::Regex::new(r"processed: (?P\d+); failed: (?P\d+); total: (?P\d+); seconds spent: (?P\d.\d+)").unwrap(); match reg.captures(&self.info) { Some(x) => Some(x[name].to_string()), None => None, } - } }