1
+ //! This library is intended for use in both the Inquisitor Agent and the Inquisitor Receptor.
2
+ //! Plugin authors must implement the plugin trait for their desired platform, but they
3
+ //! may also make use of several convience functions included in this library.
1
4
#[ macro_use]
2
5
extern crate serde_derive;
3
6
extern crate serde;
@@ -19,7 +22,8 @@ use std::collections::HashMap;
19
22
use std:: path:: PathBuf ;
20
23
use std:: time:: { SystemTime , UNIX_EPOCH } ;
21
24
22
-
25
+ /// This struct is for communication between agent and receptor.
26
+ /// Plugins should not use this directly
23
27
#[ derive( Serialize , Deserialize , Debug ) ]
24
28
pub struct Status {
25
29
pub sender : String ,
@@ -28,13 +32,18 @@ pub struct Status {
28
32
pub plugin_name : String
29
33
}
30
34
35
+ /// A utility function that returns the current timestamp in seconds
31
36
pub fn current_ts ( ) -> i64 {
32
37
SystemTime :: now ( )
33
38
. duration_since ( UNIX_EPOCH )
34
39
. expect ( "Error getting system time !?" )
35
40
. as_secs ( ) as i64
36
41
}
37
42
43
+ /// A utility function that returns a deserialized object from a configuration file.
44
+ /// Plugins should use this instead of manipulating their own configuration file
45
+ ///
46
+ /// # TODO examples
38
47
pub fn read_cfg < ConfigT > ( cfg_file_path : & PathBuf ) -> Result < ConfigT , String >
39
48
where
40
49
ConfigT : DeserializeOwned
@@ -45,11 +54,15 @@ where
45
54
Ok ( cfg)
46
55
}
47
56
57
+ /// This trait is required by agent plugins
48
58
pub trait AgentPlugin {
59
+ /// Returns the plugin's name. Sent to the server to tag plugin messages
49
60
fn name ( & self ) -> & ' static str ;
50
-
61
+ /// This is the 'worker' function, and will be called when the ready fucntion returns true.
62
+ /// Currently this requires plugins to return a string.
63
+ /// An `Ok` will be sent to the server, while currently an `Err` is output to the terminal on the agent
51
64
fn gather ( & mut self ) -> Result < String , String > ;
52
-
65
+ /// This function tells the agent if the plugin is ready to be run.
53
66
fn ready ( & self ) -> bool ;
54
67
}
55
68
@@ -61,10 +74,14 @@ pub fn get_url_params(req: &Request) -> HashMap<String, String> {
61
74
hash_query
62
75
}
63
76
77
+ /// This trait is required by receptor plugins
64
78
pub trait ReceptorPlugin {
79
+ /// Returns the plugin's name. Stored in the database with the message returnd
65
80
fn name ( & self ) -> & ' static str ;
66
-
81
+ /// This is the 'worker' function, and will be called when the ready fucntion returns true.
82
+ /// Currently this requires plugins to return a string.
83
+ /// An `Ok` will be stored, while currently an `Err` is output to the terminal on the receptor
67
84
fn gather ( & mut self , db_conn : & Connection ) -> Result < String , String > ;
68
-
85
+ /// This function tells the receptor if the plugin is ready to be run.
69
86
fn ready ( & self ) -> bool ;
70
87
}
0 commit comments