Skip to content

Commit

Permalink
enh(bbdo/downtime): Convert downtime to pb (#395)
Browse files Browse the repository at this point in the history
* enh(conan): conanfile updated to match packages requirements on openssl
* fix(broker): stats engine was subject to deadlocks (#391)

* fix(broker/bam): downtimes migrated to pb_downtimes
* enh(tests): attempt to improve rrd tests
* fix(broker): refacto of bbdo files

REFS: MON-15225 MON-15226
  • Loading branch information
bouda1 authored Oct 11, 2022
1 parent 8ebfd17 commit 501fedc
Show file tree
Hide file tree
Showing 47 changed files with 2,095 additions and 2,747 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test-coverage
test/python/*.crt
test/python/*.key
ut
tests/failed
###
apps/
build/*
Expand Down
12 changes: 0 additions & 12 deletions bbdo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,6 @@ macro(get_protobuf_files name)
"${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.h")
endmacro()

macro(get_protobuf_accessor name)
set(proto_file "${name}.proto")
set(full_proto_file "${CMAKE_SOURCE_DIR}/bbdo/${name}.proto")
add_custom_command(OUTPUT "${CMAKE_SOURCE_DIR}/bbdo/${name}_accessor.hh"
DEPENDS ${full_proto_file}
COMMENT "Generating accessor to protobuf message ${proto_file}"
COMMAND python3
ARGS ${full_proto_file}
VERBATIM
)
endmacro()

include_directories("${CMAKE_SOURCE_DIR}/broker/core/inc")

add_library(
Expand Down
2 changes: 1 addition & 1 deletion bbdo/events.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ enum data_element {
de_pb_severity = 33,
de_pb_tag = 34,
de_pb_comment = 35,
de_pb_downtime = 36,
de_pb_custom_variable = 37,
de_pb_custom_variable_status = 38,

};
} // namespace neb
namespace storage {
Expand Down
124 changes: 77 additions & 47 deletions bbdo/neb_proto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,91 @@ package com.centreon.broker;


message Comment {
BBDOHeader header = 1;
BBDOHeader header = 1;

enum Src {
INTERNAL = 0;
EXTERNAL = 1;
}
enum Src {
INTERNAL = 0;
EXTERNAL = 1;
}

enum Type {
NO_TYPE = 0;
HOST = 1;
SERVICE = 2;
}
enum Type {
NO_TYPE = 0;
HOST = 1;
SERVICE = 2;
}

enum EntryType {
NO_ENTRY_TYPE = 0;
USER = 1;
DOWNTIME = 2;
FLAPPING = 3;
ACKNOWLEDGMENT = 4;
}
enum EntryType {
NO_ENTRY_TYPE = 0;
USER = 1;
DOWNTIME = 2;
FLAPPING = 3;
ACKNOWLEDGMENT = 4;
}

string author = 2;
Type type = 3;
string data = 4;
uint64 deletion_time = 5;
uint64 entry_time = 6;
EntryType entry_type = 7;
uint64 expire_time = 8;
bool expires = 9;
uint64 host_id = 10;
uint64 internal_id = 11;
bool persistent = 12;
uint64 instance_id = 13;
uint64 service_id = 14;
Src source = 15;

string author = 2;
Type type = 3;
string data = 4;
uint64 deletion_time = 5;
uint64 entry_time = 6;
EntryType entry_type = 7;
uint64 expire_time = 8;
bool expires = 9;
uint64 host_id = 10;
uint64 internal_id = 11;
bool persistent = 12;
uint64 instance_id = 13;
uint64 service_id = 14;
Src source = 15;
}

/**
* @brief A downtime is applied on a resource when we don't want notifications
* concerning bad states on this resource.
*/
message Downtime {
enum DowntimeType {
NOT_USED = 0;
SERVICE = 1;
HOST = 2;
ANY = 3;
};
uint64 id = 1;
uint64 instance_id = 2;
uint64 host_id = 3;
uint64 service_id = 4;
string author = 5;
string comment_data = 6;
DowntimeType type = 7;
uint32 duration = 8;
uint64 triggered_by = 9;
int64 entry_time = 10;
uint64 actual_start_time = 11;
uint64 actual_end_time = 12;
uint64 start_time = 13;
uint64 deletion_time = 14;
uint64 end_time = 15;
bool started = 16;
bool cancelled = 17;
bool fixed = 18;
}

message CustomVariable {
enum VarType {
HOST = 0;
SERVICE = 1;
}
enum VarType {
HOST = 0;
SERVICE = 1;
}

BBDOHeader header = 1;
uint64 host_id = 2;
uint64 service_id = 3;
bool modified = 4;
string name = 5;
uint64 update_time = 6;
string value = 7;
string default_value = 8;
bool enabled = 9;
bool password = 10;
VarType var_type = 11;
BBDOHeader header = 1;
uint64 host_id = 2;
uint64 service_id = 3;
bool modified = 4;
string name = 5;
uint64 update_time = 6;
string value = 7;
string default_value = 8;
bool enabled = 9;
bool password = 10;
VarType var_type = 11;
}


2 changes: 2 additions & 0 deletions broker/bam/inc/com/centreon/broker/bam/ba.hh
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class ba : public computable, public service_listener {
void visit(io::stream* visitor);
void service_update(std::shared_ptr<neb::downtime> const& dt,
io::stream* visitor) override;
void service_update(std::shared_ptr<neb::pb_downtime> const& dt,
io::stream* visitor) override;
void save_inherited_downtime(persistent_cache& cache) const;
void set_inherited_downtime(inherited_downtime const& dwn);
void set_level_critical(double level);
Expand Down
12 changes: 7 additions & 5 deletions broker/bam/inc/com/centreon/broker/bam/kpi_service.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright 2014-2015, 2021 Centreon
** Copyright 2014-2015, 2021-2022 Centreon
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,13 +80,15 @@ class kpi_service : public service_listener, public kpi {
bool in_downtime() const;
bool is_acknowledged() const;
void service_update(std::shared_ptr<neb::service_status> const& status,
io::stream* visitor = nullptr);
io::stream* visitor = nullptr) override;
void service_update(const std::shared_ptr<neb::pb_service_status>& status,
io::stream* visitor = nullptr);
io::stream* visitor = nullptr) override;
void service_update(std::shared_ptr<neb::acknowledgement> const& ack,
io::stream* visitor = nullptr);
io::stream* visitor = nullptr) override;
void service_update(std::shared_ptr<neb::downtime> const& dt,
io::stream* visitor = nullptr);
io::stream* visitor = nullptr) override;
void service_update(const std::shared_ptr<neb::pb_downtime>& dt,
io::stream* visitor = nullptr) override;
void set_acknowledged(bool acknowledged);
void set_downtimed(bool downtimed);
void set_impact_critical(double impact);
Expand Down
2 changes: 2 additions & 0 deletions broker/bam/inc/com/centreon/broker/bam/service_book.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class service_book {
io::stream* visitor = nullptr);
void update(const std::shared_ptr<neb::downtime>& t,
io::stream* visitor = nullptr);
void update(const std::shared_ptr<neb::pb_downtime>& t,
io::stream* visitor = nullptr);
void update(const std::shared_ptr<neb::service_status>& t,
io::stream* visitor = nullptr);
void update(const std::shared_ptr<neb::pb_service>& t,
Expand Down
2 changes: 2 additions & 0 deletions broker/bam/inc/com/centreon/broker/bam/service_listener.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class service_listener {
io::stream* visitor = nullptr);
virtual void service_update(std::shared_ptr<neb::downtime> const& dt,
io::stream* visitor = nullptr);
virtual void service_update(const std::shared_ptr<neb::pb_downtime>& dt,
io::stream* visitor = nullptr);
};
} // namespace bam

