Skip to content

Commit

Permalink
enh(broker/lua): lua cache is now updated on service_status/host_stat…
Browse files Browse the repository at this point in the history
…us events

REFS: MON-60933
  • Loading branch information
bouda1 authored May 15, 2024
1 parent 3fe0675 commit 6fbf949
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 104 deletions.
34 changes: 17 additions & 17 deletions bbdo/neb.proto
Original file line number Diff line number Diff line change
@@ -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 : [email protected]
*/
/**
* 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 : [email protected]
*/

syntax = "proto3";

Expand Down
36 changes: 19 additions & 17 deletions broker/lua/inc/com/centreon/broker/lua/macro_cache.hh
Original file line number Diff line number Diff line change
@@ -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 : [email protected]
*/
/**
* 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 : [email protected]
*/

#ifndef CCB_LUA_MACRO_CACHE_HH
#define CCB_LUA_MACRO_CACHE_HH
Expand Down Expand Up @@ -118,13 +118,15 @@ class macro_cache {
void _process_pb_instance(std::shared_ptr<io::data> const& data);
void _process_host(std::shared_ptr<io::data> const& data);
void _process_pb_host(std::shared_ptr<io::data> const& data);
void _process_pb_host_status(std::shared_ptr<io::data> const& data);
void _process_pb_adaptive_host(std::shared_ptr<io::data> const& data);
void _process_host_group(std::shared_ptr<io::data> const& data);
void _process_host_group_member(std::shared_ptr<io::data> const& data);
void _process_custom_variable(std::shared_ptr<io::data> const& data);
void _process_pb_custom_variable(std::shared_ptr<io::data> const& data);
void _process_service(std::shared_ptr<io::data> const& data);
void _process_pb_service(std::shared_ptr<io::data> const& data);
void _process_pb_service_status(std::shared_ptr<io::data> const& data);
void _process_pb_adaptive_service(std::shared_ptr<io::data> const& data);
void _process_service_group(std::shared_ptr<io::data> const& data);
void _process_service_group_member(std::shared_ptr<io::data> const& data);
Expand Down
2 changes: 0 additions & 2 deletions broker/lua/src/luabinding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ int luabinding::write(std::shared_ptr<io::data> 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.
Expand Down
226 changes: 198 additions & 28 deletions broker/lua/src/macro_cache.cc
Original file line number Diff line number Diff line change
@@ -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 : [email protected]
*/
/**
* 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 : [email protected]
*/

#include "com/centreon/broker/lua/macro_cache.hh"
#include "bbdo/bam/dimension_ba_bv_relation_event.hh"
Expand Down Expand Up @@ -515,6 +515,9 @@ void macro_cache::write(std::shared_ptr<io::data> 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;
Expand All @@ -530,6 +533,9 @@ void macro_cache::write(std::shared_ptr<io::data> 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;
Expand Down Expand Up @@ -633,6 +639,84 @@ void macro_cache::_process_pb_host(std::shared_ptr<io::data> const& data) {
_hosts.erase(h->obj().host_id());
}

void macro_cache::_process_pb_host_status(
const std::shared_ptr<io::data>& data) {
const auto& s = std::static_pointer_cast<neb::pb_host_status>(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<neb::host>(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<neb::pb_host>(it->second)->mut_obj();
hst.set_checked(obj.checked());
hst.set_check_type(static_cast<Host_CheckType>(obj.check_type()));
hst.set_state(static_cast<Host_State>(obj.state()));
hst.set_state_type(static_cast<Host_StateType>(obj.state_type()));
hst.set_last_state_change(obj.last_state_change());
hst.set_last_hard_state(static_cast<Host_State>(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.
*
Expand Down Expand Up @@ -727,10 +811,12 @@ void macro_cache::_process_pb_adaptive_host(
void macro_cache::_process_host_group(std::shared_ptr<io::data> const& data) {
std::shared_ptr<neb::host_group> const& hg =
std::static_pointer_cast<neb::host_group>(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
}

/**
Expand Down Expand Up @@ -785,6 +871,89 @@ void macro_cache::_process_pb_service(std::shared_ptr<io::data> const& data) {
_services.erase({s->obj().host_id(), s->obj().service_id()});
}

void macro_cache::_process_pb_service_status(
const std::shared_ptr<io::data>& data) {
const auto& s = std::static_pointer_cast<neb::pb_service_status>(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<neb::service>(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<neb::pb_service>(it->second)->mut_obj();
svc.set_checked(obj.checked());
svc.set_check_type(static_cast<Service_CheckType>(obj.check_type()));
svc.set_state(static_cast<Service_State>(obj.state()));
svc.set_state_type(static_cast<Service_StateType>(obj.state_type()));
svc.set_last_state_change(obj.last_state_change());
svc.set_last_hard_state(static_cast<Service_State>(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.
*
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -1020,10 +1190,10 @@ void macro_cache::_process_dimension_ba_bv_relation_event(
} else {
auto const& rel =
std::static_pointer_cast<bam::dimension_ba_bv_relation_event>(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<bam::pb_dimension_ba_bv_relation_event>());
pb_data->mut_obj().set_ba_id(rel->ba_id);
pb_data->mut_obj().set_bv_id(rel->bv_id);
Expand Down Expand Up @@ -1102,11 +1272,11 @@ void macro_cache::_process_custom_variable(
std::shared_ptr<io::data> const& data) {
auto const& cv = std::static_pointer_cast<neb::custom_variable>(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;
Expand Down
Loading

3 comments on commit 6fbf949

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
13 1 0 14 92.86 0s

Passed Tests

Name ⏱️ Duration Suite
BETAG1 0.000 s Tags
BETAG2 0.000 s Tags
BEUTAG1 0.000 s Tags
BEUTAG2 0.000 s Tags
BEUTAG3 0.000 s Tags
BEUTAG4 0.000 s Tags
BEUTAG5 0.000 s Tags
BEUTAG6 0.000 s Tags
BEUTAG9 0.000 s Tags
BEUTAG10 0.000 s Tags
BEUTAG11 0.000 s Tags
BEUTAG12 0.000 s Tags
BEUTAG_REMOVE_HOST_FROM_HOSTGROUP 0.000 s Tags

Failed Tests

Name Message ⏱️ Duration Suite
BEUTAG8 First step: Service (1, 2) should have servicecategory tags 3 and 5. 0.000 s Tags

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
13 1 0 14 92.86 0s

Passed Tests

Name ⏱️ Duration Suite
BETAG1 0.000 s Tags
BETAG2 0.000 s Tags
BEUTAG1 0.000 s Tags
BEUTAG2 0.000 s Tags
BEUTAG3 0.000 s Tags
BEUTAG4 0.000 s Tags
BEUTAG5 0.000 s Tags
BEUTAG6 0.000 s Tags
BEUTAG9 0.000 s Tags
BEUTAG10 0.000 s Tags
BEUTAG11 0.000 s Tags
BEUTAG12 0.000 s Tags
BEUTAG_REMOVE_HOST_FROM_HOSTGROUP 0.000 s Tags

Failed Tests

Name Message ⏱️ Duration Suite
BEUTAG8 First step: Service (1, 2) should have servicecategory tags 3 and 5. 0.000 s Tags

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
13 1 0 14 92.86 0s

Passed Tests

Name ⏱️ Duration Suite
BETAG1 0.000 s Tags
BETAG2 0.000 s Tags
BEUTAG1 0.000 s Tags
BEUTAG2 0.000 s Tags
BEUTAG3 0.000 s Tags
BEUTAG4 0.000 s Tags
BEUTAG5 0.000 s Tags
BEUTAG6 0.000 s Tags
BEUTAG8 0.000 s Tags
BEUTAG9 0.000 s Tags
BEUTAG10 0.000 s Tags
BEUTAG12 0.000 s Tags
BEUTAG_REMOVE_HOST_FROM_HOSTGROUP 0.000 s Tags

Failed Tests

Name Message ⏱️ Duration Suite
BEUTAG11 First step: Service (1, 4) should have servicegroup tags 2 and 4 0.000 s Tags

Please sign in to comment.