Skip to content

Commit

Permalink
enh(log_v2): new test check all log are duplicate in tables logs
Browse files Browse the repository at this point in the history
REFS: MON-11866
  • Loading branch information
rem31 committed Jan 13, 2022
1 parent 3555dee commit 363d29f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
12 changes: 9 additions & 3 deletions centreon-engine/inc/com/centreon/engine/logging/broker_sink.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <mutex>
#include "com/centreon/engine/broker.hh"
#include "com/centreon/engine/logging/broker.hh"
#include "com/centreon/engine/logging/logger.hh"
#include "com/centreon/engine/namespace.hh"
#include "com/centreon/engine/nebstructs.hh"
#include "com/centreon/unique_array_ptr.hh"
Expand All @@ -40,9 +41,14 @@ class broker_sink : public spdlog::sinks::base_sink<Mutex> {
// If needed (very likely but not mandatory), the sink formats the message
// before sending it to its final destination:
if (this->should_log(msg.level)) {
nebstruct_log_data ds;
ds.entry_time = time(nullptr);
ds.data = msg.payload.data();
std::string message{fmt::to_string(msg.payload)};
nebstruct_log_data ds{.type = NEBTYPE_LOG_DATA,
.flags = NEBFLAG_NONE,
.attr = NEBATTR_NONE,
.timestamp = get_broker_timestamp(nullptr),
.entry_time = time(nullptr),
.data_type = logging::log_all,
.data = message.c_str()};

// Make callbacks.
neb_make_callbacks(NEBCALLBACK_LOG_DATA, &ds);
Expand Down
5 changes: 3 additions & 2 deletions centreon-engine/src/log_v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ void log_v2::apply(const configuration::state& config) {
if (config.log_file() != "")
sinks.push_back(
std::make_shared<sinks::basic_file_sink_mt>(config.log_file()));
else
else {
log_v2::config()->error("log_file name is empty");
sinks.push_back(std::make_shared<sinks::stdout_sink_mt>());
sinks.push_back(std::make_shared<sinks::stdout_sink_mt>());
}
} else if (config.log_v2_logger() == "syslog")
sinks.push_back(std::make_shared<sinks::syslog_sink_mt>("centreon-engine",
0, 0, true));
Expand Down
38 changes: 35 additions & 3 deletions centreon-tests/broker-engine/log-v2_engine.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Suite Setup Clean Before Suite
Suite Teardown Clean After Suite
Test Setup Stop Processes

Documentation Centreon Broker and Engine add Hostgroup
Documentation Centreon Broker and Engine log_v2
Library DatabaseLibrary
Library Process
Library OperatingSystem
Expand Down Expand Up @@ -41,7 +41,7 @@ LOGV2EB1
${result1}= Find In Log With Timeout ${log} ${start} ${content} 15
Should Be True ${result1}

Sleep 5s
Sleep 10s

Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}
Log To Console after connection
Expand Down Expand Up @@ -156,7 +156,7 @@ LOGV2EB2
Should Be True ${result1}
Should Be True ${result2}

Sleep 10s
Sleep 20s

Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}
Log To Console after connection
Expand Down Expand Up @@ -272,6 +272,38 @@ LOGV2EF2
Stop Engine
Stop Broker

LOGV2BE2
[Documentation] log-v2 enabled hold log enabled check broker sink is equal
[Tags] Broker Engine log-v2 sinkbroker
Config Engine ${1}
Config Broker rrd
Config Broker central
Config Broker module
Engine Config Set Value ${0} log_legacy_enabled ${1}
Engine Config Set Value ${0} log_v2_enabled ${1}

${start}= Get Current Date UTC exclude_millis=yes
${time_stamp} Convert Date ${start} epoch exclude_millis=yes
${time_stamp2} evaluate int(${time_stamp})
log to console ${time_stamp2}
Start Broker
Start Engine
${result}= Check Connections
Should Be True ${result} msg=Engine and Broker not connected

Sleep 3m

Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}
Log To Console after connection
@{output}= Query select count(*) as c, output from logs where ctime>=${time_stamp2} group by output having c<>2

${res}= engine log duplicate ${output}
Should Be True ${res} msg=one or other log are not duplicate in tables logs

Stop Engine
Stop Broker


*** Variables ***
${DBName} centreon_storage
${DBHost} localhost
Expand Down
7 changes: 7 additions & 0 deletions centreon-tests/resources/Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,10 @@ def add_host_group(index: int, members: list):
logger.console(mbs)
f.write(engine.create_host_group(mbs))
f.close()

def engine_log_duplicate(result: list):
dup = True
for i in result:
if (i[0] % 2) != 0:
dup = False
return dup

0 comments on commit 363d29f

Please sign in to comment.