Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(graphite) : replacing msg by msg_fmt #27

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/70-graphite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
##
## Copyright 2013 Centreon
##
## Licensed under the Apache License, Version 2.0 (the "License");
####Copyright 2013 Centreon####Licensed under the Apache License,
Version 2.0(the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
Expand All @@ -19,9 +17,9 @@ include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CONAN_INCLUDE_DIRS_JSON11})
include_directories(${CONAN_INCLUDE_DIRS_SPDLOG})

# TLS module.
#TLS module.
add_library(70-graphite SHARED
# Sources
#Sources
${CMAKE_SOURCE_DIR}/src/70-graphite/connector.cc
${CMAKE_SOURCE_DIR}/src/70-graphite/factory.cc
${CMAKE_SOURCE_DIR}/src/70-graphite/macro_cache.cc
Expand All @@ -30,5 +28,5 @@ add_library(70-graphite SHARED
${CMAKE_SOURCE_DIR}/src/70-graphite/stream.cc
)
set_target_properties(70-graphite PROPERTIES PREFIX "")
target_link_libraries(70-graphite CONAN_PKG::asio)
target_link_libraries(70-graphite CONAN_PKG::asio CONAN_PKG::fmt)
install(TARGETS 70-graphite DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/centreon/lib/centreon-broker)
36 changes: 22 additions & 14 deletions src/70-graphite/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include <memory>
#include <sstream>
#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/graphite/connector.hh"

using namespace com::centreon::exceptions;
using namespace com::centreon::broker;
using namespace com::centreon::broker::graphite;

Expand All @@ -45,8 +46,7 @@ static std::string find_param(config::endpoint const& cfg,
std::string const& key) {
std::map<std::string, std::string>::const_iterator it{cfg.params.find(key)};
if (cfg.params.end() == it)
throw exceptions::msg() << "graphite: no '" << key
<< "' defined for endpoint '" << cfg.name << "'";
throw msg_fmt("graphite: no '{}' defined for endpoint '{}'", key, cfg.name);
return it->second;
}

Expand Down Expand Up @@ -79,17 +79,18 @@ static std::string get_string_param(config::endpoint const& cfg,
* @return Property value.
*/
static uint32_t get_uint_param(config::endpoint const& cfg,
std::string const& key,
uint32_t def) {
std::string const& key,
uint32_t def) {
std::map<std::string, std::string>::const_iterator it(cfg.params.find(key));
if (cfg.params.end() == it)
return (def);
else {
try {
return std::stoul(it->second);
} catch (std::exception const& ex) {
throw exceptions::msg() << "graphite: '" << key
<< "' must be numeric for endpoint '" << cfg.name << "'";
}
catch (std::exception const& ex) {
throw msg_fmt(
"graphite: '{}' must be numeric for endpoint '{}'", key, cfg.name);
}
}

Expand Down Expand Up @@ -127,10 +128,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<persistent_cache> cache) const {
io::endpoint* factory::new_endpoint(config::endpoint& cfg,
bool& is_acceptor,
std::shared_ptr<persistent_cache> cache)
const {
std::string db_host(find_param(cfg, "db_host"));
unsigned short db_port(get_uint_param(cfg, "db_port", 2003));
std::string db_user(get_string_param(cfg, "db_user", ""));
Expand All @@ -145,8 +146,15 @@ io::endpoint* factory::new_endpoint(

// Connector.
std::unique_ptr<graphite::connector> c(new graphite::connector);
c->connect_to(metric_naming, status_naming, escape_string, db_user,
db_password, db_host, db_port, queries_per_transaction, cache);
c->connect_to(metric_naming,
status_naming,
escape_string,
db_user,
db_password,
db_host,
db_port,
queries_per_transaction,
cache);
is_acceptor = false;
return (c.release());
}
30 changes: 15 additions & 15 deletions src/70-graphite/macro_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/

#include "com/centreon/broker/graphite/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::graphite;

Expand All @@ -46,7 +47,8 @@ macro_cache::~macro_cache() {
if (_cache != nullptr) {
try {
_save_to_disk();
} catch (std::exception const& e) {
}
catch (std::exception const& e) {
logging::error(logging::medium)
<< "graphite: macro cache couldn't save data to disk: '" << e.what()
<< "'";
Expand All @@ -61,12 +63,12 @@ macro_cache::~macro_cache() {
*
* @return The status mapping.
*/
storage::index_mapping const& macro_cache::get_index_mapping(
uint64_t index_id) const {
storage::index_mapping const& macro_cache::get_index_mapping(uint64_t index_id)
const {
auto found = _index_mappings.find(index_id);
if (found == _index_mappings.end())
throw exceptions::msg()
<< "graphite: could not find host/service of index " << index_id;
throw msg_fmt("graphite: could not find host/service of index {}",
index_id);
return *found->second;
}

Expand All @@ -81,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() << "graphite: could not find index of metric "
<< metric_id;
throw msg_fmt("graphite: could not find index of metric {}", metric_id);
return *found->second;
}

Expand All @@ -96,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() << "graphite: could not find information on host "
<< host_id;
throw msg_fmt("graphite: could not find information on host {}", host_id);
return found->second->host_name;
}

Expand All @@ -114,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()
<< "graphite: could not find information on service (" << host_id
<< ", " << service_id << ")";
throw msg_fmt("graphite: could not find information on service ({},{})",
host_id,
service_id);
return found->second->service_description;
}

Expand All @@ -130,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()
<< "graphite: could not find information on instance " << instance_id;
throw msg_fmt("graphite: could not find information on instance {}",
instance_id);
return found->second->name;
}

Expand Down
Loading