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

Replacing msg in ccb core #41

Merged
merged 10 commits into from
Jul 6, 2020
4 changes: 2 additions & 2 deletions include/com/centreon/broker/compression/stream.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ namespace compression {
*/
class stream : public io::stream {
public:
static int const max_data_size = 100000000;
static int const max_data_size;

stream(int level = -1, size_t size = 0);
stream(stream const& other);
~stream();
stream& operator=(stream const& other);
int flush();
bool read(std::shared_ptr<io::data>& d, time_t deadline = (time_t)-1);
bool read(std::shared_ptr<io::data>& d, time_t deadline = (time_t) - 1);
void statistics(json11::Json::object& tree) const;
int write(std::shared_ptr<io::data> const& d);

Expand Down
10 changes: 6 additions & 4 deletions src/70-graphite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
####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 @@ -17,9 +19,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 Down
7 changes: 2 additions & 5 deletions src/ccb_core/bbdo/acceptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "com/centreon/broker/bbdo/internal.hh"
#include "com/centreon/broker/bbdo/stream.hh"
#include "com/centreon/broker/bbdo/version_response.hh"
#include "com/centreon/broker/exceptions/msg.hh"
#include "com/centreon/broker/io/events.hh"
#include "com/centreon/broker/io/protocols.hh"
#include "com/centreon/broker/logging/logging.hh"
Expand Down Expand Up @@ -68,7 +67,7 @@ acceptor::acceptor(std::string const& name,
_one_peer_retention_mode(one_peer_retention_mode),
_timeout(timeout),
_ack_limit(ack_limit) {
if ((_timeout == (time_t)-1) || (_timeout == 0))
if ((_timeout == (time_t) - 1) || (_timeout == 0))
_timeout = 3;
}

Expand All @@ -90,9 +89,7 @@ acceptor::acceptor(acceptor const& other)
/**
* Destructor.
*/
acceptor::~acceptor() {
_from.reset();
}
acceptor::~acceptor() { _from.reset(); }

/**
* Assignment operator.
Expand Down
3 changes: 1 addition & 2 deletions src/ccb_core/bbdo/connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "com/centreon/broker/bbdo/internal.hh"
#include "com/centreon/broker/bbdo/stream.hh"
#include "com/centreon/broker/bbdo/version_response.hh"
#include "com/centreon/broker/exceptions/msg.hh"
#include "com/centreon/broker/io/events.hh"
#include "com/centreon/broker/io/protocols.hh"
#include "com/centreon/broker/logging/logging.hh"
Expand Down Expand Up @@ -58,7 +57,7 @@ connector::connector(bool negotiate,
_negotiate{negotiate},
_timeout{timeout},
_ack_limit{ack_limit} {
if (_timeout == (time_t)-1 || _timeout == 0)
if (_timeout == (time_t) - 1 || _timeout == 0)
_timeout = 3;
}

Expand Down
148 changes: 87 additions & 61 deletions src/ccb_core/bbdo/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "com/centreon/broker/bbdo/ack.hh"
#include "com/centreon/broker/bbdo/internal.hh"
#include "com/centreon/broker/bbdo/version_response.hh"
#include "com/centreon/broker/exceptions/msg.hh"
#include "com/centreon/exceptions/msg_fmt.hh"
#include "com/centreon/broker/exceptions/timeout.hh"
#include "com/centreon/broker/io/events.hh"
#include "com/centreon/broker/io/raw.hh"
Expand All @@ -37,6 +37,7 @@
#include "com/centreon/broker/mapping/entry.hh"
#include "com/centreon/broker/misc/misc.hh"

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

Expand All @@ -57,8 +58,7 @@ static uint32_t set_boolean(io::data& t,
log_v2::bbdo()->error(
"BBDO: cannot extract boolean value: 0 bytes left in "
"packet");
throw exceptions::msg() << "BBDO: cannot extract boolean value: "
<< "0 bytes left in packet";
throw msg_fmt("BBDO: cannot extract boolean value: 0 bytes left in packet");
}
member.set_bool(t, *static_cast<char const*>(data));
return 1;
Expand All @@ -78,9 +78,10 @@ static uint32_t set_double(io::data& t,
"BBDO: cannot extract double value: not terminating '\0' in remaining "
Copy link
Collaborator

@bouda1 bouda1 Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think \\0 would be better than \0

"{} bytes of packet",
size);
throw exceptions::msg() << "BBDO: cannot extract double value: "
<< "not terminating '\0' in remaining " << size
<< " bytes of packet";
throw msg_fmt(
"BBDO: cannot extract double value: not terminating '\0' in remaining "
Copy link
Collaborator

@bouda1 bouda1 Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\\0 and not \0

"{} bytes of packet",
size);
}
member.set_double(t, strtod(str, nullptr));
return len + 1;
Expand All @@ -96,8 +97,8 @@ static uint32_t set_integer(io::data& t,
if (size < sizeof(uint32_t)) {
log_v2::bbdo()->error(
"BBDO: cannot extract integer value: {} bytes left in packet", size);
throw exceptions::msg() << "BBDO: cannot extract integer value: " << size
<< " bytes left in packet";
throw msg_fmt("BBDO: cannot extract integer value: {} bytes left in packet",
size);
}
member.set_int(t, ntohl(*static_cast<uint32_t const*>(data)));
return sizeof(uint32_t);
Expand All @@ -113,8 +114,8 @@ static uint32_t set_short(io::data& t,
if (size < sizeof(uint16_t)) {
log_v2::bbdo()->error(
"BBDO: cannot extract short value: {} bytes left in packet", size);
throw exceptions::msg() << "BBDO: cannot extract short value: " << size
<< " bytes left in packet";
throw msg_fmt("BBDO: cannot extract short value: {} bytes left in packet",
size);
}
member.set_short(t, ntohs(*static_cast<uint16_t const*>(data)));
return sizeof(uint16_t);
Expand All @@ -131,13 +132,14 @@ static uint32_t set_string(io::data& t,
uint32_t len(strlen(str));
if (len >= size) {
log_v2::bbdo()->error(
"BBDO: cannot extract string value: no terminating '\\0' in remaining "
"BBDO: cannot extract string value: no terminating '\0' in remaining "
Copy link
Collaborator

@bouda1 bouda1 Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted you to make the reverse: keep '\\0' and not '\0'

"{} bytes left in packet",
size);

throw exceptions::msg() << "BBDO: cannot extract string value: "
<< "no terminating '\\0' in remaining " << size
<< " bytes of packet";
throw msg_fmt(
"BBDO: cannot extract string value: no terminating '\0' in remaining "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

"{} bytes of packet",
size);
}
member.set_string(t, str);
return len + 1;
Expand All @@ -153,8 +155,8 @@ static uint32_t set_timestamp(io::data& t,
if (size < 2 * sizeof(uint32_t)) {
log_v2::bbdo()->error(
"BBDO: cannot extract timestamp value: {} bytes left in packet", size);
throw exceptions::msg() << "BBDO: cannot extract timestamp value: " << size
<< " bytes left in packet";
throw msg_fmt(
"BBDO: cannot extract timestamp value: {} bytes left in packet", size);
}
uint32_t const* ptr(static_cast<uint32_t const*>(data));
uint64_t val(ntohl(*ptr));
Expand All @@ -176,8 +178,9 @@ static uint32_t set_uint(io::data& t,
log_v2::bbdo()->error(
"BBDO: cannot extract uint32_t integer value: {} bytes left in packet",
size);
throw exceptions::msg() << "BBDO: cannot extract uint32_teger value: "
<< size << " bytes left in packet";
throw msg_fmt(
"BBDO: cannot extract uint32_teger value: {} bytes left in packet",
size);
}
member.set_uint(t, ntohl(*static_cast<uint32_t const*>(data)));
return sizeof(uint32_t);
Expand Down Expand Up @@ -209,7 +212,8 @@ static io::data* unserialize(uint32_t event_type,
t->destination_id = destination_id;
// Browse all mapping to unserialize the object.
for (mapping::entry const* current_entry(info->get_mapping());
!current_entry->is_null(); ++current_entry)
!current_entry->is_null();
++current_entry)
// Skip entries that should not be serialized.
if (current_entry->get_serialize()) {
uint32_t rb;
Expand Down Expand Up @@ -239,11 +243,13 @@ static io::data* unserialize(uint32_t event_type,
log_v2::bbdo()->error(
"BBDO: invalid mapping for object of type '{0}': {1} is not "
"a known type ID",
info->get_name(), current_entry->get_type());
throw exceptions::msg() << "BBDO: invalid mapping for "
<< "object of type '" << info->get_name()
<< "': " << current_entry->get_type()
<< " is not a known type ID";
info->get_name(),
current_entry->get_type());
throw msg_fmt(
"BBDO: invalid mapping for object of type '{}': {} is not a "
"known type ID",
info->get_name(),
current_entry->get_type());
}
buffer += rb;
size -= rb;
Expand All @@ -253,9 +259,9 @@ static io::data* unserialize(uint32_t event_type,
log_v2::bbdo()->error(
"BBDO: cannot create object of ID {} whereas it has been registered",
event_type);
throw exceptions::msg()
<< "BBDO: cannot create object of ID " << event_type
<< " whereas it has been registered";
throw msg_fmt(
"BBDO: cannot create object of ID {} whereas it has been registered",
event_type);
}
} else {
log_v2::bbdo()->info(
Expand Down Expand Up @@ -335,32 +341,47 @@ bool input::read(std::shared_ptr<io::data>& d, time_t deadline) {
"BBDO: peer is using protocol version {0}.{1}.{2} , whereas we're "
"using protocol version "
"{3}.{4}.{5}",
version->bbdo_major, version->bbdo_minor, version->bbdo_patch,
BBDO_VERSION_MAJOR, BBDO_VERSION_MINOR, BBDO_VERSION_PATCH);
throw exceptions::msg()
<< "BBDO: peer is using protocol version " << version->bbdo_major
<< "." << version->bbdo_minor << "." << version->bbdo_patch
<< " whereas we're using protocol version " << BBDO_VERSION_MAJOR
<< "." << BBDO_VERSION_MINOR << "." << BBDO_VERSION_PATCH;
version->bbdo_major,
version->bbdo_minor,
version->bbdo_patch,
BBDO_VERSION_MAJOR,
BBDO_VERSION_MINOR,
BBDO_VERSION_PATCH);
throw msg_fmt(
"BBDO: peer is using protocol version {}.{}.{} whereas we're using "
"protocol version {}.{}.{}",
version->bbdo_major,
version->bbdo_minor,
version->bbdo_patch,
BBDO_VERSION_MAJOR,
BBDO_VERSION_MINOR,
BBDO_VERSION_PATCH);
}
log_v2::bbdo()->info(
"BBDO: peer is using protocol version {0}.{1}.{2} , we're using version "
"BBDO: peer is using protocol version {0}.{1}.{2} , we're using "
"version "
"{3}.{4}.{5}",
version->bbdo_major, version->bbdo_minor, version->bbdo_patch,
BBDO_VERSION_MAJOR, BBDO_VERSION_MINOR, BBDO_VERSION_PATCH);
logging::info(logging::medium)
<< "BBDO: peer is using protocol version " << version->bbdo_major
<< "." << version->bbdo_minor << "." << version->bbdo_patch
<< ", we're using version " << BBDO_VERSION_MAJOR << "."
<< BBDO_VERSION_MINOR << "." << BBDO_VERSION_PATCH;
version->bbdo_major,
version->bbdo_minor,
version->bbdo_patch,
BBDO_VERSION_MAJOR,
BBDO_VERSION_MINOR,
BBDO_VERSION_PATCH);
logging::info(logging::medium) << "BBDO: peer is using protocol version "
<< version->bbdo_major << "."
<< version->bbdo_minor << "."
<< version->bbdo_patch
<< ", we're using version "
<< BBDO_VERSION_MAJOR << "."
<< BBDO_VERSION_MINOR << "."
<< BBDO_VERSION_PATCH;
} else if ((event_id & 0xFFFF) == 2) {
log_v2::bbdo()->info(
"BBDO: received acknowledgement for {} events",
std::static_pointer_cast<ack const>(d)->acknowledged_events);
logging::info(logging::medium)
<< "BBDO: received acknowledgement for "
<< std::static_pointer_cast<ack const>(d)->acknowledged_events
<< " events";
logging::info(logging::medium) << "BBDO: received acknowledgement for "
<< std::static_pointer_cast<ack const>(d)
->acknowledged_events << " events";
acknowledge_events(
std::static_pointer_cast<ack const>(d)->acknowledged_events);
}
Expand Down Expand Up @@ -434,13 +455,15 @@ bool input::read_any(std::shared_ptr<io::data>& d, time_t deadline) {
source_id != current_source_id || destination_id != current_dest_id) {
if (!_skipped) { // First corrupted byte.
log_v2::bbdo()->error(
"BBDO: peer {0} is sending corrupted data: {1}", peer(),
"BBDO: peer {0} is sending corrupted data: {1}",
peer(),
((chksum != expected) ? "invalid CRC"
: "invalid multi-packet event"));
logging::error(logging::high)
<< "BBDO: peer " << peer() << " is sending corrupted data: "
<< ((chksum != expected) ? "invalid CRC"
: "invalid multi-packet event");
logging::error(logging::high) << "BBDO: peer " << peer()
<< " is sending corrupted data: "
<< ((chksum != expected)
? "invalid CRC"
: "invalid multi-packet event");
}
++_skipped;
_buffer.erase(1);
Expand All @@ -463,39 +486,42 @@ bool input::read_any(std::shared_ptr<io::data>& d, time_t deadline) {
log_v2::bbdo()->info(
"BBDO: peer {0} sent {1} corrupted payload bytes, resuming "
"processing",
peer(), _skipped);
peer(),
_skipped);
logging::info(logging::high)
<< "BBDO: peer " << peer() << " sent " << _skipped
<< " corrupted payload bytes, resuming processing";
_skipped = 0;
}

// Unserialize event.
d.reset(unserialize(event_id, source_id, destination_id, packet.data(),
packet.size()));
d.reset(unserialize(
event_id, source_id, destination_id, packet.data(), packet.size()));
if (d) {
log_v2::bbdo()->debug(
"BBDO: unserialized {0} bytes for event of type {1}", raw_size,
"BBDO: unserialized {0} bytes for event of type {1}",
raw_size,
event_id);
logging::debug(logging::medium)
<< "BBDO: unserialized " << raw_size << " bytes for event of type "
<< event_id;
logging::debug(logging::medium) << "BBDO: unserialized " << raw_size
<< " bytes for event of type "
<< event_id;
} else {
log_v2::bbdo()->error(
"BBDO: unknown event type {} event cannot be decoded", event_id);
log_v2::bbdo()->debug("BBDO: discarded {} bytes", raw_size);

logging::error(logging::medium) << "BBDO: unknown event type " << event_id
<< ": event cannot be decoded";
logging::debug(logging::medium)
<< "BBDO: discarded " << raw_size << " bytes";
logging::debug(logging::medium) << "BBDO: discarded " << raw_size
<< " bytes";
}

// Mark data as processed.
_buffer.erase(raw_size);

return true;
} catch (exceptions::timeout const& e) {
}
catch (exceptions::timeout const& e) {
(void)e;
return false;
}
Expand Down
Loading