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

Mon 87270 customvariable conf #1397

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4a8cb65
enh(engine): customvariables have their own configuration class
bouda1 Jun 5, 2024
42e07ae
enh(engine/string): string lib removed from configuration
bouda1 May 22, 2024
e116fb1
fix(engine/string): string lib removed from configuration
bouda1 May 22, 2024
a5f095c
cleanup(engine/configuration): headers updated
bouda1 May 22, 2024
5eab0e0
fix(engine/string): string lib a little less used in configuration mo…
bouda1 May 22, 2024
823bb5c
enh(engine/string): always on string functions
bouda1 May 23, 2024
e0ea2a7
fix(engine/conf): issue with debug_level unsigned
bouda1 May 23, 2024
f505072
fix(common/log_v2): log with grpc can crash
bouda1 May 23, 2024
d427ff0
fix(engine/string): still some use of string lib in configuration fixed
bouda1 May 23, 2024
37e3852
fix(engine): extinfo classes are no more used.
bouda1 May 23, 2024
87ff6d6
enh(engine/conf): customvariable has its conf object now
bouda1 May 23, 2024
d3f299c
fix(engine): on configuration independency
bouda1 May 24, 2024
e0ab74e
enh(engine): on the road of independency
bouda1 May 27, 2024
8ce0f01
enh(engine): dependencies on engine removed in configuration
bouda1 May 28, 2024
ad463cf
cleanup(engine): headers updated
bouda1 May 29, 2024
1a8cf46
cleanup(engine): opt file updated
bouda1 May 29, 2024
fbe9d04
fix(engine): wrong order while initializing the logger
bouda1 May 29, 2024
e0dc20f
fix(engine): unit tests fixed
bouda1 Jun 3, 2024
f5eb7c8
fix(tests): issue with notifications fixed
bouda1 Jun 3, 2024
350c112
fix(common/log_v2): issue due to rebase
bouda1 Jun 3, 2024
cffedf1
fix(engine): bad rebase
bouda1 Jun 4, 2024
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
4 changes: 2 additions & 2 deletions broker/neb/src/initial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void send_custom_variables_list(
nscvd.type = NEBTYPE_HOSTCUSTOMVARIABLE_ADD;
nscvd.timestamp.tv_sec = time(nullptr);
nscvd.var_name = const_cast<char*>(name.c_str());
nscvd.var_value = const_cast<char*>(cit->second.get_value().c_str());
nscvd.var_value = const_cast<char*>(cit->second.value().c_str());
nscvd.object_ptr = it->second.get();

// Callback.
Expand All @@ -103,7 +103,7 @@ static void send_custom_variables_list(
nscvd.type = NEBTYPE_SERVICECUSTOMVARIABLE_ADD;
nscvd.timestamp.tv_sec = time(nullptr);
nscvd.var_name = const_cast<char*>(name.c_str());
nscvd.var_value = const_cast<char*>(cit->second.get_value().c_str());
nscvd.var_value = const_cast<char*>(cit->second.value().c_str());
nscvd.object_ptr = it->second.get();

// Callback.
Expand Down
43 changes: 43 additions & 0 deletions clib/inc/com/centreon/exceptions/error.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2023 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_EXCEPTIONS_ERROR_HH
#define CCB_EXCEPTIONS_ERROR_HH

#include "com/centreon/exceptions/msg_fmt.hh"

namespace com::centreon::exceptions {
/**
* @class error error.hh "com/centreon/exceptions/error.hh"
* @brief Shutdown exception class.
*
* This exception is thrown when someone attemps to read from a
* stream that has been error.
*/
class error : public com::centreon::exceptions::msg_fmt {
public:
template <typename... Args>
explicit error(std::string const& str, const Args&... args)
: msg_fmt(str, args...) {}
error() = delete;
~error() noexcept {}
error& operator=(const error&) = delete;
};
} // namespace com::centreon::exceptions

#endif // !CCB_EXCEPTIONS_ERROR_HH
1 change: 1 addition & 0 deletions engine/enginerpc/engine_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace asio = boost::asio;
#include "com/centreon/engine/globals.hh"
#include "com/centreon/engine/hostdependency.hh"
#include "com/centreon/engine/hostgroup.hh"
#include "com/centreon/engine/logging/logger.hh"
#include "com/centreon/engine/service.hh"
#include "com/centreon/engine/servicedependency.hh"
#include "com/centreon/engine/servicegroup.hh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#define CCE_CONFIGURATION_ANOMALYDETECTION_HH

#include "com/centreon/engine/common.hh"
#include "com/centreon/engine/configuration/customvariable.hh"
#include "com/centreon/engine/configuration/group.hh"
#include "com/centreon/engine/configuration/object.hh"
#include "com/centreon/engine/customvariable.hh"
#include "com/centreon/engine/opt.hh"

namespace com::centreon::engine {
Expand All @@ -31,6 +31,12 @@ namespace configuration {

class anomalydetection : public object {
public:
enum state {
state_ok = 0,
state_warning = 1,
state_critical = 2,
state_unknown = 3,
};
enum action_on {
none = 0,
ok = (1 << 0),
Expand All @@ -49,7 +55,7 @@ class anomalydetection : public object {
bool operator==(anomalydetection const& other) const noexcept;
bool operator!=(anomalydetection const& other) const noexcept;
bool operator<(anomalydetection const& other) const noexcept;
void check_validity() const override;
void check_validity(error_info* err) const override;
key_type key() const;
void merge(object const& obj) override;
bool parse(char const* key, char const* value) override;
Expand All @@ -68,8 +74,9 @@ class anomalydetection : public object {
set_string& contacts() noexcept;
set_string const& contacts() const noexcept;
bool contacts_defined() const noexcept;
map_customvar const& customvariables() const noexcept;
map_customvar& customvariables() noexcept;
const std::unordered_map<std::string, customvariable>& customvariables()
const noexcept;
std::unordered_map<std::string, customvariable>& customvariables() noexcept;
std::string const& display_name() const noexcept;
std::string const& event_handler() const noexcept;
bool event_handler_enabled() const noexcept;
Expand Down Expand Up @@ -189,7 +196,7 @@ class anomalydetection : public object {
opt<unsigned int> _check_interval;
group<set_string> _contactgroups;
group<set_string> _contacts;
map_customvar _customvariables;
std::unordered_map<std::string, customvariable> _customvariables;
std::string _display_name;
std::string _event_handler;
opt<bool> _event_handler_enabled;
Expand Down
25 changes: 15 additions & 10 deletions engine/inc/com/centreon/engine/configuration/applier/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ class state;
namespace applier {
class command {
public:
command();
~command() throw();
void add_object(configuration::command const& obj);
/**
* @brief Default constructor
*/
command() = default;

/**
* @brief Destructor.
*/
~command() noexcept = default;
command(const command&) = delete;
command& operator=(const command&) = delete;
void add_object(const configuration::command& obj);
void modify_object(const configuration::command& obj);
void remove_object(const configuration::command& obj);
void expand_objects(configuration::state& s);
void modify_object(configuration::command const& obj);
void remove_object(configuration::command const& obj);
void resolve_object(configuration::command const& obj);

private:
command(command const& right);
command& operator=(command const& right);
void resolve_object(const configuration::command& obj);
};
} // namespace applier
} // namespace configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class scheduler {
timed_event* _evt_reschedule_checks;
timed_event* _evt_retention_save;
timed_event* _evt_sfreshness_check;
timed_event* _evt_service_perfdata;
timed_event* _evt_status_save;
unsigned int _old_auto_rescheduling_interval;
unsigned int _old_check_reaper_interval;
Expand All @@ -106,7 +105,6 @@ class scheduler {
unsigned int _old_retention_update_interval;
unsigned int _old_service_freshness_check_interval;
std::string _old_service_perfdata_file_processing_command;
unsigned int _old_service_perfdata_file_processing_interval;
unsigned int _old_status_update_interval;
};
} // namespace applier
Expand Down
2 changes: 1 addition & 1 deletion engine/inc/com/centreon/engine/configuration/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class command : public object {
bool operator==(command const& right) const throw();
bool operator!=(command const& right) const throw();
bool operator<(command const& right) const throw();
void check_validity() const override;
void check_validity(error_info* err) const override;
key_type const& key() const throw();
void merge(object const& obj) override;
bool parse(char const* key, char const* value) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class connector : public object {
bool operator==(connector const& right) const throw();
bool operator!=(connector const& right) const throw();
bool operator<(connector const& right) const throw();
void check_validity() const override;
void check_validity(error_info* err) const override;
key_type const& key() const throw();
void merge(object const& obj) override;
bool parse(char const* key, char const* value) override;
Expand Down
12 changes: 7 additions & 5 deletions engine/inc/com/centreon/engine/configuration/contact.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include <absl/container/flat_hash_map.h>

#include "com/centreon/engine/configuration/customvariable.hh"
#include "com/centreon/engine/configuration/group.hh"
#include "com/centreon/engine/configuration/object.hh"
#include "com/centreon/engine/customvariable.hh"
#include "com/centreon/engine/opt.hh"

typedef std::vector<std::string> tab_string;
Expand All @@ -42,7 +42,7 @@ class contact : public object {
bool operator==(contact const& other) const noexcept;
bool operator!=(contact const& other) const noexcept;
bool operator<(contact const& other) const noexcept;
void check_validity() const override;
void check_validity(error_info* err) const override;
key_type const& key() const noexcept;
void merge(object const& obj) override;
bool parse(const char* key, const char* value) override;
Expand All @@ -53,8 +53,10 @@ class contact : public object {
set_string& contactgroups() noexcept;
set_string const& contactgroups() const noexcept;
std::string const& contact_name() const noexcept;
map_customvar const& customvariables() const noexcept;
map_customvar& customvariables() noexcept;
const std::unordered_map<std::string, customvariable>& customvariables()
const noexcept;
std::unordered_map<std::string, customvariable>&
mutable_customvariables() noexcept;
std::string const& email() const noexcept;
bool host_notifications_enabled() const noexcept;
list_string const& host_notification_commands() const noexcept;
Expand Down Expand Up @@ -96,7 +98,7 @@ class contact : public object {
opt<bool> _can_submit_commands;
group<set_string> _contactgroups;
std::string _contact_name;
map_customvar _customvariables;
std::unordered_map<std::string, customvariable> _customvariables;
std::string _email;
opt<bool> _host_notifications_enabled;
group<list_string> _host_notification_commands;
Expand Down
24 changes: 12 additions & 12 deletions engine/inc/com/centreon/engine/configuration/contactgroup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ class contactgroup : public object {

contactgroup(key_type const& key = "");
contactgroup(contactgroup const& right);
~contactgroup() throw() override;
~contactgroup() noexcept override;
contactgroup& operator=(contactgroup const& right);
bool operator==(contactgroup const& right) const throw();
bool operator!=(contactgroup const& right) const throw();
bool operator<(contactgroup const& right) const throw();
void check_validity() const override;
key_type const& key() const throw();
bool operator==(contactgroup const& right) const noexcept;
bool operator!=(contactgroup const& right) const noexcept;
bool operator<(contactgroup const& right) const noexcept;
void check_validity(error_info* err) const override;
key_type const& key() const noexcept;
void merge(object const& obj) override;
bool parse(char const* key, char const* value) override;

std::string const& alias() const throw();
set_string& contactgroup_members() throw();
set_string const& contactgroup_members() const throw();
std::string const& contactgroup_name() const throw();
set_string& members() throw();
set_string const& members() const throw();
std::string const& alias() const noexcept;
set_string& contactgroup_members() noexcept;
set_string const& contactgroup_members() const noexcept;
std::string const& contactgroup_name() const noexcept;
set_string& members() noexcept;
set_string const& members() const noexcept;

private:
typedef bool (*setter_func)(contactgroup&, char const*);
Expand Down
79 changes: 44 additions & 35 deletions engine/inc/com/centreon/engine/configuration/file_info.hh
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
/*
** Copyright 2011-2013 Merethis
**
** 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-2013 Merethis
*
* 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_CONFIGURATION_FILE_INFO_HH
#define CCE_CONFIGURATION_FILE_INFO_HH

#include <fmt/ostream.h>

#include "com/centreon/engine/exceptions/error.hh"

namespace com::centreon::engine {
Expand All @@ -30,35 +32,42 @@ class file_info {
std::string _path;

public:
file_info(std::string const& path = "", unsigned int line = 0)
file_info(const std::string& path, uint32_t line)
: _line(line), _path(path) {}
file_info(file_info const& right) { operator=(right); }
~file_info() noexcept {}
file_info& operator=(file_info const& right) {
if (this != &right) {
_line = right._line;
_path = right._path;
file_info(file_info&& other)
: _line{other._line}, _path{std::move(other._path)} {}
~file_info() noexcept = default;
file_info(const file_info&) = delete;
file_info& operator=(const file_info&) = delete;
file_info& operator=(file_info&& other) {
if (this != &other) {
_line = other._line;
_path = std::move(other._path);
}
return *this;
}
bool operator==(file_info const& right) const noexcept {
return _line == right._line && _path == right._path;
}
bool operator!=(file_info const& right) const noexcept {
return !operator==(right);
}

friend exceptions::error& operator<<(exceptions::error& err,
file_info const& info) {
err << "in file '" << info.path() << "' on line " << info.line();
return err;
}
friend std::ostream& operator<<(std::ostream& os, const file_info& info) {
os << fmt::format("in file '{}' on line {}", info.path(), info.line());
return os;
}
unsigned int line() const noexcept { return _line; }
void line(unsigned int line) noexcept { _line = line; }
std::string const& path() const noexcept { return _path; }
void path(std::string const& path) { _path = path; }
const std::string& path() const noexcept { return _path; }
};

} // namespace configuration

}
} // namespace com::centreon::engine

namespace fmt {
template <>
struct formatter<com::centreon::engine::configuration::file_info>
: ostream_formatter {};
} // namespace fmt

#endif // !CCE_CONFIGURATION_FILE_INFO_HH
Loading