Skip to content

Commit

Permalink
fix(broker): issue with fmt and timestamp fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
bouda1 committed Feb 7, 2024
1 parent 24ad6da commit 3cec71c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
13 changes: 5 additions & 8 deletions broker/bam/src/kpi_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ void kpi_service::service_update(
log_v2::bam()->debug(
"BAM: KPI {} is getting an acknowledgement event for service ({}, {}) "
"entry_time {} ; deletion_time {}",
_id, _host_id, _service_id, ack->entry_time.get_time_t(),
ack->deletion_time.get_time_t());
_id, _host_id, _service_id, ack->entry_time, ack->deletion_time);

bool changed = false;
// Update information.
Expand Down Expand Up @@ -418,15 +417,14 @@ void kpi_service::service_update(const std::shared_ptr<neb::downtime>& dt,
if (!_event || _event->in_downtime() != _downtimed) {
_last_check = _downtimed ? dt->actual_start_time : dt->actual_end_time;
log_v2::bam()->trace("kpi service {} update, last check set to {}", _id,
_last_check.get_time_t());
_last_check);
}

// Log message.
log_v2::bam()->debug(
"BAM: KPI {} is getting notified of a downtime ({}) on its service ({}, "
"{}), in downtime: {} at {}",
_id, dt->internal_id, _host_id, _service_id, _downtimed,
_last_check.get_time_t());
_id, dt->internal_id, _host_id, _service_id, _downtimed, _last_check);

// Generate status event.
visit(visitor);
Expand Down Expand Up @@ -479,15 +477,14 @@ void kpi_service::service_update(const std::shared_ptr<neb::pb_downtime>& dt,
_last_check =
_downtimed ? downtime.actual_start_time() : downtime.actual_end_time();
log_v2::bam()->trace("kpi service {} update, last check set to {}", _id,
_last_check.get_time_t());
_last_check);
}

// Log message.
log_v2::bam()->debug(
"BAM: KPI {} is getting notified of a downtime ({}) on its service ({}, "
"{}), in downtime: {} at {}",
_id, downtime.id(), _host_id, _service_id, _downtimed,
_last_check.get_time_t());
_id, downtime.id(), _host_id, _service_id, _downtimed, _last_check);

// Generate status event.
visit(visitor);
Expand Down
6 changes: 2 additions & 4 deletions broker/bam/src/reporting_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,10 @@ struct kpi_event_update_binder {
if (event->type() == bam::kpi_event::static_type()) {
bam::kpi_event const& ke =
*std::static_pointer_cast<bam::kpi_event const>(event);
std::string sz_ke_time = ke.end_time.is_null()
? "NULL"
: std::to_string(ke.end_time.get_time_t());
std::string sz_ke_time{fmt::format("{}", ke.end_time)};
return fmt::format("({},{},{},{},{},{})", sz_ke_time, ke.status,
int(ke.in_downtime), ke.impact_level, ke.kpi_id,
ke.start_time.get_time_t());
ke.start_time);
} else {
const KpiEvent& ke =
std::static_pointer_cast<bam::pb_kpi_event const>(event)->obj();
Expand Down
18 changes: 18 additions & 0 deletions broker/core/inc/com/centreon/broker/timestamp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef CCB_TIMESTAMP_HH
#define CCB_TIMESTAMP_HH

#include <fmt/format.h>
#include <istream>

namespace com::centreon::broker {
Expand Down Expand Up @@ -169,4 +170,21 @@ inline time_t format_as(const timestamp& o) {

} // namespace com::centreon::broker

namespace fmt {
template <>
struct formatter<com::centreon::broker::timestamp> {
constexpr auto parse(format_parse_context& ctx)
-> format_parse_context::iterator {
return ctx.begin();
}

auto format(const com::centreon::broker::timestamp& t,
format_context& ctx) const -> format_context::iterator {
// ctx.out() is an output iterator to write to.
return t.is_null() ? fmt::format_to(ctx.out(), "NULL")
: fmt::format_to(ctx.out(), "{}", t.get_time_t());
}
};
} // namespace fmt

#endif // !CCB_TIMESTAMP_HH
16 changes: 1 addition & 15 deletions broker/unified_sql/inc/com/centreon/broker/unified_sql/stream.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,8 @@ struct uint64_not_null {

} // namespace unified_sql
} // namespace com::centreon::broker
namespace fmt {
template <>
struct formatter<com::centreon::broker::timestamp> {
constexpr auto parse(format_parse_context& ctx)
-> format_parse_context::iterator {
return ctx.begin();
}

auto format(const com::centreon::broker::timestamp& t,
format_context& ctx) const -> format_context::iterator {
// ctx.out() is an output iterator to write to.
return t.is_null() ? fmt::format_to(ctx.out(), "NULL")
: fmt::format_to(ctx.out(), "{}", t.get_time_t());
}
};

namespace fmt {
template <>
struct formatter<com::centreon::broker::unified_sql::int64_not_minus_one> {
constexpr auto parse(format_parse_context& ctx)
Expand Down

0 comments on commit 3cec71c

Please sign in to comment.