Make sure the name of the initial library (libicinga) is not hard-coded.

Refs #4959
This commit is contained in:
Gunnar Beutner 2013-11-04 15:28:21 +01:00
parent 871f6febc7
commit a6b0233b75
3 changed files with 26 additions and 7 deletions

View File

@ -10,7 +10,7 @@ IcingaPkgDataDir |**Read-only.** Contains the path of the package data
IcingaStatePath |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to IcingaLocalStateDir + "/lib/icinga2/icinga2.state". IcingaStatePath |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to IcingaLocalStateDir + "/lib/icinga2/icinga2.state".
IcingaPidPath |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to IcingaLocalStateDir + "/run/icinga2/icinga2.pid". IcingaPidPath |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to IcingaLocalStateDir + "/run/icinga2/icinga2.pid".
IcingaMacros |**Read-write.** Contains a dictionary with global macros. Not set by default. IcingaMacros |**Read-write.** Contains a dictionary with global macros. Not set by default.
ApplicationType |**Read-write.** Contains the name of the Application type. Defaults to "IcingaApplication". ApplicationType |**Read-write.** Contains the name of the Application type. Defaults to "icinga/IcingaApplication".
IcingaEnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true. IcingaEnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true.
IcingaEnableEventHandlers |**Read-write.** Whether event handlers are globally enabled. Defaults to true. IcingaEnableEventHandlers |**Read-write.** Whether event handlers are globally enabled. Defaults to true.
IcingaEnableFlapping |**Read-write.** Whether flap detection is globally enabled. Defaults to true. IcingaEnableFlapping |**Read-write.** Whether flap detection is globally enabled. Defaults to true.

View File

@ -44,7 +44,25 @@ namespace po = boost::program_options;
static po::variables_map g_AppParams; static po::variables_map g_AppParams;
static bool LoadConfigFiles(bool validateOnly) static String LoadAppType(const String& typeSpec)
{
int index;
Log(LogInformation, "icinga-app", "Loading application type: " + typeSpec);
index = typeSpec.FindFirstOf('/');
if (index == String::NPos)
return typeSpec;
String library = typeSpec.SubStr(0, index);
(void) Utility::LoadExtensionLibrary(library);
return typeSpec.SubStr(index + 1);
}
static bool LoadConfigFiles(const String& appType, bool validateOnly)
{ {
ConfigCompilerContext::GetInstance()->Reset(); ConfigCompilerContext::GetInstance()->Reset();
@ -58,7 +76,7 @@ static bool LoadConfigFiles(bool validateOnly)
} }
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(); ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>();
builder->SetType(Application::GetApplicationType()); builder->SetType(appType);
builder->SetName("application"); builder->SetName("application");
ConfigItem::Ptr item = builder->Compile(); ConfigItem::Ptr item = builder->Compile();
item->Register(); item->Register();
@ -177,7 +195,7 @@ int main(int argc, char **argv)
Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR); Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
Application::DeclarePkgDataDir(ICINGA_PKGDATADIR); Application::DeclarePkgDataDir(ICINGA_PKGDATADIR);
Application::DeclareApplicationType("IcingaApplication"); Application::DeclareApplicationType("icinga/IcingaApplication");
po::options_description desc("Supported options"); po::options_description desc("Supported options");
desc.add_options() desc.add_options()
@ -311,8 +329,7 @@ int main(int argc, char **argv)
Log(LogInformation, "icinga-app", "Icinga application loader (version: " + Application::GetVersion() + ")"); Log(LogInformation, "icinga-app", "Icinga application loader (version: " + Application::GetVersion() + ")");
(void) Utility::LoadExtensionLibrary("icinga"); String appType = LoadAppType(Application::GetApplicationType());
(void) Utility::LoadExtensionLibrary("methods");
if (g_AppParams.count("library")) { if (g_AppParams.count("library")) {
BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as<std::vector<String> >()) { BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as<std::vector<String> >()) {
@ -345,7 +362,7 @@ int main(int argc, char **argv)
bool validateOnly = g_AppParams.count("validate"); bool validateOnly = g_AppParams.count("validate");
if (!LoadConfigFiles(validateOnly)) if (!LoadConfigFiles(appType, validateOnly))
return EXIT_FAILURE; return EXIT_FAILURE;
if (validateOnly) { if (validateOnly) {

View File

@ -38,6 +38,8 @@ INITIALIZE_ONCE(IcingaApplication, &IcingaApplication::StaticInitialize);
void IcingaApplication::StaticInitialize(void) void IcingaApplication::StaticInitialize(void)
{ {
(void) Utility::LoadExtensionLibrary("methods");
ScriptVariable::Set("IcingaEnableNotifications", true); ScriptVariable::Set("IcingaEnableNotifications", true);
ScriptVariable::Set("IcingaEnableEventHandlers", true); ScriptVariable::Set("IcingaEnableEventHandlers", true);
ScriptVariable::Set("IcingaEnableFlapping", true); ScriptVariable::Set("IcingaEnableFlapping", true);