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

fix(broker): logs concerning acknowledgements did not appear in database #2139

Merged
merged 1 commit into from
Feb 21, 2025
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
2 changes: 1 addition & 1 deletion broker/neb/src/set_log_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ bool neb::set_pb_log_data(neb::pb_log_entry& le, const std::string& output) {
le_obj.set_output(ait->data(), ait->size());
} else if (typ == "EXTERNAL COMMAND") {
test_fail("acknowledge type");
auto& data = *ait;
std::string_view data = *ait;
++ait;
if (data == "ACKNOWLEDGE_SVC_PROBLEM") {
le_obj.set_msg_type(LogEntry_MsgType_SERVICE_ACKNOWLEDGE_PROBLEM);
Expand Down
36 changes: 18 additions & 18 deletions engine/inc/com/centreon/engine/logging/broker_sink.hh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
** Copyright 2011-2021 Centreon
**
** This file is part of Centreon Engine.
**
** Centreon Engine is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License version 2
** as published by the Free Software Foundation.
**
** Centreon Engine is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Centreon Engine. If not, see
** <http://www.gnu.org/licenses/>.
*/
/**
* Copyright 2011-2025 Centreon
*
* This file is part of Centreon Engine.
*
* Centreon Engine is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* Centreon Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Centreon Engine. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef CCE_LOGGING_BROKER_SINK_HH
#define CCE_LOGGING_BROKER_SINK_HH
#include <spdlog/details/fmt_helper.h>
Expand Down
17 changes: 16 additions & 1 deletion tests/broker-engine/acknowledgement.robot
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ Test Teardown Ctn Save Logs If Failed

*** Test Cases ***
BEACK1
[Documentation] Engine has a critical service. An external command is sent to acknowledge it. The centreon_storage.acknowledgements table is then updated with this acknowledgement. The service is newly set to OK. And the acknowledgement in database is deleted from engine but still open on the database.
[Documentation] Scenario: Acknowledging a critical service
... Given Engine has a critical service
... When an external command is sent to acknowledge it
... Then the "centreon_storage.acknowledgements" table is updated with this acknowledgement
... And a log in "centreon_storage.logs" concerning this acknowledgement is added.
... When the service is set to OK
... Then the acknowledgement is deleted from the Engine
... But it remains open in the database

[Tags] broker engine services extcmd
Ctn Config Engine ${1} ${50} ${20}
Ctn Config Broker rrd
Expand All @@ -45,11 +53,18 @@ BEACK1

${result} Ctn Check Service Status With Timeout host_1 service_1 ${2} 60 HARD
Should Be True ${result} Service (1;1) should be critical HARD
${start} Ctn Get Round Current Date
${d} Get Current Date result_format=epoch exclude_millis=True
Ctn Acknowledge Service Problem host_1 service_1
${ack_id} Ctn Check Acknowledgement With Timeout host_1 service_1 ${d} 2 60 HARD
Should Be True ${ack_id} > 0 No acknowledgement on service (1, 1).

${result} Ctn Check Acknowledgement In Logs Table ${start}
Should Be True ${result} Acknowledgement should be in logs table.

# The service command is set to OK to also control active checks
Ctn Set Command Status ${cmd_id} ${0}

# Service_1 is set back to OK.
Ctn Process Service Result Hard host_1 service_1 0 (1;1) is OK
${result} Ctn Check Service Status With Timeout host_1 service_1 ${0} 60 HARD
Expand Down
32 changes: 32 additions & 0 deletions tests/resources/Broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2831,3 +2831,35 @@ def ctn_init_data_bin_without_partition():
) ENGINE=InnoDB DEFAULT CHARSET=latin1"""
cursor.execute(sql)
connection.commit()


def ctn_check_acknowledgement_in_logs_table(date: int, timeout: int = TIMEOUT):
"""
Check if a row exists in the logs table with msg_type=10 and ctime >= date.

Args:
date: The date to check.
timeout: A timeout in seconds, 30s by default.

Returns:
True on success.
"""
limit = time.time() + timeout
while time.time() < limit:
connection = pymysql.connect(host=DB_HOST,
user=DB_USER,
password=DB_PASS,
database=DB_NAME_STORAGE,
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)

with connection:
with connection.cursor() as cursor:
cursor.execute(
f"SELECT * FROM logs WHERE msg_type=10 and ctime >= {date}")
result = cursor.fetchall()
logger.console(result)
if len(result) > 0 and len(result[0]) > 0:
return True
time.sleep(2)
return False