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