mirror of https://github.com/Icinga/icinga2.git
Merge pull request #6270 from Icinga/feature/activation-priority
Add activation priority for config object types
This commit is contained in:
commit
40dfd82d65
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class FileLogger : StreamLogger
|
class FileLogger : StreamLogger
|
||||||
{
|
{
|
||||||
|
activation_priority -100;
|
||||||
|
|
||||||
[config, required] String path;
|
[config, required] String path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class SyslogLogger : Logger
|
class SyslogLogger : Logger
|
||||||
{
|
{
|
||||||
|
activation_priority -100;
|
||||||
|
|
||||||
[config] String facility {
|
[config] String facility {
|
||||||
default {{{ return "LOG_USER"; }}}
|
default {{{ return "LOG_USER"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -154,6 +154,11 @@ std::vector<String> Type::GetLoadDependencies() const
|
||||||
return std::vector<String>();
|
return std::vector<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Type::GetActivationPriority() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Type::RegisterAttributeHandler(int fieldId, const AttributeHandler& callback)
|
void Type::RegisterAttributeHandler(int fieldId, const AttributeHandler& callback)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid field ID.");
|
throw std::runtime_error("Invalid field ID.");
|
||||||
|
|
|
@ -103,6 +103,7 @@ public:
|
||||||
Value GetField(int id) const override;
|
Value GetField(int id) const override;
|
||||||
|
|
||||||
virtual std::vector<String> GetLoadDependencies() const;
|
virtual std::vector<String> GetLoadDependencies() const;
|
||||||
|
virtual int GetActivationPriority() const;
|
||||||
|
|
||||||
typedef std::function<void (const Object::Ptr&, const Value&)> AttributeHandler;
|
typedef std::function<void (const Object::Ptr&, const Value&)> AttributeHandler;
|
||||||
virtual void RegisterAttributeHandler(int fieldId, const AttributeHandler& callback);
|
virtual void RegisterAttributeHandler(int fieldId, const AttributeHandler& callback);
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class CheckerComponent : ConfigObject
|
class CheckerComponent : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] int concurrent_checks {
|
[config] int concurrent_checks {
|
||||||
get {{{
|
get {{{
|
||||||
return Application::GetMaxConcurrentChecks();
|
return Application::GetMaxConcurrentChecks();
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace icinga
|
||||||
|
|
||||||
class CheckResultReader : ConfigObject
|
class CheckResultReader : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String spool_dir {
|
[config] String spool_dir {
|
||||||
default {{{ return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; }}}
|
default {{{ return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace icinga
|
||||||
|
|
||||||
class CompatLogger : ConfigObject
|
class CompatLogger : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String log_dir {
|
[config] String log_dir {
|
||||||
default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}}
|
default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace icinga
|
||||||
|
|
||||||
class ExternalCommandListener : ConfigObject
|
class ExternalCommandListener : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String command_path {
|
[config] String command_path {
|
||||||
default {{{ return Application::GetRunDir() + "/icinga2/cmd/icinga2.cmd"; }}}
|
default {{{ return Application::GetRunDir() + "/icinga2/cmd/icinga2.cmd"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace icinga
|
||||||
|
|
||||||
class StatusDataWriter : ConfigObject
|
class StatusDataWriter : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String status_path {
|
[config] String status_path {
|
||||||
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; }}}
|
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -602,18 +602,35 @@ bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr
|
||||||
if (!silent)
|
if (!silent)
|
||||||
Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
|
Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
|
||||||
|
|
||||||
for (const ConfigItem::Ptr& item : newItems) {
|
/* Activate objects in priority order. */
|
||||||
if (!item->m_Object)
|
std::vector<Type::Ptr> types = Type::GetAllTypes();
|
||||||
continue;
|
|
||||||
|
|
||||||
ConfigObject::Ptr object = item->m_Object;
|
std::sort(types.begin(), types.end(), [](const Type::Ptr& a, const Type::Ptr& b) {
|
||||||
|
if (a->GetActivationPriority() < b->GetActivationPriority())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const Type::Ptr& type : types) {
|
||||||
|
for (const ConfigItem::Ptr& item : newItems) {
|
||||||
|
if (!item->m_Object)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ConfigObject::Ptr object = item->m_Object;
|
||||||
|
Type::Ptr objectType = object->GetReflectionType();
|
||||||
|
|
||||||
|
if (objectType != type)
|
||||||
|
continue;
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
Log(LogDebug, "ConfigItem")
|
Log(LogDebug, "ConfigItem")
|
||||||
<< "Activating object '" << object->GetName() << "' of type '" << object->GetReflectionType()->GetName() << "'";
|
<< "Activating object '" << object->GetName() << "' of type '"
|
||||||
|
<< objectType->GetName() << "' with priority '"
|
||||||
|
<< objectType->GetActivationPriority();
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
object->Activate(runtimeCreated);
|
object->Activate(runtimeCreated);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
upq.Join();
|
upq.Join();
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class IdoMysqlConnection : DbConnection
|
class IdoMysqlConnection : DbConnection
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String host {
|
[config] String host {
|
||||||
default {{{ return "localhost"; }}}
|
default {{{ return "localhost"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class IdoPgsqlConnection : DbConnection
|
class IdoPgsqlConnection : DbConnection
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String host {
|
[config] String host {
|
||||||
default {{{ return "localhost"; }}}
|
default {{{ return "localhost"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
class LivestatusListener : ConfigObject {
|
class LivestatusListener : ConfigObject {
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String socket_type {
|
[config] String socket_type {
|
||||||
default {{{ return "unix"; }}}
|
default {{{ return "unix"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class NotificationComponent : ConfigObject
|
class NotificationComponent : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] bool enable_ha (EnableHA) {
|
[config] bool enable_ha (EnableHA) {
|
||||||
default {{{ return true; }}}
|
default {{{ return true; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,8 @@ namespace icinga
|
||||||
|
|
||||||
class ElasticsearchWriter : ConfigObject
|
class ElasticsearchWriter : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config, required] String host {
|
[config, required] String host {
|
||||||
default {{{ return "127.0.0.1"; }}}
|
default {{{ return "127.0.0.1"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class GelfWriter : ConfigObject
|
class GelfWriter : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String host {
|
[config] String host {
|
||||||
default {{{ return "127.0.0.1"; }}}
|
default {{{ return "127.0.0.1"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class GraphiteWriter : ConfigObject
|
class GraphiteWriter : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String host {
|
[config] String host {
|
||||||
default {{{ return "127.0.0.1"; }}}
|
default {{{ return "127.0.0.1"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class InfluxdbWriter : ConfigObject
|
class InfluxdbWriter : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config, required] String host {
|
[config, required] String host {
|
||||||
default {{{ return "127.0.0.1"; }}}
|
default {{{ return "127.0.0.1"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
class OpenTsdbWriter : ConfigObject
|
class OpenTsdbWriter : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String host {
|
[config] String host {
|
||||||
default {{{ return "127.0.0.1"; }}}
|
default {{{ return "127.0.0.1"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace icinga
|
||||||
|
|
||||||
class PerfdataWriter : ConfigObject
|
class PerfdataWriter : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 100;
|
||||||
|
|
||||||
[config] String host_perfdata_path {
|
[config] String host_perfdata_path {
|
||||||
default {{{ return Application::GetLocalStateDir() + "/spool/icinga2/perfdata/host-perfdata"; }}}
|
default {{{ return Application::GetLocalStateDir() + "/spool/icinga2/perfdata/host-perfdata"; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,8 @@ namespace icinga
|
||||||
|
|
||||||
class ApiListener : ConfigObject
|
class ApiListener : ConfigObject
|
||||||
{
|
{
|
||||||
|
activation_priority 50;
|
||||||
|
|
||||||
[config, deprecated] String cert_path;
|
[config, deprecated] String cert_path;
|
||||||
[config, deprecated] String key_path;
|
[config, deprecated] String key_path;
|
||||||
[config, deprecated] String ca_path;
|
[config, deprecated] String ca_path;
|
||||||
|
|
|
@ -135,6 +135,7 @@ class { return T_CLASS; }
|
||||||
namespace { return T_NAMESPACE; }
|
namespace { return T_NAMESPACE; }
|
||||||
code { return T_CODE; }
|
code { return T_CODE; }
|
||||||
load_after { return T_LOAD_AFTER; }
|
load_after { return T_LOAD_AFTER; }
|
||||||
|
activation_priority { return T_ACTIVATION_PRIORITY; }
|
||||||
library { return T_LIBRARY; }
|
library { return T_LIBRARY; }
|
||||||
abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
|
abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
|
||||||
vararg_constructor { yylval->num = TAVarArgConstructor; return T_CLASS_ATTRIBUTE; }
|
vararg_constructor { yylval->num = TAVarArgConstructor; return T_CLASS_ATTRIBUTE; }
|
||||||
|
@ -164,6 +165,7 @@ navigate { yylval->num = FTNavigate; return T_FIELD_ACCESSOR_TYPE; }
|
||||||
\"[^\"]+\" { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_STRING; }
|
\"[^\"]+\" { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_STRING; }
|
||||||
\<[^ \>]*\> { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_ANGLE_STRING; }
|
\<[^ \>]*\> { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_ANGLE_STRING; }
|
||||||
[a-zA-Z_][:a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
|
[a-zA-Z_][:a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
|
||||||
|
-?[0-9]+(\.[0-9]+)? { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
|
||||||
|
|
||||||
. return yytext[0];
|
. return yytext[0];
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ using namespace icinga;
|
||||||
%token T_CLASS "class (T_CLASS)"
|
%token T_CLASS "class (T_CLASS)"
|
||||||
%token T_CODE "code (T_CODE)"
|
%token T_CODE "code (T_CODE)"
|
||||||
%token T_LOAD_AFTER "load_after (T_LOAD_AFTER)"
|
%token T_LOAD_AFTER "load_after (T_LOAD_AFTER)"
|
||||||
|
%token T_ACTIVATION_PRIORITY "activation_priority (T_ACTIVATION_PRIORITY)"
|
||||||
%token T_LIBRARY "library (T_LIBRARY)"
|
%token T_LIBRARY "library (T_LIBRARY)"
|
||||||
%token T_NAMESPACE "namespace (T_NAMESPACE)"
|
%token T_NAMESPACE "namespace (T_NAMESPACE)"
|
||||||
%token T_VALIDATOR "validator (T_VALIDATOR)"
|
%token T_VALIDATOR "validator (T_VALIDATOR)"
|
||||||
|
@ -77,6 +78,7 @@ using namespace icinga;
|
||||||
%token T_SET "set (T_SET)"
|
%token T_SET "set (T_SET)"
|
||||||
%token T_DEFAULT "default (T_DEFAULT)"
|
%token T_DEFAULT "default (T_DEFAULT)"
|
||||||
%token T_FIELD_ACCESSOR_TYPE "field_accessor_type (T_FIELD_ACCESSOR_TYPE)"
|
%token T_FIELD_ACCESSOR_TYPE "field_accessor_type (T_FIELD_ACCESSOR_TYPE)"
|
||||||
|
%token T_NUMBER "number (T_NUMBER)"
|
||||||
%type <text> T_IDENTIFIER
|
%type <text> T_IDENTIFIER
|
||||||
%type <text> T_STRING
|
%type <text> T_STRING
|
||||||
%type <text> T_ANGLE_STRING
|
%type <text> T_ANGLE_STRING
|
||||||
|
@ -106,6 +108,7 @@ using namespace icinga;
|
||||||
%type <rule> validator_rule
|
%type <rule> validator_rule
|
||||||
%type <rules> validator_rules
|
%type <rules> validator_rules
|
||||||
%type <validator> validator
|
%type <validator> validator
|
||||||
|
%type <num> T_NUMBER
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
|
@ -250,6 +253,8 @@ class: class_attribute_list T_CLASS T_IDENTIFIER inherits_specifier type_base_sp
|
||||||
for (const Field& field : *$7) {
|
for (const Field& field : *$7) {
|
||||||
if (field.Attributes & FALoadDependency) {
|
if (field.Attributes & FALoadDependency) {
|
||||||
$$->LoadDependencies.push_back(field.Name);
|
$$->LoadDependencies.push_back(field.Name);
|
||||||
|
} else if (field.Attributes & FAActivationPriority) {
|
||||||
|
$$->ActivationPriority = field.Priority;
|
||||||
} else
|
} else
|
||||||
$$->Fields.push_back(field);
|
$$->Fields.push_back(field);
|
||||||
}
|
}
|
||||||
|
@ -380,6 +385,13 @@ class_field: field_attribute_list field_type identifier alternative_name_specifi
|
||||||
std::free($2);
|
std::free($2);
|
||||||
$$ = field;
|
$$ = field;
|
||||||
}
|
}
|
||||||
|
| T_ACTIVATION_PRIORITY T_NUMBER ';'
|
||||||
|
{
|
||||||
|
auto *field = new Field();
|
||||||
|
field->Attributes = FAActivationPriority;
|
||||||
|
field->Priority = $2;
|
||||||
|
$$ = field;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
alternative_name_specifier: /* empty */
|
alternative_name_specifier: /* empty */
|
||||||
|
|
|
@ -408,6 +408,14 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
|
||||||
m_Impl << "\t" << "return deps;" << std::endl
|
m_Impl << "\t" << "return deps;" << std::endl
|
||||||
<< "}" << std::endl << std::endl;
|
<< "}" << std::endl << std::endl;
|
||||||
|
|
||||||
|
/* GetActivationPriority */
|
||||||
|
m_Header << "\t" << "int GetActivationPriority() const override;" << std::endl;
|
||||||
|
|
||||||
|
m_Impl << "int TypeImpl<" << klass.Name << ">::GetActivationPriority() const" << std::endl
|
||||||
|
<< "{" << std::endl
|
||||||
|
<< "\t" << "return " << klass.ActivationPriority << ";" << std::endl
|
||||||
|
<< "}" << std::endl << std::endl;
|
||||||
|
|
||||||
/* RegisterAttributeHandler */
|
/* RegisterAttributeHandler */
|
||||||
m_Header << "public:" << std::endl
|
m_Header << "public:" << std::endl
|
||||||
<< "\t" << "void RegisterAttributeHandler(int fieldId, const Type::AttributeHandler& callback) override;" << std::endl;
|
<< "\t" << "void RegisterAttributeHandler(int fieldId, const Type::AttributeHandler& callback) override;" << std::endl;
|
||||||
|
|
|
@ -76,7 +76,8 @@ enum FieldAttribute
|
||||||
FANoUserView = 2048,
|
FANoUserView = 2048,
|
||||||
FADeprecated = 4096,
|
FADeprecated = 4096,
|
||||||
FAGetVirtual = 8192,
|
FAGetVirtual = 8192,
|
||||||
FASetVirtual = 16384
|
FASetVirtual = 16384,
|
||||||
|
FAActivationPriority = 32768
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FieldType
|
struct FieldType
|
||||||
|
@ -122,6 +123,7 @@ struct Field
|
||||||
std::string NavigationName;
|
std::string NavigationName;
|
||||||
std::string NavigateAccessor;
|
std::string NavigateAccessor;
|
||||||
bool PureNavigateAccessor{false};
|
bool PureNavigateAccessor{false};
|
||||||
|
int Priority{0};
|
||||||
|
|
||||||
inline std::string GetFriendlyName() const
|
inline std::string GetFriendlyName() const
|
||||||
{
|
{
|
||||||
|
@ -167,6 +169,7 @@ struct Klass
|
||||||
int Attributes;
|
int Attributes;
|
||||||
std::vector<Field> Fields;
|
std::vector<Field> Fields;
|
||||||
std::vector<std::string> LoadDependencies;
|
std::vector<std::string> LoadDependencies;
|
||||||
|
int ActivationPriority{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RuleAttribute
|
enum RuleAttribute
|
||||||
|
|
Loading…
Reference in New Issue