Skip to content

Commit

Permalink
added doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ava57r committed Apr 13, 2018
1 parent fa7990d commit 716ad2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Error and Result module

use failure::{self, Fail};
use failure;
use serde_json;
use std::{io, result};

pub type Result<T> = result::Result<T, Error>;

// General error the crate
#[derive(Fail, Debug)]
pub enum Error {
#[fail(display = "Invalid header protocol")]
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! The library implementation Zabbix sender protocol
//! more details:
//! [Zabbix Documentation - 4 Trapper items](https://www.zabbix.com/documentation/3.0/manual/appendix/items/trapper).
//! [Docs/protocols/zabbix sender/2.0](https://www.zabbix.org/wiki/Docs/protocols/zabbix_sender/2.0).
//!

#[macro_use]
extern crate serde_derive;
extern crate byteorder;
Expand All @@ -18,16 +24,19 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
const ZBX_HDR: &'static [u8; 5] = b"ZBXD\x01";
const ZBX_HDR_SIZE: usize = 13;

/// implementation Zabbix sender protocol.
pub struct Sender {
server: String,
port: u16,
}

impl Sender {
/// Creates a new instance of the client zabbix.
pub fn new(server: String, port: u16) -> Sender {
Sender { server, port }
}

/// Sends data to the server according to Protocol rules
pub fn send<T>(&self, msg: T) -> Result<Response>
where
T: ToMessage,
Expand Down Expand Up @@ -66,6 +75,7 @@ impl Sender {
}
}

/// Data item sent to the server.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SendValue {
host: String,
Expand All @@ -84,22 +94,26 @@ impl<'a> From<(&'a str, &'a str, &'a str)> for SendValue {
}
}

/// The message that is sent to the Zabbix server.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Message {
request: &'static str,
data: Vec<SendValue>,
}

impl Message {
/// Constant request header to the server.
const REQUEST: &'static str = "sender data";

/// Creating a new instance of the Message structure from SendValue.
pub fn new(value: SendValue) -> Message {
Message {
request: Message::REQUEST,
data: vec![value],
}
}

/// Adds an entry to send a composed message.
pub fn add(&mut self, value: SendValue) {
self.data.push(value)
}
Expand All @@ -114,6 +128,7 @@ impl Default for Message {
}
}

/// Contract for types that provide the ability to cast to a `Message` type.
pub trait ToMessage {
fn to_message(self) -> Message;
}
Expand Down Expand Up @@ -145,6 +160,7 @@ impl ToMessage for Vec<SendValue> {
}
}

/// Structure of Zabbix server's response
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Response {
response: String,
Expand Down

0 comments on commit 716ad2b

Please sign in to comment.