Expand Down
40 changes: 40 additions & 0 deletions broker/bam/src/ba.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ double ba::_normalize(double d) {
return d;
};

static bool time_is_undefined(uint64_t t) {
return t == 0 || t == static_cast<uint64_t>(-1);
}

/**
* Constructor.
*
Expand Down Expand Up @@ -375,6 +379,42 @@ void ba::service_update(const std::shared_ptr<neb::downtime>& dt,
_id, _name, dt->host_id, dt->service_id, _host_id, _service_id);
}

/**
* @brief Notify BA of a downtime (protobuf)
*
* Used to watch for downtime.
*
* @param dt Downtime of the service.
* @param visitor Visitor that will receive events.
*/
void ba::service_update(const std::shared_ptr<neb::pb_downtime>& dt,
io::stream* visitor) {
(void)visitor;
auto& downtime = dt->obj();
assert(downtime.host_id() == _host_id &&
downtime.service_id() == _service_id);

// Log message.
log_v2::bam()->debug(
"BAM: BA {} '{}' is getting notified of a downtime (pb) on its service "
"({}, {})",
_id, _name, _host_id, _service_id);

// Check if there was a change.
bool in_downtime(downtime.started() &&
time_is_undefined(downtime.actual_end_time()));
if (_in_downtime != in_downtime) {
log_v2::bam()->trace("ba: service_update downtime: {}", _in_downtime);
_in_downtime = in_downtime;

// Generate status event.
visit(visitor);

// Propagate change.
propagate_update(visitor);
}
}

/**
* Save the inherited downtime to the cache.
*
Expand Down
10 changes: 6 additions & 4 deletions broker/bam/src/kpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "com/centreon/broker/bam/kpi.hh"

#include "com/centreon/broker/bam/ba.hh"
#include "com/centreon/broker/log_v2.hh"

using namespace com::centreon::broker;
using namespace com::centreon::broker::bam;
Expand Down Expand Up @@ -63,6 +64,7 @@ timestamp kpi::get_last_state_change() const {
* @param[in] e The kpi event.
*/
void kpi::set_initial_event(const kpi_event& e) {
log_v2::bam()->trace("bam: kpi::set_initial_event");
if (!_event) {
_event = std::make_shared<kpi_event>(e);
impact_values impacts;
Expand All @@ -74,13 +76,13 @@ void kpi::set_initial_event(const kpi_event& e) {
if (std::abs(new_impact_level - _event->impact_level) >= eps &&
_event->impact_level != -1) {
time_t now = ::time(nullptr);
std::shared_ptr<kpi_event> new_event = std::make_shared<kpi_event>(e);
auto new_event = std::make_shared<kpi_event>(e);
new_event->end_time = now;
_initial_events.push_back(new_event);
new_event = std::make_shared<kpi_event>(e);
new_event->start_time = now;
_initial_events.push_back(new_event);
_event = new_event;
_event = std::move(new_event);
} else
_initial_events.push_back(_event);
;
Expand All @@ -99,8 +101,8 @@ void kpi::commit_initial_events(io::stream* visitor) {

if (visitor) {
for (std::vector<std::shared_ptr<kpi_event> >::const_iterator
it(_initial_events.begin()),
end(_initial_events.end());
it = _initial_events.begin(),
end = _initial_events.end();
it != end; ++it)
visitor->write(std::make_shared<kpi_event>(**it));
}
Expand Down
Loading

0 comments on commit 501fedc

Please sign in to comment.