Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef ANALYTICS_OPTIONS_H_ 7 : #define ANALYTICS_OPTIONS_H_ 8 : 9 : #include <cassert> 10 : #include <boost/program_options.hpp> 11 : #include "io/event_manager.h" 12 : #include <analytics/viz_types.h> 13 : #include "config-client-mgr/config_client_options.h" 14 : 15 : class ConfigClientManager; 16 : 17 : #define ANALYTICS_DATA_TTL_DEFAULT 48 // g_viz_constants.AnalyticsTTL 18 : 19 : class DbWriteOptions { 20 : public: 21 0 : const uint32_t get_disk_usage_percentage_high_watermark0() const { 22 0 : return disk_usage_percentage_high_watermark0_; } 23 0 : const uint32_t get_disk_usage_percentage_low_watermark0() const { 24 0 : return disk_usage_percentage_low_watermark0_; } 25 0 : const uint32_t get_disk_usage_percentage_high_watermark1() const { 26 0 : return disk_usage_percentage_high_watermark1_; } 27 0 : const uint32_t get_disk_usage_percentage_low_watermark1() const { 28 0 : return disk_usage_percentage_low_watermark1_; } 29 0 : const uint32_t get_disk_usage_percentage_high_watermark2() const { 30 0 : return disk_usage_percentage_high_watermark2_; } 31 0 : const uint32_t get_disk_usage_percentage_low_watermark2() const { 32 0 : return disk_usage_percentage_low_watermark2_; } 33 : 34 0 : const uint32_t get_pending_compaction_tasks_high_watermark0() const { 35 0 : return pending_compaction_tasks_high_watermark0_; } 36 0 : const uint32_t get_pending_compaction_tasks_low_watermark0() const { 37 0 : return pending_compaction_tasks_low_watermark0_; } 38 0 : const uint32_t get_pending_compaction_tasks_high_watermark1() const { 39 0 : return pending_compaction_tasks_high_watermark1_; } 40 0 : const uint32_t get_pending_compaction_tasks_low_watermark1() const { 41 0 : return pending_compaction_tasks_low_watermark1_; } 42 0 : const uint32_t get_pending_compaction_tasks_high_watermark2() const { 43 0 : return pending_compaction_tasks_high_watermark2_; } 44 0 : const uint32_t get_pending_compaction_tasks_low_watermark2() const { 45 0 : return pending_compaction_tasks_low_watermark2_; } 46 : 47 0 : SandeshLevel::type get_high_watermark0_message_severity_level() const { 48 0 : return Sandesh::StringToLevel( 49 0 : high_watermark0_message_severity_level_); } 50 0 : SandeshLevel::type get_low_watermark0_message_severity_level() const { 51 0 : return Sandesh::StringToLevel( 52 0 : low_watermark0_message_severity_level_); } 53 0 : SandeshLevel::type get_high_watermark1_message_severity_level() const { 54 0 : return Sandesh::StringToLevel( 55 0 : high_watermark1_message_severity_level_); } 56 0 : SandeshLevel::type get_low_watermark1_message_severity_level() const { 57 0 : return Sandesh::StringToLevel( 58 0 : low_watermark1_message_severity_level_); } 59 0 : SandeshLevel::type get_high_watermark2_message_severity_level() const { 60 0 : return Sandesh::StringToLevel( 61 0 : high_watermark2_message_severity_level_); } 62 0 : SandeshLevel::type get_low_watermark2_message_severity_level() const { 63 0 : return Sandesh::StringToLevel( 64 0 : low_watermark2_message_severity_level_); } 65 : 66 : uint32_t disk_usage_percentage_high_watermark0_; 67 : uint32_t disk_usage_percentage_low_watermark0_; 68 : uint32_t disk_usage_percentage_high_watermark1_; 69 : uint32_t disk_usage_percentage_low_watermark1_; 70 : uint32_t disk_usage_percentage_high_watermark2_; 71 : uint32_t disk_usage_percentage_low_watermark2_; 72 : uint32_t pending_compaction_tasks_high_watermark0_; 73 : uint32_t pending_compaction_tasks_low_watermark0_; 74 : uint32_t pending_compaction_tasks_high_watermark1_; 75 : uint32_t pending_compaction_tasks_low_watermark1_; 76 : uint32_t pending_compaction_tasks_high_watermark2_; 77 : uint32_t pending_compaction_tasks_low_watermark2_; 78 : std::string high_watermark0_message_severity_level_; 79 : std::string low_watermark0_message_severity_level_; 80 : std::string high_watermark1_message_severity_level_; 81 : std::string low_watermark1_message_severity_level_; 82 : std::string high_watermark2_message_severity_level_; 83 : std::string low_watermark2_message_severity_level_; 84 : }; 85 : 86 : // Process command line/configuration file options for collector. 87 : class Options { 88 : public: 89 : struct Cassandra { 90 9 : Cassandra() : 91 9 : user_(), 92 9 : password_(), 93 9 : use_ssl_(), 94 9 : ca_certs_(), 95 9 : compaction_strategy_(), 96 9 : flow_tables_compaction_strategy_(), 97 9 : disable_all_db_writes_(false), 98 9 : disable_db_stats_writes_(false), 99 18 : disable_db_messages_writes_(false) 100 : { 101 9 : } 102 : 103 : std::string cluster_id_; 104 : vector<string> cassandra_ips_; 105 : vector<int> cassandra_ports_; 106 : TtlMap ttlmap_; 107 : std::string user_; 108 : std::string password_; 109 : bool use_ssl_; 110 : std::string ca_certs_; 111 : std::string compaction_strategy_; 112 : std::string replication_factor_; 113 : std::string flow_tables_compaction_strategy_; 114 : bool disable_all_db_writes_; 115 : bool disable_db_stats_writes_; 116 : bool disable_db_messages_writes_; 117 : }; 118 : 119 : struct Kafka { 120 8 : Kafka() : 121 8 : ssl_enable(false), 122 8 : keyfile(), 123 8 : certfile(), 124 8 : ca_cert() {} 125 : bool ssl_enable; 126 : std::string keyfile; 127 : std::string certfile; 128 : std::string ca_cert; 129 : }; 130 : 131 : Options(); 132 : bool Parse(EventManager &evm, int argc, char **argv); 133 : void ParseReConfig(); 134 : 135 7 : const Cassandra get_cassandra_options() const { 136 7 : return cassandra_options_; 137 : } 138 : 139 : void add_cassandra_ip(std::string cassandra_ip) { 140 : cassandra_options_.cassandra_ips_.push_back(cassandra_ip); 141 : } 142 : void add_cassandra_port(int cassandra_port) { 143 : cassandra_options_.cassandra_ports_.push_back(cassandra_port); 144 : } 145 : 146 : void set_ttl_map(TtlMap &ttlmap) { 147 : cassandra_options_.ttlmap_ = ttlmap; 148 : } 149 : 150 : const TtlMap get_ttl_map() const { 151 : return cassandra_options_.ttlmap_; 152 : } 153 : 154 20 : const std::vector<std::string> cassandra_server_list() const { 155 20 : return cassandra_server_list_; 156 : } 157 : const Kafka get_kafka_options() const { 158 : return kafka_options_; 159 : } 160 : const std::string zookeeper_server_list() const { 161 : return zookeeper_server_list_; 162 : } 163 : const std::vector<std::string> uve_proxy_list() const { 164 : return uve_proxy_list_; 165 : } 166 : const std::vector<std::string> kafka_broker_list() const { 167 : return kafka_broker_list_; 168 : } 169 : const std::vector<std::string> collector_structured_syslog_tcp_forward_destination() const { 170 : return collector_structured_syslog_tcp_forward_destination_; 171 : } 172 : const std::vector<std::string> collector_structured_syslog_kafka_broker_list() const { 173 : return collector_structured_syslog_kafka_broker_list_; 174 : } 175 : const std::string collector_structured_syslog_kafka_topic() const { 176 : return collector_structured_syslog_kafka_topic_; 177 : } 178 : const uint16_t collector_structured_syslog_kafka_partitions() const { 179 : return collector_structured_syslog_kafka_partitions_; 180 : } 181 : const uint16_t partitions() const { return partitions_; } 182 6 : const std::string collector_server() const { return collector_server_; } 183 6 : const uint16_t collector_port() const { return collector_port_; }; 184 6 : bool collector_structured_syslog_port(uint16_t *collector_structured_syslog_port) const { 185 6 : if (collector_structured_syslog_port_configured_) { 186 2 : *collector_structured_syslog_port = collector_structured_syslog_port_; 187 : } 188 6 : return collector_structured_syslog_port_configured_; 189 : } 190 6 : const uint64_t collector_active_session_map_limit() const { 191 6 : return collector_structured_syslog_active_session_map_limit_; 192 : } 193 24 : const std::vector<std::string> config_file() const { 194 24 : return config_file_; 195 : } 196 : const DbWriteOptions get_db_write_options() const { 197 : return db_write_options_; 198 : } 199 6 : const std::string redis_server() const { return redis_server_; } 200 6 : const uint16_t redis_port() const { return redis_port_; } 201 : const std::string redis_password() const { return redis_password_; } 202 6 : const std::string hostname() const { return hostname_; } 203 6 : const std::string host_ip() const { return host_ip_; } 204 6 : const uint16_t http_server_port() const { return http_server_port_; } 205 6 : const std::string log_category() const { return log_category_; } 206 6 : const bool log_disable() const { return log_disable_; } 207 6 : const std::string log_file() const { return log_file_; } 208 : const std::string log_property_file() const { return log_property_file_; } 209 6 : const int log_files_count() const { return log_files_count_; } 210 6 : const long log_file_size() const { return log_file_size_; } 211 6 : const std::string log_level() const { return log_level_; } 212 6 : const bool log_local() const { return log_local_; } 213 : const bool use_syslog() const { return use_syslog_; } 214 : const std::string syslog_facility() const { return syslog_facility_; } 215 : const std::string kafka_prefix() const { return kafka_prefix_; } 216 6 : const bool dup() const { return dup_; } 217 7 : const uint64_t analytics_data_ttl() const { return analytics_data_ttl_; } 218 7 : const uint64_t analytics_flow_ttl() const { return analytics_flow_ttl_; } 219 7 : const uint64_t analytics_statistics_ttl() const { return analytics_statistics_ttl_; } 220 7 : const uint64_t analytics_config_audit_ttl() const { return analytics_config_audit_ttl_; } 221 6 : const bool test_mode() const { return test_mode_; } 222 5 : const bool disable_flow_collection() const { return disable_flow_collection_; } 223 3 : const bool disable_all_db_writes() const { return cassandra_options_.disable_all_db_writes_; } 224 2 : const bool disable_db_statistics_writes() const { return cassandra_options_.disable_db_stats_writes_; } 225 2 : const bool disable_db_messages_writes() const { return cassandra_options_.disable_db_messages_writes_; } 226 5 : const std::string cluster_id() const { return cassandra_options_.cluster_id_; } 227 : const std::string auth_host() const { return ks_server_; } 228 : const uint16_t auth_port() const { return ks_port_; } 229 : const std::string auth_protocol() const { return ks_protocol_; } 230 : const std::string auth_user() const { return ks_user_; } 231 : const std::string auth_passwd() const { return ks_password_; } 232 : const std::string auth_tenant() const { return ks_tenant_; } 233 : const std::string keystone_keyfile() const { return ks_key_; } 234 : const std::string keystone_certfile() const { return ks_cert_; } 235 : const std::string keystone_cafile() const { return ks_ca_; } 236 10 : const SandeshConfig &sandesh_config() const { return sandesh_config_; } 237 : const int api_server_checksum() const { return api_server_checksum_; } 238 : const std::vector<std::string> api_server_list() const { 239 : return api_server_list_; 240 : } 241 : const bool api_server_use_ssl() const { return api_server_use_ssl_; } 242 : 243 0 : void set_config_client_manager(ConfigClientManager* mgr) { 244 0 : config_client_manager_ = mgr; 245 0 : } 246 : 247 5 : const ConfigClientOptions &configdb_options() const { 248 5 : return configdb_options_; 249 : } 250 : 251 : private: 252 : void Process(int argc, char *argv[], 253 : boost::program_options::options_description &cmdline_options); 254 : void Initialize(EventManager &evm, 255 : boost::program_options::options_description &options); 256 : uint32_t GenerateHash(const std::vector<std::string> &); 257 : uint32_t GenerateHash(const ConfigClientOptions &config); 258 : void ParseConfigOptions(const boost::program_options::variables_map 259 : &var_map); 260 : 261 : std::string collector_server_; 262 : uint16_t collector_port_; 263 : uint16_t collector_structured_syslog_port_; 264 : bool collector_structured_syslog_port_configured_; 265 : std::vector<std::string> collector_structured_syslog_tcp_forward_destination_; 266 : std::vector<std::string> collector_structured_syslog_kafka_broker_list_; 267 : std::string collector_structured_syslog_kafka_topic_; 268 : uint16_t collector_structured_syslog_kafka_partitions_; 269 : uint64_t collector_structured_syslog_active_session_map_limit_; 270 : std::vector<std::string> config_file_; 271 : std::string redis_server_; 272 : uint16_t redis_port_; 273 : std::string redis_password_; 274 : Cassandra cassandra_options_; 275 : Kafka kafka_options_; 276 : std::string hostname_; 277 : std::string host_ip_; 278 : uint16_t http_server_port_; 279 : std::string log_category_; 280 : bool log_disable_; 281 : std::string log_file_; 282 : std::string log_property_file_; 283 : int log_files_count_; 284 : long log_file_size_; 285 : std::string log_level_; 286 : bool log_local_; 287 : bool use_syslog_; 288 : std::string syslog_facility_; 289 : std::string kafka_prefix_; 290 : bool test_mode_; 291 : bool dup_; 292 : uint64_t analytics_data_ttl_; 293 : uint64_t analytics_config_audit_ttl_; 294 : uint64_t analytics_flow_ttl_; 295 : uint64_t analytics_statistics_ttl_; 296 : std::vector<std::string> cassandra_server_list_; 297 : std::string zookeeper_server_list_; 298 : std::vector<std::string> uve_proxy_list_; 299 : std::vector<std::string> kafka_broker_list_; 300 : uint16_t partitions_; 301 : uint32_t sandesh_ratelimit_; 302 : bool disable_flow_collection_; 303 : std::string ks_server_; 304 : uint16_t ks_port_; 305 : std::string ks_protocol_; 306 : std::string ks_user_; 307 : std::string ks_password_; 308 : std::string ks_tenant_; 309 : std::string ks_authurl_; 310 : bool ks_insecure_; 311 : std::string memcache_servers_; 312 : std::string ks_cert_; 313 : std::string ks_key_; 314 : std::string ks_ca_; 315 : SandeshConfig sandesh_config_; 316 : uint32_t api_server_checksum_; 317 : std::vector<std::string> api_server_list_; 318 : bool api_server_use_ssl_; 319 : 320 : boost::program_options::options_description config_file_options_; 321 : DbWriteOptions db_write_options_; 322 : 323 : uint32_t configdb_chksum_; 324 : ConfigClientManager* config_client_manager_; 325 : ConfigClientOptions configdb_options_; 326 : }; 327 : 328 : #endif /* ANALYTICS_OPTIONS_H_ */