diff --git a/src/70-influxdb/CMakeLists.txt b/src/70-influxdb/CMakeLists.txt index 5b2e8ef8196..c0411275670 100644 --- a/src/70-influxdb/CMakeLists.txt +++ b/src/70-influxdb/CMakeLists.txt @@ -32,5 +32,5 @@ add_library(70-influxdb SHARED ${CMAKE_SOURCE_DIR}/src/70-influxdb/stream.cc ) set_target_properties(70-influxdb PROPERTIES PREFIX "") -target_link_libraries(70-influxdb CONAN_PKG::asio) -install(TARGETS 70-influxdb DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/centreon/lib/centreon-broker) \ No newline at end of file +target_link_libraries(70-influxdb CONAN_PKG::asio CONAN_PKG::fmt) +install(TARGETS 70-influxdb DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/centreon/lib/centreon-broker) diff --git a/src/70-influxdb/column.cc b/src/70-influxdb/column.cc index 2536419ef17..443f571925a 100644 --- a/src/70-influxdb/column.cc +++ b/src/70-influxdb/column.cc @@ -17,8 +17,9 @@ */ #include "com/centreon/broker/influxdb/column.hh" -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; using namespace com::centreon::broker::influxdb; @@ -75,36 +76,28 @@ column& column::operator=(column const& c) { * * @return The name of this column. */ -std::string const& column::get_name() const { - return (_name); -} +std::string const& column::get_name() const { return (_name); } /** * Get the value of this column. * * @return The value of this column. */ -std::string const& column::get_value() const { - return (_value); -} +std::string const& column::get_value() const { return (_value); } /** * Is this column a flag? * * @return True if this column is a flag. */ -bool column::is_flag() const { - return (_is_flag); -} +bool column::is_flag() const { return (_is_flag); } /** * Get the type of this column. * * @return The type of this column. */ -column::type column::get_type() const { - return (_type); -} +column::type column::get_type() const { return (_type); } /** * Parse a string containing a type. @@ -118,6 +111,5 @@ column::type column::parse_type(std::string const& type) { return (string); else if (type == "number") return (number); - throw(exceptions::msg() << "influxdb: couldn't parse column type '" << type - << "'"); + throw msg_fmt("influxdb: couldn't parse column type '{}'", type); } diff --git a/src/70-influxdb/factory.cc b/src/70-influxdb/factory.cc index acb2d2a6d0f..40da2f7bec4 100644 --- a/src/70-influxdb/factory.cc +++ b/src/70-influxdb/factory.cc @@ -23,10 +23,11 @@ #include #include #include "com/centreon/broker/config/parser.hh" -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/broker/influxdb/column.hh" #include "com/centreon/broker/influxdb/connector.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; using namespace com::centreon::broker::influxdb; using namespace json11; @@ -49,8 +50,7 @@ static std::string find_param(config::endpoint const& cfg, std::string const& key) { std::map::const_iterator it{cfg.params.find(key)}; if (cfg.params.end() == it) - throw exceptions::msg() << "influxdb: no '" << key - << "' defined for endpoint '" << cfg.name << "'"; + throw msg_fmt("influxdb: no '{}' defined for endpoint '{}'", key, cfg.name); return it->second; } @@ -85,10 +85,10 @@ bool factory::has_endpoint(config::endpoint& cfg) const { * * @return Endpoint matching the given configuration. */ -io::endpoint* factory::new_endpoint( - config::endpoint& cfg, - bool& is_acceptor, - std::shared_ptr cache) const { +io::endpoint* factory::new_endpoint(config::endpoint& cfg, + bool& is_acceptor, + std::shared_ptr cache) + const { std::string user(find_param(cfg, "db_user")); std::string passwd(find_param(cfg, "db_password")); std::string addr(find_param(cfg, "db_host")); @@ -105,9 +105,10 @@ io::endpoint* factory::new_endpoint( ss << it->second; ss >> port; if (!ss.eof()) - throw exceptions::msg() - << "influxdb: couldn't parse port '" << ss.str() - << "' defined for endpoint '" << cfg.name << "'"; + throw msg_fmt( + "influxdb: couldn't parse port '{}' defined for endpoint '{}'", + ss.str(), + cfg.name); } } @@ -118,23 +119,25 @@ io::endpoint* factory::new_endpoint( if (it != cfg.params.end()) try { queries_per_transaction = std::stoul(it->second); - } catch (std::exception const& ex) { - throw exceptions::msg() - << "influxdb: couldn't parse queries_per_transaction '" - << it->second << "' defined for endpoint '" << cfg.name << "'"; } - else - queries_per_transaction = 1000; + catch (std::exception const& ex) { + throw msg_fmt( + "influxdb: couldn't parse queries_per_transaction '{}' defined for " + "endpoint '{}'", + it->second, + cfg.name); + } + else queries_per_transaction = 1000; } - auto chk_str = [](Json const& js) -> std::string { + auto chk_str = [](Json const & js)->std::string { if (!js.is_string() || js.string_value().empty()) { - throw exceptions::msg() - << "influxdb: couldn't get the configuration of a metric column name"; + throw msg_fmt( + "influxdb: couldn't get the configuration of a metric column name"); } return js.string_value(); }; - auto chk_bool = [](std::string const& boolean) -> bool { + auto chk_bool = [](std::string const & boolean)->bool { if (boolean == "yes" || boolean == "true") return true; return false; @@ -145,14 +148,16 @@ io::endpoint* factory::new_endpoint( std::vector status_column_list; Json const& status_columns = cfg.cfg["status_column"]; if (status_columns.is_object()) - status_column_list.push_back(column( - chk_str(status_columns["name"]), chk_str(status_columns["value"]), - chk_bool(chk_str(status_columns["is_tag"])), - column::parse_type(chk_str(status_columns["type"])))); + status_column_list.push_back( + column(chk_str(status_columns["name"]), + chk_str(status_columns["value"]), + chk_bool(chk_str(status_columns["is_tag"])), + column::parse_type(chk_str(status_columns["type"])))); else if (status_columns.is_array()) for (Json const& object : status_columns.array_items()) status_column_list.push_back( - column(chk_str(object["name"]), chk_str(object["value"]), + column(chk_str(object["name"]), + chk_str(object["value"]), chk_bool(chk_str(object["is_tag"])), column::parse_type(chk_str(object["type"])))); @@ -161,22 +166,32 @@ io::endpoint* factory::new_endpoint( std::vector metric_column_list; Json const& metric_columns = cfg.cfg["metrics_column"]; if (metric_columns.is_object()) - metric_column_list.push_back(column( - chk_str(metric_columns["name"]), chk_str(metric_columns["value"]), - chk_bool(chk_str(metric_columns["is_tag"])), - column::parse_type(chk_str(metric_columns["type"])))); + metric_column_list.push_back( + column(chk_str(metric_columns["name"]), + chk_str(metric_columns["value"]), + chk_bool(chk_str(metric_columns["is_tag"])), + column::parse_type(chk_str(metric_columns["type"])))); else if (metric_columns.is_array()) for (Json const& object : metric_columns.array_items()) metric_column_list.push_back( - column(chk_str(object["name"]), chk_str(object["value"]), + column(chk_str(object["name"]), + chk_str(object["value"]), chk_bool(chk_str(object["is_tag"])), column::parse_type(chk_str(object["type"])))); // Connector. std::unique_ptr c(new influxdb::connector); - c->connect_to(user, passwd, addr, port, db, queries_per_transaction, - status_timeseries, status_column_list, metric_timeseries, - metric_column_list, cache); + c->connect_to(user, + passwd, + addr, + port, + db, + queries_per_transaction, + status_timeseries, + status_column_list, + metric_timeseries, + metric_column_list, + cache); is_acceptor = false; return c.release(); } diff --git a/src/70-influxdb/influxdb12.cc b/src/70-influxdb/influxdb12.cc index f762230795d..0f89ad3abb3 100644 --- a/src/70-influxdb/influxdb12.cc +++ b/src/70-influxdb/influxdb12.cc @@ -19,11 +19,12 @@ #include "com/centreon/broker/influxdb/influxdb12.hh" #include #include -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/broker/logging/logging.hh" #include "com/centreon/broker/misc/string.hh" using namespace asio; +using namespace com::centreon::exceptions; using namespace com::centreon::broker::influxdb; static const char* query_footer = "\n"; @@ -46,8 +47,8 @@ influxdb12::influxdb12(std::string const& user, logging::debug(logging::medium) << "influxdb: connecting using 1.2 Line Protocol"; _connect_socket(); - _create_queries(user, passwd, db, status_ts, status_cols, metric_ts, - metric_cols); + _create_queries( + user, passwd, db, status_ts, status_cols, metric_ts, metric_cols); } /** @@ -58,9 +59,7 @@ influxdb12::~influxdb12() {} /** * Clear the query. */ -void influxdb12::clear() { - _query.clear(); -} +void influxdb12::clear() { _query.clear(); } /** * Write a metric to the query. @@ -106,10 +105,12 @@ void influxdb12::commit() { asio::write(_socket, buffer(final_query), asio::transfer_all(), err); if (err) - throw exceptions::msg() - << "influxdb: couldn't commit data to InfluxDB with address '" - << _socket.remote_endpoint().address().to_string() << "' and port '" - << _socket.remote_endpoint().port() << "': " << err.message(); + throw msg_fmt( + "influxdb: couldn't commit data to InfluxDB with address '{}' and port " + "'{}': {}", + _socket.remote_endpoint().address().to_string(), + _socket.remote_endpoint().port(), + err.message()); // Receive the server answer. std::string answer; @@ -118,18 +119,20 @@ void influxdb12::commit() { do { answer.resize(read_size); - total_read += _socket.read_some(asio::buffer(&answer[total_read], read_size - total_read), err); + total_read += _socket.read_some( + asio::buffer(&answer[total_read], read_size - total_read), err); if (total_read == read_size) total_read += 2048; answer.resize(total_read); if (err) - throw exceptions::msg() - << "influxdb: couldn't receive InfluxDB answer with address '" - << _socket.remote_endpoint().address().to_string() << "' and port '" - << _socket.remote_endpoint().port() << "': " << err.message(); - + throw msg_fmt( + "influxdb: couldn't receive InfluxDB answer with address '{}' and " + "port '{}': {}", + _socket.remote_endpoint().address().to_string(), + _socket.remote_endpoint().port(), + err.message()); } while (!_check_answer_string(answer)); _socket.shutdown(ip::tcp::socket::shutdown_both); @@ -166,14 +169,21 @@ void influxdb12::_connect_socket() { } if (err) { - throw exceptions::msg() - << "influxdb: couldn't connect to InfluxDB with address '" << _host - << "' and port '" << _port << "': " << err.message(); + throw msg_fmt( + "influxdb: couldn't connect to InfluxDB with address '{}' and port " + "'{}': {}", + _host, + _port, + err.message()); } - } catch (std::system_error const& se) { - throw exceptions::msg() - << "influxdb: couldn't connect to InfluxDB with address '" << _host - << "' and port '" << _port << "': " << se.what(); + } + catch (std::system_error const& se) { + throw msg_fmt( + "influxdb: couldn't connect to InfluxDB with address '{}' and port " + "'{}': {}", + _host, + _port, + se.what()); } } @@ -199,14 +209,15 @@ bool influxdb12::_check_answer_string(std::string const& ans) { std::istringstream iss(first_line_str); std::vector split; std::copy(std::istream_iterator(iss), - std::istream_iterator(), std::back_inserter(split)); + std::istream_iterator(), + std::back_inserter(split)); if (split.size() < 3) - throw exceptions::msg() - << "influxdb: unrecognizable HTTP header for '" - << _socket.remote_endpoint().address().to_string() << "' and port '" - << _socket.remote_endpoint().port() << "': got '" << first_line_str - << "'"; + throw msg_fmt( + "influxdb: unrecognizable HTTP header for '{}' and port '{}': got '{}'", + _socket.remote_endpoint().address().to_string(), + _socket.remote_endpoint().port(), + first_line_str); if ((split[0] == "HTTP/1.0") && (split[1] == "204") && (split[2] == "No") && (split[3] == "Content")) @@ -214,15 +225,14 @@ bool influxdb12::_check_answer_string(std::string const& ans) { else if (ans.find("partial write: points beyond retention policy dropped") != std::string::npos) { logging::info(logging::medium) << "influxdb: sending points beyond " - "Influxdb database configured " - "retention policy"; + "Influxdb database configured " + "retention policy"; return true; - } - else - throw exceptions::msg() - << "influxdb: got an error from '" - << _socket.remote_endpoint().address().to_string() << "' and port '" - << _socket.remote_endpoint().port() << "': '" << ans << "'"; + } else + throw msg_fmt("influxdb: got an error from '{}' and port '{}': '{}'", + _socket.remote_endpoint().address().to_string(), + _socket.remote_endpoint().port(), + ans); } /** @@ -252,8 +262,8 @@ void influxdb12::_create_queries(std::string const& user, _post_header.append("POST ").append(base_url).append(" HTTP/1.0\n"); // Create protocol objects. - _status_query = line_protocol_query(status_ts, status_cols, - line_protocol_query::status, _cache); - _metric_query = line_protocol_query(metric_ts, metric_cols, - line_protocol_query::metric, _cache); + _status_query = line_protocol_query( + status_ts, status_cols, line_protocol_query::status, _cache); + _metric_query = line_protocol_query( + metric_ts, metric_cols, line_protocol_query::metric, _cache); } diff --git a/src/70-influxdb/line_protocol_query.cc b/src/70-influxdb/line_protocol_query.cc index e3fe63674c2..2472fd9e748 100644 --- a/src/70-influxdb/line_protocol_query.cc +++ b/src/70-influxdb/line_protocol_query.cc @@ -19,10 +19,11 @@ #include "com/centreon/broker/influxdb/line_protocol_query.hh" #include #include -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/broker/logging/logging.hh" #include "com/centreon/broker/misc/string.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; using namespace com::centreon::broker::influxdb; @@ -59,7 +60,8 @@ line_protocol_query::line_protocol_query(std::string const& timeseries, // tag_set for (std::vector::const_iterator it(columns.begin()), end(columns.end()); - it != end; ++it) + it != end; + ++it) if (it->is_flag()) { // comma _append_compiled_string(","); @@ -78,7 +80,8 @@ line_protocol_query::line_protocol_query(std::string const& timeseries, bool first(true); for (std::vector::const_iterator it(columns.begin()), end(columns.end()); - it != end; ++it) + it != end; + ++it) if (!it->is_flag()) { if (first) first = false; @@ -175,15 +178,16 @@ std::string line_protocol_query::escape_value(std::string const& str) { */ std::string line_protocol_query::generate_metric(storage::metric const& me) { if (_type != metric) - throw(exceptions::msg() << "influxdb: attempt to generate metric" - " with a query of the bad type"); + throw msg_fmt( + "influxdb: attempt to generate metric with a query of the bad type"); _string_index = 0; std::ostringstream iss; try { for (std::vector >::const_iterator it(_compiled_getters.begin()), end(_compiled_getters.end()); - it != end; ++it) { + it != end; + ++it) { if (!it->second) (this->*(it->first))(me, iss); else { @@ -192,7 +196,8 @@ std::string line_protocol_query::generate_metric(storage::metric const& me) { iss << (this->*(it->second))(escaped.str()); } } - } catch (std::exception const& e) { + } + catch (std::exception const& e) { logging::error(logging::medium) << "influxdb: could not generate query for metric " << me.metric_id << ": " << e.what(); @@ -210,15 +215,16 @@ std::string line_protocol_query::generate_metric(storage::metric const& me) { */ std::string line_protocol_query::generate_status(storage::status const& st) { if (_type != status) - throw(exceptions::msg() << "influxdb: attempt to generate status" - " with a query of the bad type"); + throw msg_fmt( + "influxdb: attempt to generate status with a query of the bad type"); _string_index = 0; std::ostringstream iss; try { for (std::vector >::const_iterator it(_compiled_getters.begin()), end(_compiled_getters.end()); - it != end; ++it) { + it != end; + ++it) { if (!it->second) (this->*(it->first))(st, iss); else { @@ -227,7 +233,8 @@ std::string line_protocol_query::generate_status(storage::status const& st) { iss << (this->*(it->second))(escaped.str()); } } - } catch (std::exception const& e) { + } + catch (std::exception const& e) { logging::error(logging::medium) << "influxdb: could not generate query for status " << st.index_id << ": " << e.what(); @@ -283,9 +290,9 @@ void line_protocol_query::_compile_scheme( if ((end_macro = scheme.find_first_of('$', found_macro + 1)) == std::string::npos) - throw(exceptions::msg() - << "influxdb: can't compile query, opened macro not closed: '" - << scheme.substr(found_macro) << "'"); + throw msg_fmt( + "influxdb: can't compile query, opened macro not closed: '{}'", + scheme.substr(found_macro)); std::string macro(scheme.substr(found_macro, end_macro + 1 - found_macro)); if (macro == "$$") @@ -293,14 +300,16 @@ void line_protocol_query::_compile_scheme( if (macro == "$METRICID$") { _throw_on_invalid(metric); _append_compiled_getter( - &line_protocol_query::_get_member, escaper); } else if (macro == "$INSTANCE$") _append_compiled_getter(&line_protocol_query::_get_instance, escaper); else if (macro == "$INSTANCEID$") _append_compiled_getter( - &line_protocol_query::_get_member, escaper); else if (macro == "$HOST$") @@ -314,7 +323,8 @@ void line_protocol_query::_compile_scheme( else if (macro == "$METRIC$") { _throw_on_invalid(metric); _append_compiled_getter( - &line_protocol_query::_get_member, escaper); } else if (macro == "$INDEXID$") @@ -322,28 +332,32 @@ void line_protocol_query::_compile_scheme( else if (macro == "$VALUE$") { if (_type == metric) _append_compiled_getter( - &line_protocol_query::_get_member, escaper); else if (_type == status) _append_compiled_getter( - &line_protocol_query::_get_member, escaper); } else if (macro == "$TIME$") { if (_type == metric) _append_compiled_getter( - &line_protocol_query::_get_member, escaper); else if (_type == status) _append_compiled_getter( - &line_protocol_query::_get_member, escaper); } else - logging::config(logging::high) - << "influxdb: unknown macro '" << macro << "': ignoring it"; + logging::config(logging::high) << "influxdb: unknown macro '" << macro + << "': ignoring it"; found_macro = end_macro = end_macro + 1; } std::string substr(scheme.substr(end_macro, found_macro - end_macro)); @@ -358,7 +372,7 @@ void line_protocol_query::_compile_scheme( */ void line_protocol_query::_throw_on_invalid(data_type macro_type) { if (macro_type != _type) - throw(exceptions::msg() << "influxdb: macro of invalid type"); + throw msg_fmt("influxdb: macro of invalid type"); } /** @@ -405,10 +419,8 @@ uint32_t line_protocol_query::_get_index_id(io::data const& d) { if (_type == status) return static_cast(d).index_id; else - return _cache - ->get_metric_mapping( - static_cast(d).metric_id) - .index_id; + return _cache->get_metric_mapping(static_cast(d) + .metric_id).index_id; } /** @@ -429,7 +441,8 @@ void line_protocol_query::_get_index_id(io::data const& d, std::ostream& is) { */ void line_protocol_query::_get_host(io::data const& d, std::ostream& is) { if (_type == status) - is << _cache->get_host_name(_cache->get_index_mapping(_get_index_id(d)).host_id); + is << _cache->get_host_name( + _cache->get_index_mapping(_get_index_id(d)).host_id); else is << _cache->get_host_name(static_cast(d).host_id); } @@ -459,8 +472,9 @@ void line_protocol_query::_get_service(io::data const& d, std::ostream& is) { _cache->get_index_mapping(_get_index_id(d))); is << _cache->get_service_description(stm.host_id, stm.service_id); } else { - is << _cache->get_service_description(static_cast(d).host_id, - static_cast(d).service_id); + is << _cache->get_service_description( + static_cast(d).host_id, + static_cast(d).service_id); } } diff --git a/src/70-influxdb/macro_cache.cc b/src/70-influxdb/macro_cache.cc index 381c26dd64b..cb451304b1e 100644 --- a/src/70-influxdb/macro_cache.cc +++ b/src/70-influxdb/macro_cache.cc @@ -17,9 +17,10 @@ */ #include "com/centreon/broker/influxdb/macro_cache.hh" -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/broker/logging/logging.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; using namespace com::centreon::broker::influxdb; @@ -66,8 +67,8 @@ storage::index_mapping const& macro_cache::get_index_mapping(uint64_t index_id) const { auto const found = _index_mappings.find(index_id); if (found == _index_mappings.end()) - throw exceptions::msg() << "influxdb: could not find host/service of index " - << index_id; + throw msg_fmt("influxdb: could not find host/service of index {}", + index_id); return *found->second; } @@ -82,8 +83,7 @@ storage::metric_mapping const& macro_cache::get_metric_mapping( uint64_t metric_id) const { auto const found = _metric_mappings.find(metric_id); if (found == _metric_mappings.end()) - throw exceptions::msg() << "influxdb: could not find index of metric " - << metric_id; + throw msg_fmt("influxdb: could not find index of metric {}", metric_id); return *found->second; } @@ -97,8 +97,7 @@ storage::metric_mapping const& macro_cache::get_metric_mapping( std::string const& macro_cache::get_host_name(uint64_t host_id) const { auto const found = _hosts.find(host_id); if (found == _hosts.end()) - throw exceptions::msg() << "influxdb: could not find information on host " - << host_id; + throw msg_fmt("influxdb: could not find information on host {}", host_id); return found->second->host_name; } @@ -115,9 +114,9 @@ std::string const& macro_cache::get_service_description(uint64_t host_id, const { auto const found = _services.find({host_id, service_id}); if (found == _services.end()) - throw exceptions::msg() - << "influxdb: could not find information on service (" << host_id - << ", " << service_id << ")"; + throw msg_fmt("influxdb: could not find information on service ({},{})", + host_id, + service_id); return found->second->service_description; } @@ -131,8 +130,8 @@ std::string const& macro_cache::get_service_description(uint64_t host_id, std::string const& macro_cache::get_instance(uint64_t instance_id) const { auto const found = _instances.find(instance_id); if (found == _instances.end()) - throw exceptions::msg() - << "influxdb: could not find information on instance " << instance_id; + throw msg_fmt("influxdb: could not find information on instance {}", + instance_id); return found->second->name; } diff --git a/src/70-influxdb/stream.cc b/src/70-influxdb/stream.cc index 2482b9e2a2a..bbaa3d07ad5 100644 --- a/src/70-influxdb/stream.cc +++ b/src/70-influxdb/stream.cc @@ -18,7 +18,6 @@ #include "com/centreon/broker/influxdb/stream.hh" #include -#include "com/centreon/broker/exceptions/msg.hh" #include "com/centreon/broker/exceptions/shutdown.hh" #include "com/centreon/broker/influxdb/influxdb12.hh" #include "com/centreon/broker/io/events.hh" @@ -63,8 +62,16 @@ stream::stream(std::string const& user, _actual_query(0), _commit(false), _cache(cache) { - _influx_db.reset(new influxdb12(user, passwd, addr, port, db, status_ts, - status_cols, metric_ts, metric_cols, _cache)); + _influx_db.reset(new influxdb12(user, + passwd, + addr, + port, + db, + status_ts, + status_cols, + metric_ts, + metric_cols, + _cache)); } /** @@ -78,8 +85,8 @@ stream::~stream() {} * @return Number of events acknowledged. */ int stream::flush() { - logging::debug(logging::medium) - << "influxdb: commiting " << _actual_query << " queries"; + logging::debug(logging::medium) << "influxdb: commiting " << _actual_query + << " queries"; int ret(_pending_queries); _actual_query = 0; _pending_queries = 0; diff --git a/tests/broker/influxdb/column.cc b/tests/broker/influxdb/column.cc index a165ec2e453..acae8fd323a 100644 --- a/tests/broker/influxdb/column.cc +++ b/tests/broker/influxdb/column.cc @@ -19,8 +19,9 @@ #include "com/centreon/broker/influxdb/column.hh" #include -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; TEST(InfluxDbColumn, Simple) { @@ -66,5 +67,5 @@ TEST(InfluxDbColumn, Assign) { TEST(InfluxDbColumn, ParseType) { ASSERT_EQ(influxdb::column::parse_type("string"), influxdb::column::string); ASSERT_EQ(influxdb::column::parse_type("number"), influxdb::column::number); - ASSERT_THROW(influxdb::column::parse_type("other"), exceptions::msg); + ASSERT_THROW(influxdb::column::parse_type("other"), msg_fmt); } \ No newline at end of file diff --git a/tests/broker/influxdb/factory.cc b/tests/broker/influxdb/factory.cc index a041779c371..19277eac497 100644 --- a/tests/broker/influxdb/factory.cc +++ b/tests/broker/influxdb/factory.cc @@ -19,8 +19,9 @@ #include "com/centreon/broker/influxdb/factory.hh" #include -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; TEST(InfluxDBFactory, HasEndpoint) { @@ -41,25 +42,25 @@ TEST(InfluxDBFactory, MissingParams) { std::shared_ptr cache; bool is_acceptor; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["db_user"] = "admin"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["db_password"] = "pass"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["db_host"] = "host"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["db_name"] = "centreon"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["db_port"] = "centreon"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["db_port"] = "4242"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["queries_per_transaction"] = "centreon"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["queries_per_transaction"] = "100"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); cfg.params["status_timeseries"] = "host_status"; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); } TEST(InfluxDBFactory, StatusException) { @@ -84,89 +85,61 @@ TEST(InfluxDBFactory, StatusException) { std::unique_ptr ep; ASSERT_NO_THROW(ep.reset(fact.new_endpoint(cfg, is_acceptor, cache))); - json11::Json js1 { - json11::Json::object{ - {"name", json11::Json{nullptr}}, - {"value", json11::Json{nullptr}}, - {"is_tag", json11::Json{nullptr}}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js1{json11::Json::object{{"name", json11::Json{nullptr}}, + {"value", json11::Json{nullptr}}, + {"is_tag", json11::Json{nullptr}}, + {"type", json11::Json{nullptr}}, }}; conf["status_column"] = js1; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js2 { - json11::Json::object{ - {"name", "host"}, - {"value", json11::Json{nullptr}}, - {"is_tag", json11::Json{nullptr}}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js2{json11::Json::object{{"name", "host"}, + {"value", json11::Json{nullptr}}, + {"is_tag", json11::Json{nullptr}}, + {"type", json11::Json{nullptr}}, }}; conf["status_column"] = js2; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js3 { - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", json11::Json{nullptr}}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js3{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", json11::Json{nullptr}}, + {"type", json11::Json{nullptr}}, }}; conf["status_column"] = js3; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js4{ - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", "true"}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js4{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", "true"}, + {"type", json11::Json{nullptr}}, }}; conf["status_column"] = js4; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js5{ - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", "true"}, - {"type", "bad"}, - } - }; + json11::Json js5{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", "true"}, + {"type", "bad"}, }}; conf["status_column"] = js5; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js6{ - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", "true"}, - {"type", "number"}, - } - }; + json11::Json js6{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", "true"}, + {"type", "number"}, }}; conf["status_column"] = js6; cfg.cfg = json11::Json{conf}; ASSERT_NO_THROW(delete fact.new_endpoint(cfg, is_acceptor, cache)); - json11::Json js7{ - json11::Json::object{ - {"name", ""}, - {"value", "val"}, - {"is_tag", "true"}, - {"type", "number"}, - } - }; + json11::Json js7{json11::Json::object{{"name", ""}, + {"value", "val"}, + {"is_tag", "true"}, + {"type", "number"}, }}; conf["status_column"] = js7; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); json11::Json::array array; array.push_back(js6); @@ -200,89 +173,61 @@ TEST(InfluxDBFactory, MetricException) { std::unique_ptr ep; ASSERT_NO_THROW(ep.reset(fact.new_endpoint(cfg, is_acceptor, cache))); - json11::Json js1 { - json11::Json::object{ - {"name", json11::Json{nullptr}}, - {"value", json11::Json{nullptr}}, - {"is_tag", json11::Json{nullptr}}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js1{json11::Json::object{{"name", json11::Json{nullptr}}, + {"value", json11::Json{nullptr}}, + {"is_tag", json11::Json{nullptr}}, + {"type", json11::Json{nullptr}}, }}; conf["metrics_column"] = js1; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js2 { - json11::Json::object{ - {"name", "host"}, - {"value", json11::Json{nullptr}}, - {"is_tag", json11::Json{nullptr}}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js2{json11::Json::object{{"name", "host"}, + {"value", json11::Json{nullptr}}, + {"is_tag", json11::Json{nullptr}}, + {"type", json11::Json{nullptr}}, }}; conf["metrics_column"] = js2; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js3 { - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", json11::Json{nullptr}}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js3{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", json11::Json{nullptr}}, + {"type", json11::Json{nullptr}}, }}; conf["metrics_column"] = js3; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js4{ - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", "true"}, - {"type", json11::Json{nullptr}}, - } - }; + json11::Json js4{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", "true"}, + {"type", json11::Json{nullptr}}, }}; conf["metrics_column"] = js4; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js5{ - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", "true"}, - {"type", "bad"}, - } - }; + json11::Json js5{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", "true"}, + {"type", "bad"}, }}; conf["metrics_column"] = js5; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); - json11::Json js6{ - json11::Json::object{ - {"name", "host"}, - {"value", "val"}, - {"is_tag", "true"}, - {"type", "number"}, - } - }; + json11::Json js6{json11::Json::object{{"name", "host"}, + {"value", "val"}, + {"is_tag", "true"}, + {"type", "number"}, }}; conf["metrics_column"] = js6; cfg.cfg = json11::Json{conf}; ASSERT_NO_THROW(delete fact.new_endpoint(cfg, is_acceptor, cache)); - json11::Json js7{ - json11::Json::object{ - {"name", ""}, - {"value", "val"}, - {"is_tag", "false"}, - {"type", "number"}, - } - }; + json11::Json js7{json11::Json::object{{"name", ""}, + {"value", "val"}, + {"is_tag", "false"}, + {"type", "number"}, }}; conf["metrics_column"] = js7; cfg.cfg = json11::Json{conf}; - ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), exceptions::msg); + ASSERT_THROW(fact.new_endpoint(cfg, is_acceptor, cache), msg_fmt); json11::Json::array array; array.push_back(js6); diff --git a/tests/broker/influxdb/influxdb12.cc b/tests/broker/influxdb/influxdb12.cc index 211afc7a1a1..610f0da5b4c 100644 --- a/tests/broker/influxdb/influxdb12.cc +++ b/tests/broker/influxdb/influxdb12.cc @@ -19,10 +19,11 @@ #include "com/centreon/broker/influxdb/influxdb12.hh" #include -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/broker/logging/manager.hh" #include "../test_server.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; class InfluxDB12 : public testing::Test { @@ -49,9 +50,17 @@ TEST_F(InfluxDB12, BadConnection) { std::vector mcolumns; std::vector scolumns; - ASSERT_THROW(influxdb::influxdb12 idb - ("centreon", "pass", "localhost", 4243, "centreon", "host_status", scolumns, "host_metrics", mcolumns, mcache), - exceptions::msg); + ASSERT_THROW(influxdb::influxdb12 idb("centreon", + "pass", + "localhost", + 4243, + "centreon", + "host_status", + scolumns, + "host_metrics", + mcolumns, + mcache), + msg_fmt); } TEST_F(InfluxDB12, Empty) { @@ -61,8 +70,16 @@ TEST_F(InfluxDB12, Empty) { std::vector mcolumns; std::vector scolumns; - influxdb::influxdb12 idb - ("centreon", "pass", "localhost", 4242, "centreon", "host_status", scolumns, "host_metrics", mcolumns, mcache); + influxdb::influxdb12 idb("centreon", + "pass", + "localhost", + 4242, + "centreon", + "host_status", + scolumns, + "host_metrics", + mcolumns, + mcache); idb.clear(); ASSERT_NO_THROW(idb.commit()); } @@ -73,19 +90,35 @@ TEST_F(InfluxDB12, Simple) { storage::metric m1, m2, m3; std::vector mcolumns; - mcolumns.push_back(influxdb::column{"mhost1", "42.0", true, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"mhost2", "42.0", false, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"most2", "42.0", false, influxdb::column::string}); - mcolumns.push_back(influxdb::column{"most3", "43.0", true, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"mhost1", "42.0", true, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"mhost2", "42.0", false, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"most2", "42.0", false, influxdb::column::string}); + mcolumns.push_back( + influxdb::column{"most3", "43.0", true, influxdb::column::number}); std::vector scolumns; - mcolumns.push_back(influxdb::column{"shost1", "42.0", true, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"shost2", "42.0", false, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"shost2", "42.0", false, influxdb::column::string}); - mcolumns.push_back(influxdb::column{"shost3", "43.0", true, influxdb::column::number}); - - influxdb::influxdb12 idb - ("centreon", "pass", "localhost", 4242, "centreon", "host_status", scolumns, "host_metrics", mcolumns, mcache); + mcolumns.push_back( + influxdb::column{"shost1", "42.0", true, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"shost2", "42.0", false, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"shost2", "42.0", false, influxdb::column::string}); + mcolumns.push_back( + influxdb::column{"shost3", "43.0", true, influxdb::column::number}); + + influxdb::influxdb12 idb("centreon", + "pass", + "localhost", + 4242, + "centreon", + "host_status", + scolumns, + "host_metrics", + mcolumns, + mcache); m1.ctime = 2000llu; m1.interval = 60; m1.is_for_rebuild = true; @@ -133,8 +166,16 @@ TEST_F(InfluxDB12, BadServerResponse1) { std::vector mcolumns; std::vector scolumns; - influxdb::influxdb12 idb - ("centreon", "fail1", "localhost", 4242, "centreon", "host_status", scolumns, "host_metrics", mcolumns, mcache); + influxdb::influxdb12 idb("centreon", + "fail1", + "localhost", + 4242, + "centreon", + "host_status", + scolumns, + "host_metrics", + mcolumns, + mcache); m1.ctime = 2000llu; m1.interval = 60; @@ -173,7 +214,7 @@ TEST_F(InfluxDB12, BadServerResponse1) { idb.write(m2); idb.write(m3); - ASSERT_THROW(idb.commit(), exceptions::msg); + ASSERT_THROW(idb.commit(), msg_fmt); } TEST_F(InfluxDB12, BadServerResponse2) { @@ -182,19 +223,35 @@ TEST_F(InfluxDB12, BadServerResponse2) { storage::metric m1, m2, m3; std::vector mcolumns; - mcolumns.push_back(influxdb::column{"mhost1", "42.0", true, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"mhost2", "42.0", false, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"most2", "42.0", false, influxdb::column::string}); - mcolumns.push_back(influxdb::column{"most3", "43.0", true, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"mhost1", "42.0", true, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"mhost2", "42.0", false, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"most2", "42.0", false, influxdb::column::string}); + mcolumns.push_back( + influxdb::column{"most3", "43.0", true, influxdb::column::number}); std::vector scolumns; - mcolumns.push_back(influxdb::column{"shost1", "42.0", true, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"shost2", "42.0", false, influxdb::column::number}); - mcolumns.push_back(influxdb::column{"shost2", "42.0", false, influxdb::column::string}); - mcolumns.push_back(influxdb::column{"shost3", "43.0", true, influxdb::column::number}); - - influxdb::influxdb12 idb - ("centreon", "fail2", "localhost", 4242, "centreon", "host_status", scolumns, "host_metrics", mcolumns, mcache); + mcolumns.push_back( + influxdb::column{"shost1", "42.0", true, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"shost2", "42.0", false, influxdb::column::number}); + mcolumns.push_back( + influxdb::column{"shost2", "42.0", false, influxdb::column::string}); + mcolumns.push_back( + influxdb::column{"shost3", "43.0", true, influxdb::column::number}); + + influxdb::influxdb12 idb("centreon", + "fail2", + "localhost", + 4242, + "centreon", + "host_status", + scolumns, + "host_metrics", + mcolumns, + mcache); m1.ctime = 2000llu; m1.interval = 60; @@ -233,6 +290,5 @@ TEST_F(InfluxDB12, BadServerResponse2) { idb.write(m2); idb.write(m3); - ASSERT_THROW(idb.commit(), exceptions::msg); + ASSERT_THROW(idb.commit(), msg_fmt); } - diff --git a/tests/broker/influxdb/line_protocol_query.cc b/tests/broker/influxdb/line_protocol_query.cc index 533370941f0..c420ea2d207 100644 --- a/tests/broker/influxdb/line_protocol_query.cc +++ b/tests/broker/influxdb/line_protocol_query.cc @@ -19,8 +19,9 @@ #include "com/centreon/broker/influxdb/line_protocol_query.hh" #include -#include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; TEST(InfluxDBLineProtoQuery, EscapeKey) { @@ -55,8 +56,8 @@ TEST(InfluxDBLineProtoQuery, GenerateMetricExcept) { "test", columns, influxdb::line_protocol_query::metric, cache); storage::metric m1; - ASSERT_THROW(lpq1.generate_metric(m1), exceptions::msg); - ASSERT_THROW(lpq2.generate_metric(m1), exceptions::msg); + ASSERT_THROW(lpq1.generate_metric(m1), msg_fmt); + ASSERT_THROW(lpq2.generate_metric(m1), msg_fmt); ASSERT_NO_THROW(lpq3.generate_metric(m1)); } @@ -206,56 +207,59 @@ TEST(InfluxDBLineProtoQuery, Except) { storage::status s; storage::metric m; - influxdb::line_protocol_query q{"test .", columns, - influxdb::line_protocol_query::metric, cache}; + influxdb::line_protocol_query q{ + "test .", columns, influxdb::line_protocol_query::metric, cache}; influxdb::line_protocol_query q2{ "test .", columns, influxdb::line_protocol_query::status, cache}; try { - influxdb::line_protocol_query q3{"test . $METRICID$", columns, - influxdb::line_protocol_query::status, - cache}; + influxdb::line_protocol_query q3{ + "test . $METRICID$", columns, + influxdb::line_protocol_query::status, cache}; ASSERT_TRUE(false); - } catch (exceptions::msg const& ex) { + } + catch (msg_fmt const& ex) { ASSERT_TRUE(true); } try { - influxdb::line_protocol_query q3{"test . $METRIC$", columns, - influxdb::line_protocol_query::status, - cache}; + influxdb::line_protocol_query q3{ + "test . $METRIC$", columns, + influxdb::line_protocol_query::status, cache}; ASSERT_TRUE(false); - } catch (exceptions::msg const& ex) { + } + catch (msg_fmt const& ex) { ASSERT_TRUE(true); } try { - influxdb::line_protocol_query q3{"test . $METRIC", columns, - influxdb::line_protocol_query::status, - cache}; + influxdb::line_protocol_query q3{ + "test . $METRIC", columns, + influxdb::line_protocol_query::status, cache}; ASSERT_TRUE(false); - } catch (exceptions::msg const& ex) { + } + catch (msg_fmt const& ex) { ASSERT_TRUE(true); } m.metric_id = 3; m.name = "A"; - influxdb::line_protocol_query q4{"test . $METRICID$ $METRIC$", columns, - influxdb::line_protocol_query::metric, - cache}; + influxdb::line_protocol_query q4{ + "test . $METRICID$ $METRIC$", columns, + influxdb::line_protocol_query::metric, cache}; - ASSERT_THROW(q.generate_status(s), exceptions::msg); - ASSERT_THROW(q2.generate_metric(m), exceptions::msg); + ASSERT_THROW(q.generate_status(s), msg_fmt); + ASSERT_THROW(q2.generate_metric(m), msg_fmt); ASSERT_EQ(q4.generate_metric(m), "test\\ .\\ 3\\ A 0\n"); - influxdb::line_protocol_query q5{"test . $INSTANCE$", columns, - influxdb::line_protocol_query::metric, - cache}; + influxdb::line_protocol_query q5{ + "test . $INSTANCE$", columns, + influxdb::line_protocol_query::metric, cache}; ASSERT_EQ(q5.generate_metric(m), ""); - influxdb::line_protocol_query q6{"test . $INSTANCE$", columns, - influxdb::line_protocol_query::status, - cache}; + influxdb::line_protocol_query q6{ + "test . $INSTANCE$", columns, + influxdb::line_protocol_query::status, cache}; ASSERT_EQ(q6.generate_status(s), ""); } \ No newline at end of file diff --git a/tests/broker/influxdb/stream.cc b/tests/broker/influxdb/stream.cc index 56b11d7988c..6639dd2d686 100644 --- a/tests/broker/influxdb/stream.cc +++ b/tests/broker/influxdb/stream.cc @@ -21,9 +21,11 @@ #include #include #include "com/centreon/broker/exceptions/msg.hh" +#include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/broker/logging/manager.hh" #include "../test_server.hh" +using namespace com::centreon::exceptions; using namespace com::centreon::broker; class InfluxDBStream : public testing::Test { @@ -49,7 +51,18 @@ TEST_F(InfluxDBStream, BadPort) { std::vector mcolumns; std::vector scolumns; - ASSERT_THROW(influxdb::stream st("centreon", "pass", "localhost", 4243, "centreon", 3, "host_status", scolumns, "host_metrics", mcolumns, cache), exceptions::msg); + ASSERT_THROW(influxdb::stream st("centreon", + "pass", + "localhost", + 4243, + "centreon", + 3, + "host_status", + scolumns, + "host_metrics", + mcolumns, + cache), + msg_fmt); } TEST_F(InfluxDBStream, Read) { @@ -58,18 +71,38 @@ TEST_F(InfluxDBStream, Read) { std::vector mcolumns; std::vector scolumns; std::shared_ptr data; - influxdb::stream st("centreon", "pass", "localhost", 4242, "centreon", 3, "host_status", scolumns, "host_metrics", mcolumns, cache); + influxdb::stream st("centreon", + "pass", + "localhost", + 4242, + "centreon", + 3, + "host_status", + scolumns, + "host_metrics", + mcolumns, + cache); ASSERT_THROW(st.read(data, -1), exceptions::msg); } TEST_F(InfluxDBStream, Write) { std::shared_ptr cache; - storage::metric *m1, *m2, *m3; + storage::metric* m1, *m2, *m3; std::vector mcolumns; std::vector scolumns; std::shared_ptr data; - influxdb::stream st("centreon", "pass", "localhost", 4242, "centreon", 3, "host_status", scolumns, "host_metrics", mcolumns, cache); + influxdb::stream st("centreon", + "pass", + "localhost", + 4242, + "centreon", + 3, + "host_status", + scolumns, + "host_metrics", + mcolumns, + cache); m1 = new storage::metric; m2 = new storage::metric; @@ -121,11 +154,21 @@ TEST_F(InfluxDBStream, Write) { TEST_F(InfluxDBStream, Flush) { std::shared_ptr cache; - storage::metric *m1, *m2, *m3; + storage::metric* m1, *m2, *m3; std::vector mcolumns; std::vector scolumns; std::shared_ptr data; - influxdb::stream st("centreon", "pass", "localhost", 4242, "centreon", 9, "host_status", scolumns, "host_metrics", mcolumns, cache); + influxdb::stream st("centreon", + "pass", + "localhost", + 4242, + "centreon", + 9, + "host_status", + scolumns, + "host_metrics", + mcolumns, + cache); m1 = new storage::metric; m2 = new storage::metric; @@ -201,7 +244,7 @@ TEST_F(InfluxDBStream, NullData) { TEST_F(InfluxDBStream, FlushStatusOK) { std::shared_ptr cache; - storage::status *s1, *s2, *s3; + storage::status* s1, *s2, *s3; std::vector mcolumns; std::vector scolumns; std::shared_ptr data; @@ -272,7 +315,17 @@ TEST_F(InfluxDBStream, StatsAndConnector) { std::vector scolumns; std::shared_ptr data; influxdb::connector con; - con.connect_to("centreon", "pass", "localhost", 4242, "centreon", 3, "host_status", scolumns, "host_metrics", mcolumns, cache); + con.connect_to("centreon", + "pass", + "localhost", + 4242, + "centreon", + 3, + "host_status", + scolumns, + "host_metrics", + mcolumns, + cache); json11::Json::object obj; con.open()->statistics(obj);