Skip to content

Commit

Permalink
push ver 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ava57r committed Jul 9, 2018
1 parent ac5c7b9 commit ab499b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zbx_sender"
version = "0.1.0"
version = "0.1.1"
authors = ["Alexander Andreev <[email protected]>"]
description = "Implementation of Zabbix Sender Client."
homepage = "https://github.com/andreevlex/zbx-sender-rs"
Expand Down
13 changes: 11 additions & 2 deletions examples/bulk_sender.rs
Original file line number Diff line number Diff line change
@@ -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<Response> {
let sender = Sender::new(command.to_owned(), 10051);
Expand All @@ -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),
}
}
2 changes: 1 addition & 1 deletion examples/sender.rs
Original file line number Diff line number Diff line change
@@ -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<Response> {
let sender = Sender::new(command.to_owned(), 10051);
Expand Down
16 changes: 7 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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::<i32>() {
return int_value
return int_value;
}
}
-1 //Return a invalid number
Expand All @@ -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::<i32>() {
return int_value
return int_value;
}
}
-1 //Return a invalid number
Expand All @@ -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::<i32>() {
return int_value
return int_value;
}
}
-1 //Return a invalid number
Expand All @@ -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::<f32>() {
return float_value
return float_value;
}
}
-1.0 //Return a invalid number
}

fn get_value_from_info(&self, name: &str) -> Option<String> {

let reg = regex::Regex::new(r"processed: (?P<processed>\d+); failed: (?P<failed>\d+); total: (?P<total>\d+); seconds spent: (?P<seconds_spent>\d.\d+)").unwrap();
match reg.captures(&self.info) {
Some(x) => Some(x[name].to_string()),
None => None,
}

}
}

0 comments on commit ab499b9

Please sign in to comment.