Dripline-Cpp  v2.4.2
Dripline Implementation in C++
dripline_config.cc
Go to the documentation of this file.
1 /*
2  * dripline_config.cc
3  *
4  * Created on: Jun 26, 2019
5  * Author: N.S. Oblath
6  */
7 
8 #define DRIPLINE_API_EXPORTS
9 
10 #include "dripline_config.hh"
11 
12 #include "application.hh"
13 
14 #include "logger.hh"
15 
16 using scarab::param_node;
17 
18 LOGGER( dlog, "agent_config" );
19 
20 namespace dripline
21 {
22 
23  dripline_config::dripline_config( const std::string& a_auth_file )
24  {
25  // default dripline configuration
26 
27  scarab::path t_auth_default_path;
28 #ifdef DRIPLINE_AUTH_FILE
29  //add logic for default auth file if it exists
30  LTRACE( dlog, "Have a default auth path provided at build time: <" << TOSTRING( DRIPLINE_AUTH_FILE ) << ">" );
31  t_auth_default_path = scarab::expand_path( TOSTRING( DRIPLINE_AUTH_FILE ) );
32 #endif
33  if( ! a_auth_file.empty() )
34  {
35  LTRACE( dlog, "Have a default auth path provided at runtime: <" << a_auth_file << ">" );
36  t_auth_default_path = scarab::expand_path( a_auth_file );
37  }
38 
39  if ( ! t_auth_default_path.empty() && boost::filesystem::exists( t_auth_default_path ) )
40  {
41  LDEBUG( dlog, "default auth file found, setting that as initial value: " << t_auth_default_path.string() );
42  add( "auth-file", t_auth_default_path.string() );
43  }
44  else
45  {
46  if( t_auth_default_path.empty() )
47  {
48  LDEBUG( dlog, "No default auth file present; will not be set in dripline_config" );
49  }
50  else
51  {
52  LDEBUG( dlog, "Default auth path <" << t_auth_default_path.string() << "> does not exist; will not be set in dripline_config" );
53  }
54  }
55  add( "requests-exchange", "requests" );
56  add( "alerts-exchange", "alerts" );
57  add( "max-payload-size", DL_MAX_PAYLOAD_SIZE );
58  add( "loop-timeout-ms", 1000 );
59  add( "message-wait-ms", 1000 );
60  add( "heartbeat-routing-key", "heartbeat" );
61  add( "heartbeat-interval-s", 60 );
62 
63  // broker and broker-port can be specified in the config.
64  // however, we don't give default values so that they can be specified in the auth file.
65  // the dripline config will override the auth file if it's given there.
66  //add( "broker-port", 5672 );
67  //add( "broker", "localhost" );
68 
69  }
70 
72  {
73  }
74 
75  void add_dripline_options( scarab::main_app& an_app )
76  {
77  an_app.add_config_option< std::string >( "-b,--broker", "dripline.broker", "Set the dripline broker address" );
78  an_app.add_config_option< unsigned >( "-p,--port", "dripline.broker-port", "Set the port for communication with the dripline broker" );
79  an_app.add_config_option< std::string >( "--auth-file", "dripline.auth-file", "Set the authentication file path" );
80  an_app.add_config_option< std::string >( "--requests-exchange", "dripline.requests-exchange", "Set the name of the requests exchange" );
81  an_app.add_config_option< std::string >( "--alerts-exchange", "dripline.alerts-exchange", "Set the name of the alerts exchange" );
82  an_app.add_config_option< unsigned >( "--max-payload", "dripline.max-payload-size", "Set the maximum payload size (in bytes)" );
83  an_app.add_config_option< unsigned >( "--loop-timeout-ms" "dripline.loop-timeout-ms", "Set the timeout for thread loops in ms" );
84  an_app.add_config_option< unsigned >( "--message-wait-ms" "dripline.message-wait-ms", "Set the time to wait for a full multi-part message in ms" );
85  an_app.add_config_option< std::string >( "--heartbeat-routing-key", "dripline.heartbeat-routing-key", "Set the first token of heartbeat routing keys: [token].[origin]" );
86  an_app.add_config_option< unsigned >( "--heartbeat-interval-s", "dripline.heartbeat-interval-s", "Set the interval between heartbeats in s" );
87 
88  return;
89  }
90 
91 } /* namespace dripline */
static scarab::logger dlog("agent_config")
static scarab::logger dlog("agent")
dripline_config(const std::string &a_auth_file="")
void add_dripline_options(scarab::main_app &an_app)
Add basic AMQP options to an app object.
#define DL_MAX_PAYLOAD_SIZE