diff --git a/engine/inc/com/centreon/engine/string.hh b/engine/inc/com/centreon/engine/string.hh index 89c9bb5df44..7a47803cd05 100644 --- a/engine/inc/com/centreon/engine/string.hh +++ b/engine/inc/com/centreon/engine/string.hh @@ -29,7 +29,6 @@ #include #include - namespace com::centreon::engine { namespace string { @@ -205,6 +204,8 @@ std::string& remove_thresholds(std::string& perfdata) noexcept; void unescape(char* buffer); +void unescape(std::string& str); + /** * @brief this class is a thread safe replacement for my_strtok * An instance is not thread safe but sevaral instances can be used in different @@ -226,6 +227,6 @@ class c_strtok { } // namespace string -} +} // namespace com::centreon::engine #endif // !CCE_MISC_STRING_HH diff --git a/engine/src/command_manager.cc b/engine/src/command_manager.cc index 1718b63442e..665fa498a71 100644 --- a/engine/src/command_manager.cc +++ b/engine/src/command_manager.cc @@ -137,6 +137,12 @@ int command_manager::process_passive_service_check( if (!found->second->passive_checks_enabled()) return ERROR; + SPDLOG_LOGGER_DEBUG(runtime_logger, + "process_passive_service_check check_time={}, " + "host_name={}, service={}, return_code={}, output={}", + check_time, host_name, svc_description, return_code, + output); + timeval tv; gettimeofday(&tv, nullptr); diff --git a/engine/src/commands/commands.cc b/engine/src/commands/commands.cc index ec6e7d53d1a..234d437038a 100644 --- a/engine/src/commands/commands.cc +++ b/engine/src/commands/commands.cc @@ -571,8 +571,8 @@ int cmd_process_service_check_result(int cmd [[maybe_unused]], ++ait; // replace \\n with \n - std::string output; - absl::CUnescape(*ait, &output); + std::string output(ait->data(), ait->size()); + string::unescape(output); timeval tv; gettimeofday(&tv, nullptr); diff --git a/engine/src/string.cc b/engine/src/string.cc index 595ecb98b3a..b4cc09d9773 100644 --- a/engine/src/string.cc +++ b/engine/src/string.cc @@ -449,3 +449,16 @@ void string::unescape(char* buffer) { *buffer = 0; } } + +/** + * @brief * @brief Unescape the string buffer. Works with \t, \n, \r and \\. + * The buffer is directly changed. No copy is made. + * + * @param str in out modified string + */ +void string::unescape(std::string& str) { + boost::replace_all(str, "\\n", "\n"); + boost::replace_all(str, "\\r", "\r"); + boost::replace_all(str, "\\t", "\t"); + boost::replace_all(str, "\\\\", "\\"); +} diff --git a/tests/broker-engine/external-commands2.robot b/tests/broker-engine/external-commands2.robot index 65c6b7dc848..90d67fbcaec 100644 --- a/tests/broker-engine/external-commands2.robot +++ b/tests/broker-engine/external-commands2.robot @@ -1412,3 +1412,42 @@ BEHOSTCHECK Ctn Schedule Forced Host Check host_1 ${result} Ctn Check Host Check With Timeout host_1 30 ${VarRoot}/lib/centreon-engine/check.pl --id 0 Should Be True ${result} hosts table not updated + + +BE_BACKSLASH_CHECK_RESULT + [Documentation] external command PROCESS_SERVICE_CHECK_RESULT with \: + [Tags] broker engine services extcmd MON-51121 + Ctn Config Engine ${1} ${50} ${20} + Ctn Set Services Passive ${0} service_.* + Ctn Config Broker rrd + Ctn Config Broker central + Ctn Config Broker module ${1} + Ctn ConfigBBDO3 1 + Ctn Config Broker Sql Output central unified_sql + Ctn Clear Retention + Ctn Broker Config Log central sql debug + FOR ${use_grpc} IN RANGE 0 2 + Log To Console external command PROCESS_SERVICE_CHECK_RESULT use_grpc=${use_grpc} + Ctn Clear Retention + ${start} Get Current Date + Ctn Start Broker + Ctn Start engine + Ctn Wait For Engine To Be Ready ${start} ${1} + + ${start} Ctn Get Round Current Date + Ctn Process Service Check Result host_1 service_1 0 output ok D: \\: Total: 1.205TB - Used: 1.203TB (100%) - Free: 2.541GB (0%) ${use_grpc} config0 ${use_grpc} + + ${result} Ctn Check Service Output Resource Status With Timeout + ... host_1 + ... service_1 + ... 35 + ... ${start} + ... 0 + ... HARD + ... output ok D: \\: Total: 1.205TB - Used: 1.203TB (100%) - Free: 2.541GB (0%) ${use_grpc} + Should Be True ${result} resources table not updated + + + Ctn Stop engine + Ctn Kindly Stop Broker + END diff --git a/tests/resources/Engine.py b/tests/resources/Engine.py index e0562834e47..9d601ff85c6 100755 --- a/tests/resources/Engine.py +++ b/tests/resources/Engine.py @@ -2823,6 +2823,8 @@ def ctn_process_service_check_result(hst: str, svc: str, state: int, output: str 0 on success. """ if use_grpc > 0: + ts = Timestamp() + ts.GetCurrentTime() port = 50001 + int(config[6:]) with grpc.insecure_channel(f"127.0.0.1:{port}") as channel: stub = engine_pb2_grpc.EngineStub(channel) @@ -2830,10 +2832,10 @@ def ctn_process_service_check_result(hst: str, svc: str, state: int, output: str for i in range(nb_check): indexed_output = f"{output}_{i}" stub.ProcessServiceCheckResult(engine_pb2.Check( - host_name=hst, svc_desc=svc, output=indexed_output, code=state)) + host_name=hst, svc_desc=svc, check_time=ts, output=indexed_output, code=state)) else: stub.ProcessServiceCheckResult(engine_pb2.Check( - host_name=hst, svc_desc=svc, output=output, code=state)) + host_name=hst, svc_desc=svc, check_time=ts, output=output, code=state)) else: now = int(time.time())