From 6fbf9495102d3b9a21b79de1c6605aa56f8db4a0 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Wed, 15 May 2024 09:57:27 +0200 Subject: [PATCH] enh(broker/lua): lua cache is now updated on service_status/host_status events REFS: MON-60933 --- bbdo/neb.proto | 34 +-- .../com/centreon/broker/lua/macro_cache.hh | 36 +-- broker/lua/src/luabinding.cc | 2 - broker/lua/src/macro_cache.cc | 226 +++++++++++++++--- broker/sql/src/stream.cc | 36 +-- tests/bam/bam_pb.robot | 20 -- tests/broker-engine/lua-cache.robot | 188 +++++++++++++++ tests/resources/Common.py | 2 +- tests/resources/resources.robot | 15 +- 9 files changed, 455 insertions(+), 104 deletions(-) create mode 100644 tests/broker-engine/lua-cache.robot diff --git a/bbdo/neb.proto b/bbdo/neb.proto index 65cfc597b41..a4a74a6f110 100644 --- a/bbdo/neb.proto +++ b/bbdo/neb.proto @@ -1,20 +1,20 @@ -/* -** Copyright 2022 Centreon -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -** -** For more information : contact@centreon.com -*/ +/** + * Copyright 2022-2024 Centreon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + */ syntax = "proto3"; diff --git a/broker/lua/inc/com/centreon/broker/lua/macro_cache.hh b/broker/lua/inc/com/centreon/broker/lua/macro_cache.hh index e22a6d6c3ad..dbd9cd3822a 100644 --- a/broker/lua/inc/com/centreon/broker/lua/macro_cache.hh +++ b/broker/lua/inc/com/centreon/broker/lua/macro_cache.hh @@ -1,20 +1,20 @@ -/* -** Copyright 2018-2022 Centreon -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -** -** For more information : contact@centreon.com -*/ +/** + * Copyright 2018-2024 Centreon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + */ #ifndef CCB_LUA_MACRO_CACHE_HH #define CCB_LUA_MACRO_CACHE_HH @@ -118,6 +118,7 @@ class macro_cache { void _process_pb_instance(std::shared_ptr const& data); void _process_host(std::shared_ptr const& data); void _process_pb_host(std::shared_ptr const& data); + void _process_pb_host_status(std::shared_ptr const& data); void _process_pb_adaptive_host(std::shared_ptr const& data); void _process_host_group(std::shared_ptr const& data); void _process_host_group_member(std::shared_ptr const& data); @@ -125,6 +126,7 @@ class macro_cache { void _process_pb_custom_variable(std::shared_ptr const& data); void _process_service(std::shared_ptr const& data); void _process_pb_service(std::shared_ptr const& data); + void _process_pb_service_status(std::shared_ptr const& data); void _process_pb_adaptive_service(std::shared_ptr const& data); void _process_service_group(std::shared_ptr const& data); void _process_service_group_member(std::shared_ptr const& data); diff --git a/broker/lua/src/luabinding.cc b/broker/lua/src/luabinding.cc index 4f69cdbb9fe..3c561e37b78 100644 --- a/broker/lua/src/luabinding.cc +++ b/broker/lua/src/luabinding.cc @@ -297,8 +297,6 @@ int luabinding::write(std::shared_ptr const& data) noexcept { int retval = 0; if (log_v2::lua()->level() == spdlog::level::trace) { SPDLOG_LOGGER_TRACE(log_v2::lua(), "lua: luabinding::write call {}", *data); - } else { - SPDLOG_LOGGER_DEBUG(log_v2::lua(), "lua: luabinding::write call"); } // Give data to cache. diff --git a/broker/lua/src/macro_cache.cc b/broker/lua/src/macro_cache.cc index 39300d0c08c..53a0bf9cad8 100644 --- a/broker/lua/src/macro_cache.cc +++ b/broker/lua/src/macro_cache.cc @@ -1,20 +1,20 @@ -/* -** Copyright 2017-2022 Centreon -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -** -** For more information : contact@centreon.com -*/ +/** + * Copyright 2017-2024 Centreon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + */ #include "com/centreon/broker/lua/macro_cache.hh" #include "bbdo/bam/dimension_ba_bv_relation_event.hh" @@ -515,6 +515,9 @@ void macro_cache::write(std::shared_ptr const& data) { case neb::pb_host::static_type(): _process_pb_host(data); break; + case neb::pb_host_status::static_type(): + _process_pb_host_status(data); + break; case neb::pb_adaptive_host::static_type(): _process_pb_adaptive_host(data); break; @@ -530,6 +533,9 @@ void macro_cache::write(std::shared_ptr const& data) { case neb::pb_service::static_type(): _process_pb_service(data); break; + case neb::pb_service_status::static_type(): + _process_pb_service_status(data); + break; case neb::pb_adaptive_service::static_type(): _process_pb_adaptive_service(data); break; @@ -633,6 +639,84 @@ void macro_cache::_process_pb_host(std::shared_ptr const& data) { _hosts.erase(h->obj().host_id()); } +void macro_cache::_process_pb_host_status( + const std::shared_ptr& data) { + const auto& s = std::static_pointer_cast(data); + const auto& obj = s->obj(); + + SPDLOG_LOGGER_DEBUG(log_v2::lua(), "lua: processing host status ({})", + obj.host_id()); + + auto it = _hosts.find(obj.host_id()); + if (it == _hosts.end()) { + log_v2::lua()->warn( + "lua: Attempt to update host ({}) in lua cache, but it does not " + "exist. Maybe Engine should be restarted to update the cache.", + obj.host_id()); + return; + } + + if (it->second->type() == make_type(io::neb, neb::de_host)) { + auto& hst = *std::static_pointer_cast(it->second); + hst.has_been_checked = obj.checked(); + hst.check_type = obj.check_type(); + hst.current_state = obj.state(); + hst.state_type = obj.state_type(); + hst.last_state_change = obj.last_state_change(); + hst.last_hard_state = obj.last_hard_state(); + hst.last_hard_state_change = obj.last_hard_state_change(); + hst.last_time_up = obj.last_time_up(); + hst.last_time_down = obj.last_time_down(); + hst.last_time_unreachable = obj.last_time_unreachable(); + hst.output = obj.output(); + hst.perf_data = obj.perfdata(); + hst.is_flapping = obj.flapping(); + hst.percent_state_change = obj.percent_state_change(); + hst.latency = obj.latency(); + hst.execution_time = obj.execution_time(); + hst.last_check = obj.last_check(); + hst.next_check = obj.next_check(); + hst.should_be_scheduled = obj.should_be_scheduled(); + hst.current_check_attempt = obj.check_attempt(); + hst.notification_number = obj.notification_number(); + hst.no_more_notifications = obj.no_more_notifications(); + hst.last_notification = obj.last_notification(); + hst.next_notification = obj.next_host_notification(); + hst.acknowledgement_type = obj.acknowledgement_type(); + hst.downtime_depth = obj.scheduled_downtime_depth(); + } else if (it->second->type() == make_type(io::neb, neb::de_pb_host)) { + auto& hst = std::static_pointer_cast(it->second)->mut_obj(); + hst.set_checked(obj.checked()); + hst.set_check_type(static_cast(obj.check_type())); + hst.set_state(static_cast(obj.state())); + hst.set_state_type(static_cast(obj.state_type())); + hst.set_last_state_change(obj.last_state_change()); + hst.set_last_hard_state(static_cast(obj.last_hard_state())); + hst.set_last_hard_state_change(obj.last_hard_state_change()); + hst.set_last_time_up(obj.last_time_up()); + hst.set_last_time_down(obj.last_time_down()); + hst.set_last_time_unreachable(obj.last_time_unreachable()); + hst.set_output(obj.output()); + hst.set_perfdata(obj.perfdata()); + hst.set_flapping(obj.flapping()); + hst.set_percent_state_change(obj.percent_state_change()); + hst.set_latency(obj.latency()); + hst.set_execution_time(obj.execution_time()); + hst.set_last_check(obj.last_check()); + hst.set_next_check(obj.next_check()); + hst.set_should_be_scheduled(obj.should_be_scheduled()); + hst.set_check_attempt(obj.check_attempt()); + hst.set_notification_number(obj.notification_number()); + hst.set_no_more_notifications(obj.no_more_notifications()); + hst.set_last_notification(obj.last_notification()); + hst.set_next_host_notification(obj.next_host_notification()); + hst.set_acknowledgement_type(obj.acknowledgement_type()); + hst.set_scheduled_downtime_depth(obj.scheduled_downtime_depth()); + } else { + log_v2::lua()->error("lua: The host ({}) stored in cache is corrupted", + obj.host_id()); + } +} /** * Process a pb adaptive host event. * @@ -727,10 +811,12 @@ void macro_cache::_process_pb_adaptive_host( void macro_cache::_process_host_group(std::shared_ptr const& data) { std::shared_ptr const& hg = std::static_pointer_cast(data); - SPDLOG_LOGGER_DEBUG(log_v2::lua(), "lua: processing host group '{}' of id {}", - hg->name, hg->id); + SPDLOG_LOGGER_DEBUG(log_v2::lua(), + "lua: processing host group '{}' of id {} enabled: {}", + hg->name, hg->id, hg->enabled); if (hg->enabled) _host_groups[hg->id] = hg; + // erasure is desactivated because a group cen be owned by several pollers } /** @@ -785,6 +871,89 @@ void macro_cache::_process_pb_service(std::shared_ptr const& data) { _services.erase({s->obj().host_id(), s->obj().service_id()}); } +void macro_cache::_process_pb_service_status( + const std::shared_ptr& data) { + const auto& s = std::static_pointer_cast(data); + const auto& obj = s->obj(); + + SPDLOG_LOGGER_DEBUG(log_v2::lua(), "lua: processing service status ({}, {})", + obj.host_id(), obj.service_id()); + + auto it = _services.find({obj.host_id(), obj.service_id()}); + if (it == _services.end()) { + log_v2::lua()->warn( + "lua: Attempt to update service ({}, {}) in lua cache, but it does not " + "exist. Maybe Engine should be restarted to update the cache.", + obj.host_id(), obj.service_id()); + return; + } + + if (it->second->type() == make_type(io::neb, neb::de_service)) { + auto& svc = *std::static_pointer_cast(it->second); + svc.has_been_checked = obj.checked(); + svc.check_type = obj.check_type(); + svc.current_state = obj.state(); + svc.state_type = obj.state_type(); + svc.last_state_change = obj.last_state_change(); + svc.last_hard_state = obj.last_hard_state(); + svc.last_hard_state_change = obj.last_hard_state_change(); + svc.last_time_ok = obj.last_time_ok(); + svc.last_time_warning = obj.last_time_warning(); + svc.last_time_critical = obj.last_time_critical(); + svc.last_time_unknown = obj.last_time_unknown(); + svc.output = obj.output(); + svc.perf_data = obj.perfdata(); + svc.is_flapping = obj.flapping(); + svc.percent_state_change = obj.percent_state_change(); + svc.latency = obj.latency(); + svc.execution_time = obj.execution_time(); + svc.last_check = obj.last_check(); + svc.next_check = obj.next_check(); + svc.should_be_scheduled = obj.should_be_scheduled(); + svc.current_check_attempt = obj.check_attempt(); + svc.notification_number = obj.notification_number(); + svc.no_more_notifications = obj.no_more_notifications(); + svc.last_notification = obj.last_notification(); + svc.next_notification = obj.next_notification(); + svc.acknowledgement_type = obj.acknowledgement_type(); + svc.downtime_depth = obj.scheduled_downtime_depth(); + } else if (it->second->type() == make_type(io::neb, neb::de_pb_service)) { + auto& svc = + std::static_pointer_cast(it->second)->mut_obj(); + svc.set_checked(obj.checked()); + svc.set_check_type(static_cast(obj.check_type())); + svc.set_state(static_cast(obj.state())); + svc.set_state_type(static_cast(obj.state_type())); + svc.set_last_state_change(obj.last_state_change()); + svc.set_last_hard_state(static_cast(obj.last_hard_state())); + svc.set_last_hard_state_change(obj.last_hard_state_change()); + svc.set_last_time_ok(obj.last_time_ok()); + svc.set_last_time_warning(obj.last_time_warning()); + svc.set_last_time_critical(obj.last_time_critical()); + svc.set_last_time_unknown(obj.last_time_unknown()); + svc.set_output(obj.output()); + svc.set_perfdata(obj.perfdata()); + svc.set_flapping(obj.flapping()); + svc.set_percent_state_change(obj.percent_state_change()); + svc.set_latency(obj.latency()); + svc.set_execution_time(obj.execution_time()); + svc.set_last_check(obj.last_check()); + svc.set_next_check(obj.next_check()); + svc.set_should_be_scheduled(obj.should_be_scheduled()); + svc.set_check_attempt(obj.check_attempt()); + svc.set_notification_number(obj.notification_number()); + svc.set_no_more_notifications(obj.no_more_notifications()); + svc.set_last_notification(obj.last_notification()); + svc.set_next_notification(obj.next_notification()); + svc.set_acknowledgement_type(obj.acknowledgement_type()); + svc.set_scheduled_downtime_depth(obj.scheduled_downtime_depth()); + } else { + log_v2::lua()->error( + "lua: The service ({}, {}) stored in cache is corrupted", obj.host_id(), + obj.service_id()); + } +} + /** * Process a pb service event. * @@ -887,6 +1056,7 @@ void macro_cache::_process_service_group( sg->id); if (sg->enabled) _service_groups[sg->id] = sg; + // erasure is desactivated because a group cen be owned by several pollers } /** @@ -1020,10 +1190,10 @@ void macro_cache::_process_dimension_ba_bv_relation_event( } else { auto const& rel = std::static_pointer_cast(data); - SPDLOG_LOGGER_DEBUG( - log_v2::lua(), - "lua: processing dimension ba bv relation event (ba_id: {}, bv_id: {})", - rel->ba_id, rel->bv_id); + SPDLOG_LOGGER_DEBUG(log_v2::lua(), + "lua: processing dimension ba bv relation event " + "(ba_id: {}, bv_id: {})", + rel->ba_id, rel->bv_id); auto pb_data(std::make_shared()); pb_data->mut_obj().set_ba_id(rel->ba_id); pb_data->mut_obj().set_bv_id(rel->bv_id); @@ -1102,11 +1272,11 @@ void macro_cache::_process_custom_variable( std::shared_ptr const& data) { auto const& cv = std::static_pointer_cast(data); if (cv->name == "CRITICALITY_LEVEL") { - SPDLOG_LOGGER_DEBUG( - log_v2::lua(), - "lua: processing custom variable representing a criticality level for " - "host_id {} and service_id {} and level {}", - cv->host_id, cv->service_id, cv->value); + SPDLOG_LOGGER_DEBUG(log_v2::lua(), + "lua: processing custom variable representing a " + "criticality level for " + "host_id {} and service_id {} and level {}", + cv->host_id, cv->service_id, cv->value); int32_t value = std::atoi(cv->value.c_str()); if (value) _custom_vars[{cv->host_id, cv->service_id}] = cv; diff --git a/broker/sql/src/stream.cc b/broker/sql/src/stream.cc index 5ab090229dc..e691d976f06 100644 --- a/broker/sql/src/stream.cc +++ b/broker/sql/src/stream.cc @@ -1,20 +1,20 @@ -/* -** Copyright 2009-2021 Centreon -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -** -** For more information : contact@centreon.com -*/ +/** + * Copyright 2009-2024 Centreon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + */ #include "com/centreon/broker/sql/stream.hh" @@ -58,7 +58,7 @@ stream::stream(database_config const& dbcfg, uint32_t cleanup_check_interval, uint32_t loop_timeout, uint32_t instance_timeout, - bool with_state_events) + bool with_state_events [[maybe_unused]]) : io::stream("SQL"), _mysql(dbcfg), // _cleanup_thread(dbcfg.get_type(), diff --git a/tests/bam/bam_pb.robot b/tests/bam/bam_pb.robot index 9eda36f3980..63f70fb8a48 100644 --- a/tests/bam/bam_pb.robot +++ b/tests/bam/bam_pb.robot @@ -151,11 +151,6 @@ BAWORST2 ${result} Ctn Check Ba Status With Timeout test 0 60 Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} Should Be True ${result} The BA test is not OK as expected - ${result} Ctn Check Ba Output With Timeout - ... test - ... Status is OK - All KPIs are in an OK state - ... 10 - Should Be True ${result} The BA test has not the expected output # boolean critical => ba test critical Ctn Process Service Result Hard @@ -169,11 +164,6 @@ BAWORST2 ${result} Ctn Check Ba Status With Timeout test 2 60 Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} Should Be True ${result} The BA test is not CRITICAL as expected - ${result} Ctn Check Ba Output With Timeout - ... test - ... Status is CRITICAL - At least one KPI is in a CRITICAL state: KPI Boolean rule bool test is in CRITICAL state - ... 10 - Should Be True ${result} The BA test has not the expected output # child ba critical Ctn Process Service Result Hard @@ -190,11 +180,6 @@ BAWORST2 ${result} Ctn Check Ba Status With Timeout test 2 60 Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} Should Be True ${result} The BA test is not CRITICAL as expected - ${result} Ctn Check Ba Output With Timeout - ... test - ... Status is CRITICAL - At least one KPI is in a CRITICAL state: KPI Business Activity test_child is in CRITICAL state, KPI Boolean rule bool test is in CRITICAL state - ... 10 - Should Be True ${result} The BA test has not the expected output # boolean rule ok stay in critical Ctn Process Service Result Hard @@ -208,11 +193,6 @@ BAWORST2 ${result} Ctn Check Ba Status With Timeout test 2 60 Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} Should Be True ${result} The BA test is not CRITICAL as expected - ${result} Ctn Check Ba Output With Timeout - ... test - ... Status is CRITICAL - At least one KPI is in a CRITICAL state: KPI Business Activity test_child is in CRITICAL state - ... 10 - Should Be True ${result} The BA test has not the expected output BABEST_SERVICE_CRITICAL [Documentation] With bbdo version 3.0.1, a BA of type 'best' with 2 serv, ba is critical only if the 2 services are critical diff --git a/tests/broker-engine/lua-cache.robot b/tests/broker-engine/lua-cache.robot new file mode 100644 index 00000000000..27c30747c93 --- /dev/null +++ b/tests/broker-engine/lua-cache.robot @@ -0,0 +1,188 @@ +*** Settings *** +Documentation Centreon Broker and Engine progressively add services + +Resource ../resources/resources.robot +Library ../resources/Broker.py +Library ../resources/Engine.py +Library DateTime + +Suite Setup Ctn Clean Before Suite +Suite Teardown Ctn Clean After Suite +Test Setup Ctn Stop Processes +Test Teardown Ctn Save Logs If Failed + + +*** Test Cases *** +LCDNU + [Documentation] the lua cache updates correctly service cache. + [Tags] broker engine services lua MON-24745 MON-60933 + Ctn Clear Commands Status + Ctn Clear Retention + + Remove File /tmp/test-LUA.log + Ctn Config Engine ${1} ${1} ${1} + Ctn Config Broker central + Ctn Config Broker module + Ctn Config Broker rrd + Ctn Config BBDO3 1 + Ctn Broker Config Log central neb trace + Ctn Broker Config Log central sql error + Ctn Broker Config Log central lua debug + Ctn Config Broker Sql Output central unified_sql + + ${new_content} Catenate SEPARATOR=\n + ... function init(params) + ... broker_log:set_parameters(2, '/tmp/test-LUA.log') + ... broker_log:info(0, 'lua start test') + ... end + ... + ... function write(e) + ... if e._type == 65563 then --Service id + ... broker_log:info(0, 'configuration of ('.. e.host_id.. ','.. e.service_id.. ')') + ... local svc = broker_cache:get_service(e.host_id,e.service_id) + ... broker_log:info(0, broker.json_encode(svc)) + ... end + ... if e._type == 65565 then --service status ID + ... broker_log:info(0, 'Status of ('.. e.host_id.. ','.. e.service_id.. ')') + ... local svc = broker_cache:get_service(e.host_id,e.service_id) + ... local field = {"checked", "check_type", "state", "state_type", "last_state_change", "last_hard_state", "last_hard_state_change", "last_time_ok", "last_time_warning", "last_time_critical", "last_time_unknown", "output", "perfdata", "flapping", "percent_state_change", "latency", "execution_time", "last_check", "next_check", "should_be_scheduled", "check_attempt", "notification_number", "no_more_notifications", "last_notification", "next_notification", "acknowledgement_type", "scheduled_downtime_depth"} + ... local ko = 0 + ... for i, v in ipairs(field) do + ... if svc[v] ~= e[v] then + ... broker_log:info(0, v.." doesn't match (".. svc[v].." ~= ".. e[v]..")") + ... ko = ko + 1 + ... end + ... end + ... if ko == 0 then + ... broker_log:info(0, "Service cache OK") + ... end + ... end + ... return true + ... end + + # Create the initial LUA script file + Create File /tmp/test-LUA.lua ${new_content} + + Ctn Broker Config Add Lua Output central test-LUA /tmp/test-LUA.lua + + ${start} Get Current Date + Ctn Start Broker + Ctn Start Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + + Wait Until Created /tmp/test-LUA.log + FOR ${i} IN RANGE 60 + ${result} Grep File /tmp/test-LUA.log configuration of (1,1) regexp=False + IF len("""${result}""") > 0 BREAK + Sleep 1s + END + Should Not Be Empty ${result} Configuration error + + ## Time to set the service to OK hard + + Ctn Process Service Result Hard host_1 service_1 ${0} The service_1 is OK + + ## check that we check the correct service + FOR ${i} IN RANGE 60 + ${grep_res} Grep File /tmp/test-LUA.log Status of + IF len("""${grep_res}""") > 0 BREAK + Sleep 1s + END + Should Not Be Empty ${result} No message about the service (1,1) status + + FOR ${i} IN RANGE 60 + ${grep_res} Grep File /tmp/test-LUA.log Service cache OK regexp=False + IF len("""${grep_res}""") > 0 BREAK + Sleep 1s + END + Should Not Be Empty ${grep_res} Some checks failed + + Ctn Stop Engine + Ctn Kindly Stop Broker + + +LCDNUH + [Documentation] the lua cache updates correctly host cache + [Tags] broker engine services lua MON-24745 MON-60933 + Ctn Clear Commands Status + Ctn Clear Retention + + Remove File /tmp/test-LUA.log + Ctn Config Engine ${1} ${1} ${1} + Ctn Config Broker central + Ctn Config Broker module + Ctn Config Broker rrd + Ctn Config BBDO3 1 + Ctn Broker Config Log central neb trace + Ctn Broker Config Log central sql error + Ctn Broker Config Log central lua debug + Ctn Config Broker Sql Output central unified_sql + + ${new_content} Catenate SEPARATOR=\n + ... function init(params) + ... broker_log:set_parameters(2, '/tmp/test-LUA.log') + ... broker_log:info(0, 'lua start test') + ... end + ... + ... function write(e) + ... if e._type == 65566 then --Host ID + ... broker_log:info(0, 'configuration of ('.. e.host_id.. ')') + ... end + ... if e._type == 65568 then --Host status ID + ... broker_log:info(0, 'Status of ('.. e.host_id.. ')') + ... local host = broker_cache:get_host(e.host_id) + ... local field = {"checked", "check_type", "state", "state_type", "last_state_change", "last_hard_state", "last_hard_state_change", "last_time_up", "last_time_down", "last_time_unreachable", "output", "perfdata", "flapping", "percent_state_change", "latency", "execution_time", "last_check", "next_check", "should_be_scheduled", "check_attempt", "notification_number", "no_more_notifications", "last_notification", "next_host_notification", "acknowledgement_type", "scheduled_downtime_depth"} + ... local ko = 0 + ... for i, v in ipairs(field) do + ... if host[v] ~= e[v] then + ... broker_log:info(0, v.." doesn't match (".. host[v].." ~= ".. e[v]..")") + ... ko = ko + 1 + ... end + ... end + ... if ko == 0 then + ... broker_log:info(0, "Host cache OK") + ... end + ... end + ... return true + ... end + + # Create the initial LUA script file + Create File /tmp/test-LUA.lua ${new_content} + + Ctn Broker Config Add Lua Output central test-LUA /tmp/test-LUA.lua + + ${start} Get Current Date + Ctn Start Broker + Ctn Start Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + + Wait Until Created /tmp/test-LUA.log + FOR ${i} IN RANGE 60 + ${result} Grep File /tmp/test-LUA.log configuration of (1) regexp=False + IF len("""${result}""") > 0 BREAK + Sleep 1s + END + Should Not Be Empty ${result} Configuration error + + ## Time to set the host to UP hard + + FOR ${i} IN RANGE ${3} + Ctn Process Host Check Result host_1 0 host_1 UP + END + + FOR ${i} IN RANGE 60 + ${grep_res} Grep File /tmp/test-LUA.log Status of + IF len("""${grep_res}""") > 0 BREAK + Sleep 1s + END + Should Not Be Empty ${result} No message about the host (1) status + + FOR ${i} IN RANGE 60 + ${grep_res} Grep File /tmp/test-LUA.log Host cache OK regexp=False + IF len("""${grep_res}""") > 0 BREAK + Sleep 1s + END + Should Not Be Empty ${grep_res} Some checks failed + + Ctn Stop Engine + Ctn Kindly Stop Broker diff --git a/tests/resources/Common.py b/tests/resources/Common.py index 7b2bc3f6935..afb7fa36a4b 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -771,7 +771,7 @@ def ctn_check_ba_output_with_timeout(ba_name: str, expected_output: str, timeout logger.console(f"ba: {result[0]}") if result[0]['current_status'] is not None and result[0]['comment'] == expected_output: return True - time.sleep(5) + time.sleep(2) return False diff --git a/tests/resources/resources.robot b/tests/resources/resources.robot index bcf444b6592..d51b50a8e96 100644 --- a/tests/resources/resources.robot +++ b/tests/resources/resources.robot @@ -40,7 +40,7 @@ Ctn Clean Before Suite Ctn Clear Engine Logs Ctn Clear Broker Logs -Ctn Clean Before Suite With rrdcached +Ctn Clean Before Suite With Rrdcached Ctn Clean Before Suite log to console Starting RRDCached Run Process /usr/bin/rrdcached -l unix:${BROKER_LIB}/rrdcached.sock -V LOG_DEBUG -F @@ -286,3 +286,16 @@ Ctn Process Service Result Hard ... ${svc} ... ${state} ... ${output} + +Ctn Wait For Engine To Be Ready + [Arguments] ${start} ${nbEngine}=1 + FOR ${i} IN RANGE ${nbEngine} + # Let's wait for the external command check start + ${content} Create List check_for_external_commands() + ${result} Ctn Find In Log With Timeout + ... ${ENGINE_LOG}/config${i}/centengine.log + ... ${start} ${content} 60 + Should Be True + ... ${result} + ... A message telling check_for_external_commands() should be available in config${i}/centengine.log. + END