2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2012-06-06 14:38:28 +02:00
|
|
|
|
|
|
|
#ifndef CONFIGITEM_H
|
|
|
|
#define CONFIGITEM_H
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "config/i2-config.hpp"
|
2014-10-16 17:44:06 +02:00
|
|
|
#include "config/expression.hpp"
|
2015-11-19 19:38:20 +01:00
|
|
|
#include "config/activationcontext.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configobject.hpp"
|
2014-11-16 16:20:39 +01:00
|
|
|
#include "base/workqueue.hpp"
|
2013-03-16 21:18:53 +01:00
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2015-11-19 19:38:20 +01:00
|
|
|
|
2012-09-17 14:47:43 +02:00
|
|
|
/**
|
2012-09-19 12:32:39 +02:00
|
|
|
* A configuration item. Non-abstract configuration items can be used to
|
|
|
|
* create configuration objects at runtime.
|
2012-09-17 14:47:43 +02:00
|
|
|
*
|
|
|
|
* @ingroup config
|
|
|
|
*/
|
2018-01-04 06:11:04 +01:00
|
|
|
class ConfigItem final : public Object {
|
2012-06-01 16:49:33 +02:00
|
|
|
public:
|
2014-11-07 12:32:25 +01:00
|
|
|
DECLARE_PTR_TYPEDEFS(ConfigItem);
|
2012-06-06 14:38:28 +02:00
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
ConfigItem(Type::Ptr type, String name, bool abstract,
|
2019-07-26 14:17:27 +02:00
|
|
|
Expression::Ptr exprl,
|
|
|
|
Expression::Ptr filter,
|
2018-01-04 08:54:18 +01:00
|
|
|
bool defaultTmpl, bool ignoreOnError, DebugInfo debuginfo,
|
|
|
|
Dictionary::Ptr scope, String zone,
|
|
|
|
String package);
|
2012-06-05 15:05:15 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Type::Ptr GetType() const;
|
|
|
|
String GetName() const;
|
|
|
|
bool IsAbstract() const;
|
|
|
|
bool IsDefaultTemplate() const;
|
|
|
|
bool IsIgnoreOnError() const;
|
2012-06-05 15:05:15 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::vector<ConfigItem::Ptr> GetParents() const;
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2019-07-26 14:17:27 +02:00
|
|
|
Expression::Ptr GetExpression() const;
|
|
|
|
Expression::Ptr GetFilter() const;
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Register();
|
|
|
|
void Unregister();
|
2013-01-30 23:02:46 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
DebugInfo GetDebugInfo() const;
|
|
|
|
Dictionary::Ptr GetScope() const;
|
2014-03-24 11:23:47 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ConfigObject::Ptr GetObject() const;
|
2017-12-13 12:54:14 +01:00
|
|
|
|
2017-05-11 14:21:30 +02:00
|
|
|
static ConfigItem::Ptr GetByTypeAndName(const Type::Ptr& type,
|
2017-12-19 15:50:05 +01:00
|
|
|
const String& name);
|
2012-06-05 15:05:15 +02:00
|
|
|
|
2016-08-09 10:40:29 +02:00
|
|
|
static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent = false);
|
2021-01-13 15:19:55 +01:00
|
|
|
static bool ActivateItems(const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated = false,
|
2021-06-21 16:07:36 +02:00
|
|
|
bool mainConfigActivation = false, bool withModAttrs = false, const Value& cookie = Empty);
|
2012-07-27 16:05:02 +02:00
|
|
|
|
2015-11-19 19:38:20 +01:00
|
|
|
static bool RunWithActivationContext(const Function::Ptr& function);
|
2014-12-19 13:08:46 +01:00
|
|
|
|
2017-05-11 14:21:30 +02:00
|
|
|
static std::vector<ConfigItem::Ptr> GetItems(const Type::Ptr& type);
|
|
|
|
static std::vector<ConfigItem::Ptr> GetDefaultTemplates(const Type::Ptr& type);
|
2014-11-16 16:20:39 +01:00
|
|
|
|
2016-03-31 13:29:08 +02:00
|
|
|
static void RemoveIgnoredItems(const String& allowedConfigPath);
|
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
private:
|
2017-05-11 14:21:30 +02:00
|
|
|
Type::Ptr m_Type; /**< The object type. */
|
2012-09-19 12:32:39 +02:00
|
|
|
String m_Name; /**< The name. */
|
2013-03-11 12:04:10 +01:00
|
|
|
bool m_Abstract; /**< Whether this is a template. */
|
2012-07-06 14:33:10 +02:00
|
|
|
|
2019-07-26 14:17:27 +02:00
|
|
|
Expression::Ptr m_Expression;
|
|
|
|
Expression::Ptr m_Filter;
|
2016-08-28 10:27:43 +02:00
|
|
|
bool m_DefaultTmpl;
|
2015-10-05 12:44:11 +02:00
|
|
|
bool m_IgnoreOnError;
|
2012-09-19 12:32:39 +02:00
|
|
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
2014-11-22 12:21:28 +01:00
|
|
|
Dictionary::Ptr m_Scope; /**< variable scope. */
|
2014-05-03 20:02:22 +02:00
|
|
|
String m_Zone; /**< The zone. */
|
2015-08-28 17:58:29 +02:00
|
|
|
String m_Package;
|
2015-11-19 19:38:20 +01:00
|
|
|
ActivationContext::Ptr m_ActivationContext;
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr m_Object;
|
2013-03-19 07:09:06 +01:00
|
|
|
|
2021-02-02 10:16:04 +01:00
|
|
|
static std::mutex m_Mutex;
|
2013-02-17 19:14:34 +01:00
|
|
|
|
2014-11-16 16:20:39 +01:00
|
|
|
typedef std::map<String, ConfigItem::Ptr> ItemMap;
|
2017-05-11 14:21:30 +02:00
|
|
|
typedef std::map<Type::Ptr, ItemMap> TypeMap;
|
2014-11-16 16:20:39 +01:00
|
|
|
static TypeMap m_Items; /**< All registered configuration items. */
|
2016-08-29 08:40:46 +02:00
|
|
|
static TypeMap m_DefaultTemplates;
|
2013-02-22 08:12:43 +01:00
|
|
|
|
2014-11-09 04:17:34 +01:00
|
|
|
typedef std::vector<ConfigItem::Ptr> ItemList;
|
|
|
|
static ItemList m_UnnamedItems;
|
2016-03-31 13:29:08 +02:00
|
|
|
|
|
|
|
typedef std::vector<String> IgnoredItemList;
|
|
|
|
static IgnoredItemList m_IgnoredItems;
|
2014-11-09 04:17:34 +01:00
|
|
|
|
2013-02-22 08:12:43 +01:00
|
|
|
static ConfigItem::Ptr GetObjectUnlocked(const String& type,
|
2017-12-19 15:50:05 +01:00
|
|
|
const String& name);
|
2014-11-15 15:57:23 +01:00
|
|
|
|
2015-11-19 19:38:20 +01:00
|
|
|
ConfigObject::Ptr Commit(bool discard = true);
|
|
|
|
|
|
|
|
static bool CommitNewItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems);
|
2012-06-01 16:49:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
#endif /* CONFIGITEM_H */
|