fluentbit/
lib.rs

1//! # fluentbit    
2//! This crate aims to build output plugins for [Fluent-bit](https://fluentbit.io/).
3//! It is based on  the Go interface for writting output plugins.
4//!
5//! This crate is still in heavy development. At this point, Multiple-instance plugin is not supported
6//! but it would be added very soon.
7//! # Hello World
8//! A simple Hello world example which prints data to stdout, it involves following three steps:
9//! - Create a struct/enum with the data you might use for processing the incoming buffer from Fluent-bit
10//! - Implement the trait *FLBPluginMethods* for that struct/enum.
11//! - After steps 1 and 2, call the macro create_boilerplate!() which will generate the boilerplate code that every plugin should have, 
12//!   taking care of the unsafe safe code and abstracting it into a safe Rust style. 
13//!   This macro will accept as an argument any type which implements the FLBPluginMethods trait
14//!
15//! And that's all. Compile your plugin as a dynamic library by adding this line to your Cargo.toml
16//!
17//! ```
18//! [lib]
19//! crate-type=["cdylib"]
20//! ```
21//!
22//! Another thing that is worth to mention is that Fluent-bit should be able to load Go plugins even though
23//! your plugin was written in Rust. To enable external plugins'  support  you have to compile Fluent-bit with Goland support, e.g:
24//!
25//! ```
26//! $ cd build/
27//! $ cmake -DFLB_DEBUG=On -DFLB_PROXY_GO=On ../
28//! $ make && make install
29//! ```
30//! Once compiled, you can see a new option in the binary -e which stands for external plugin, e.g:
31//! ```
32//! $ bin/fluent-bit -h
33//! Usage: fluent-bit [OPTION]
34
35//! Available Options
36//!  -c  --config=FILE	specify an optional configuration file
37//!  -d, --daemon		run Fluent Bit in background mode
38//!  -f, --flush=SECONDS	flush timeout in seconds (default: 5)
39//!  -i, --input=INPUT	set an input
40//!  -m, --match=MATCH	set plugin match, same as '-p match=abc'
41//!  -o, --output=OUTPUT	set an output
42//!  -p, --prop="A=B"	set plugin configuration property
43//!  -e, --plugin=FILE	load an external plugin (shared lib)
44//!  ...
45//! ```
46//!
47//! Now here is a simple output plugin
48//!
49//! ```
50//! extern crate fluentbit;
51//! use fluentbit::*;
52//! 
53//! extern crate rmpv;
54//! extern crate serde_json;
55//! 
56//! extern crate serde;
57//! 
58//! 
59//! #[derive(Default)]
60//! struct JsonExample{}
61//! 
62//! impl FLBPluginMethods for JsonExample{
63//!     
64//!     fn plugin_register(&mut self, info: &mut PluginInfo) -> FLBResult{
65//!         info.name = "rustout".into();
66//!         info.description = "This is a default description".into();
67//!         Ok(())
68//!     }
69//! 
70//!     fn plugin_init(&mut self) -> FLBResult{
71//!         println!("default init");
72//!         Ok(())
73//!     }
74//! 
75//!     fn plugin_flush(&mut self, data: &[u8]) -> FLBResult{
76//! 
77//!         let mut value = data.clone();
78//!         let value: rmpv::Value = rmpv::decode::value::read_value(&mut value).unwrap();
79//!         let json = serde_json::to_string_pretty(&value).unwrap();
80//!         
81//!         println!("{}", json);
82//!         Ok(())
83//!     }
84//! 
85//!     fn plugin_exit(&mut self) -> FLBResult{
86//!         println!("exiting");
87//!         Ok(())
88//!     }
89//!     
90//! }
91//! 
92//! create_boilerplate!(JsonExample::default());
93//! ```
94//!
95//! Test your plugin:
96//! ```
97//! cargo build --release
98//! fluent-bit -e target/release/libexample.so -i cpu -o "rustout"
99//! ```
100
101mod fluent;
102pub use fluent::*;