Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
fix(macros): hostgroups/servicegroups may be empty.
Browse files Browse the repository at this point in the history

REFS: MON-7197
  • Loading branch information
bouda1 authored Apr 26, 2021
1 parent 12e9272 commit 6fde671
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 21.04.1

### Bugs

*Macros*

If a service / host is not in a service/host group, then the HOSTGROUPNAME/
SERVICEGROUPNAME macros can lead to segfault. This patch fixes this issue.

## 21.04.0

`To be released in april 2021`
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ link_directories(${json11_LIB_DIRS})
# Version.
set(CENTREON_ENGINE_MAJOR 21)
set(CENTREON_ENGINE_MINOR 04)
set(CENTREON_ENGINE_PATCH 0)
set(CENTREON_ENGINE_PATCH 1)
if (CENTREON_ENGINE_PRERELEASE)
set(CENTREON_ENGINE_VERSION "${CENTREON_ENGINE_MAJOR}.${CENTREON_ENGINE_MINOR}.${CENTREON_ENGINE_PATCH}-${CENTREON_ENGINE_PRERELEASE}")
else ()
Expand Down
17 changes: 7 additions & 10 deletions src/macros/grab_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ using namespace com::centreon::engine;
using namespace com::centreon::engine::macros;
using namespace com::centreon::engine::logging;

/**************************************
* *
* Local Functions *
* *
**************************************/

/**
* Generate total services macros.
*
Expand Down Expand Up @@ -141,10 +135,13 @@ static std::string get_host_group_names(host& hst, nagios_macros* mac) {
*/
static std::string get_host_group_name(host& hst, nagios_macros* mac) {
(void)mac;
logger(dbg_notifications, more) << "on macro juste avant host group ";
std::string buf{hst.get_parent_groups().front()->get_group_name()};
logger(dbg_notifications, more) << "on macro after host group " << buf;
return buf;

// Find all hostgroups this host is associated with.
auto it = hst.get_parent_groups().begin();
if (it == hst.get_parent_groups().end())
return "";
else
return (*it)->get_group_name();
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/macros/grab_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ static std::string get_service_group_name(service& svc, nagios_macros* mac) {
(void)mac;

// Find all servicegroups this service is associated with.
std::string buf{svc.get_parent_groups().front()->get_group_name()};
logger(dbg_notifications, more) << "on grab service service name :" << buf;
return buf;
auto it = svc.get_parent_groups().begin();
if (it == svc.get_parent_groups().end())
return "";
else
return (*it)->get_group_name();
}

/**
Expand Down Expand Up @@ -234,7 +236,11 @@ struct grab_service_redirection {
true}},
// Is volatile.
{MACRO_SERVICEISVOLATILE,
{&get_member_as_string<service, bool, notifier, &notifier::get_is_volatile>, true}},
{&get_member_as_string<service,
bool,
notifier,
&notifier::get_is_volatile>,
true}},
// Attempt.
{MACRO_SERVICEATTEMPT,
{&get_member_as_string<service,
Expand Down

0 comments on commit 6fde671

Please sign in to comment.