]> granicus.if.org Git - icinga2/commitdiff
Move constants and functions into different namespaces
authorGunnar Beutner <gunnar.beutner@icinga.com>
Tue, 7 Aug 2018 11:55:41 +0000 (13:55 +0200)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 13 Aug 2018 11:44:31 +0000 (13:44 +0200)
icinga-app/icinga.cpp
lib/base/logger.cpp
lib/base/sysloglogger.cpp
lib/cli/daemonutility.cpp
lib/db_ido/dbquery.cpp
lib/icinga/checkresult.cpp
lib/icinga/icingaapplication.cpp
lib/icinga/notification.cpp
lib/icinga/objectutils.cpp

index 24da8864403519ce982e4e4c878a6aaad3a8679c..5e8cbd8ec42b1ba6631d32b7b8eea25246f1dd3a 100644 (file)
@@ -300,15 +300,15 @@ static int Main()
 
        ScriptGlobal::Set("AttachDebugger", false);
 
-       ScriptGlobal::Set("PlatformKernel", Utility::GetPlatformKernel());
-       ScriptGlobal::Set("PlatformKernelVersion", Utility::GetPlatformKernelVersion());
-       ScriptGlobal::Set("PlatformName", Utility::GetPlatformName());
-       ScriptGlobal::Set("PlatformVersion", Utility::GetPlatformVersion());
-       ScriptGlobal::Set("PlatformArchitecture", Utility::GetPlatformArchitecture());
-
-       ScriptGlobal::Set("BuildHostName", ICINGA_BUILD_HOST_NAME);
-       ScriptGlobal::Set("BuildCompilerName", ICINGA_BUILD_COMPILER_NAME);
-       ScriptGlobal::Set("BuildCompilerVersion", ICINGA_BUILD_COMPILER_VERSION);
+       ScriptGlobal::Set("System.PlatformKernel", Utility::GetPlatformKernel(), true);
+       ScriptGlobal::Set("System.PlatformKernelVersion", Utility::GetPlatformKernelVersion(), true);
+       ScriptGlobal::Set("System.PlatformName", Utility::GetPlatformName(), true);
+       ScriptGlobal::Set("System.PlatformVersion", Utility::GetPlatformVersion(), true);
+       ScriptGlobal::Set("System.PlatformArchitecture", Utility::GetPlatformArchitecture(), true);
+
+       ScriptGlobal::Set("System.BuildHostName", ICINGA_BUILD_HOST_NAME, true);
+       ScriptGlobal::Set("System.BuildCompilerName", ICINGA_BUILD_COMPILER_NAME, true);
+       ScriptGlobal::Set("System.BuildCompilerVersion", ICINGA_BUILD_COMPILER_VERSION, true);
 
        if (!autocomplete)
                Application::SetResourceLimits();
index 376296ada0c38075093b1af4eeee0e06cf5bf742..9a59d199f32c5242064f850a00c265cc27353434 100644 (file)
@@ -49,11 +49,11 @@ bool Logger::m_TimestampEnabled = true;
 LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
 
 INITIALIZE_ONCE([]() {
-       ScriptGlobal::Set("LogDebug", LogDebug);
-       ScriptGlobal::Set("LogNotice", LogNotice);
-       ScriptGlobal::Set("LogInformation", LogInformation);
-       ScriptGlobal::Set("LogWarning", LogWarning);
-       ScriptGlobal::Set("LogCritical", LogCritical);
+       ScriptGlobal::Set("System.LogDebug", LogDebug, true);
+       ScriptGlobal::Set("System.LogNotice", LogNotice, true);
+       ScriptGlobal::Set("System.LogInformation", LogInformation, true);
+       ScriptGlobal::Set("System.LogWarning", LogWarning, true);
+       ScriptGlobal::Set("System.LogCritical", LogCritical, true);
 });
 
 /**
index b5d735a8030fffa79718e23a07e81bdd253cec2f..673a27930c1a7412fe68901c12dfdd8ab05df61d 100644 (file)
@@ -35,26 +35,26 @@ std::map<String, int> SyslogLogger::m_FacilityMap;
 
 void SyslogLogger::StaticInitialize()
 {
-       ScriptGlobal::Set("FacilityAuth", "LOG_AUTH");
-       ScriptGlobal::Set("FacilityAuthPriv", "LOG_AUTHPRIV");
-       ScriptGlobal::Set("FacilityCron", "LOG_CRON");
-       ScriptGlobal::Set("FacilityDaemon", "LOG_DAEMON");
-       ScriptGlobal::Set("FacilityFtp", "LOG_FTP");
-       ScriptGlobal::Set("FacilityKern", "LOG_KERN");
-       ScriptGlobal::Set("FacilityLocal0", "LOG_LOCAL0");
-       ScriptGlobal::Set("FacilityLocal1", "LOG_LOCAL1");
-       ScriptGlobal::Set("FacilityLocal2", "LOG_LOCAL2");
-       ScriptGlobal::Set("FacilityLocal3", "LOG_LOCAL3");
-       ScriptGlobal::Set("FacilityLocal4", "LOG_LOCAL4");
-       ScriptGlobal::Set("FacilityLocal5", "LOG_LOCAL5");
-       ScriptGlobal::Set("FacilityLocal6", "LOG_LOCAL6");
-       ScriptGlobal::Set("FacilityLocal7", "LOG_LOCAL7");
-       ScriptGlobal::Set("FacilityLpr", "LOG_LPR");
-       ScriptGlobal::Set("FacilityMail", "LOG_MAIL");
-       ScriptGlobal::Set("FacilityNews", "LOG_NEWS");
-       ScriptGlobal::Set("FacilitySyslog", "LOG_SYSLOG");
-       ScriptGlobal::Set("FacilityUser", "LOG_USER");
-       ScriptGlobal::Set("FacilityUucp", "LOG_UUCP");
+       ScriptGlobal::Set("System.FacilityAuth", "LOG_AUTH", true);
+       ScriptGlobal::Set("System.FacilityAuthPriv", "LOG_AUTHPRIV", true);
+       ScriptGlobal::Set("System.FacilityCron", "LOG_CRON", true);
+       ScriptGlobal::Set("System.FacilityDaemon", "LOG_DAEMON", true);
+       ScriptGlobal::Set("System.FacilityFtp", "LOG_FTP", true);
+       ScriptGlobal::Set("System.FacilityKern", "LOG_KERN", true);
+       ScriptGlobal::Set("System.FacilityLocal0", "LOG_LOCAL0", true);
+       ScriptGlobal::Set("System.FacilityLocal1", "LOG_LOCAL1", true);
+       ScriptGlobal::Set("System.FacilityLocal2", "LOG_LOCAL2", true);
+       ScriptGlobal::Set("System.FacilityLocal3", "LOG_LOCAL3", true);
+       ScriptGlobal::Set("System.FacilityLocal4", "LOG_LOCAL4", true);
+       ScriptGlobal::Set("System.FacilityLocal5", "LOG_LOCAL5", true);
+       ScriptGlobal::Set("System.FacilityLocal6", "LOG_LOCAL6", true);
+       ScriptGlobal::Set("System.FacilityLocal7", "LOG_LOCAL7", true);
+       ScriptGlobal::Set("System.FacilityLpr", "LOG_LPR", true);
+       ScriptGlobal::Set("System.FacilityMail", "LOG_MAIL", true);
+       ScriptGlobal::Set("System.FacilityNews", "LOG_NEWS", true);
+       ScriptGlobal::Set("System.FacilitySyslog", "LOG_SYSLOG", true);
+       ScriptGlobal::Set("System.FacilityUser", "LOG_USER", true);
+       ScriptGlobal::Set("System.FacilityUucp", "LOG_UUCP", true);
 
        m_FacilityMap["LOG_AUTH"] = LOG_AUTH;
        m_FacilityMap["LOG_AUTHPRIV"] = LOG_AUTHPRIV;
index 62d39c2f44f9e3be37f4675c61bcaeb4dd038454..64d8b17c8e6e3b56f396070211c2719505e7edda 100644 (file)
@@ -145,7 +145,11 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
        if (!success)
                return false;
 
-       Type::Ptr appType = Type::GetByName(ScriptGlobal::Get("ApplicationType", &Empty));
+       Namespace::Ptr systemNS = ScriptGlobal::Get("System");
+       Value vAppType;
+       VERIFY(systemNS->Get("ApplicationType", &vAppType));
+
+       Type::Ptr appType = Type::GetByName(vAppType);
 
        if (ConfigItem::GetItems(appType).empty()) {
                ConfigItemBuilder builder;
index cd3656c1f044257fe87799f524a4bd1c8cb314f5..d64904f538a9e687e42568471ed70d62dcb0acfc 100644 (file)
@@ -29,22 +29,22 @@ std::map<String, int> DbQuery::m_CategoryFilterMap;
 
 void DbQuery::StaticInitialize()
 {
-       ScriptGlobal::Set("DbCatConfig", DbCatConfig);
-       ScriptGlobal::Set("DbCatState", DbCatState);
-       ScriptGlobal::Set("DbCatAcknowledgement", DbCatAcknowledgement);
-       ScriptGlobal::Set("DbCatComment", DbCatComment);
-       ScriptGlobal::Set("DbCatDowntime", DbCatDowntime);
-       ScriptGlobal::Set("DbCatEventHandler", DbCatEventHandler);
-       ScriptGlobal::Set("DbCatExternalCommand", DbCatExternalCommand);
-       ScriptGlobal::Set("DbCatFlapping", DbCatFlapping);
-       ScriptGlobal::Set("DbCatCheck", DbCatCheck);
-       ScriptGlobal::Set("DbCatLog", DbCatLog);
-       ScriptGlobal::Set("DbCatNotification", DbCatNotification);
-       ScriptGlobal::Set("DbCatProgramStatus", DbCatProgramStatus);
-       ScriptGlobal::Set("DbCatRetention", DbCatRetention);
-       ScriptGlobal::Set("DbCatStateHistory", DbCatStateHistory);
+       ScriptGlobal::Set("Icinga.DbCatConfig", DbCatConfig, true);
+       ScriptGlobal::Set("Icinga.DbCatState", DbCatState, true);
+       ScriptGlobal::Set("Icinga.DbCatAcknowledgement", DbCatAcknowledgement, true);
+       ScriptGlobal::Set("Icinga.DbCatComment", DbCatComment, true);
+       ScriptGlobal::Set("Icinga.DbCatDowntime", DbCatDowntime, true);
+       ScriptGlobal::Set("Icinga.DbCatEventHandler", DbCatEventHandler, true);
+       ScriptGlobal::Set("Icinga.DbCatExternalCommand", DbCatExternalCommand, true);
+       ScriptGlobal::Set("Icinga.DbCatFlapping", DbCatFlapping, true);
+       ScriptGlobal::Set("Icinga.DbCatCheck", DbCatCheck, true);
+       ScriptGlobal::Set("Icinga.DbCatLog", DbCatLog, true);
+       ScriptGlobal::Set("Icinga.DbCatNotification", DbCatNotification, true);
+       ScriptGlobal::Set("Icinga.DbCatProgramStatus", DbCatProgramStatus, true);
+       ScriptGlobal::Set("Icinga.DbCatRetention", DbCatRetention, true);
+       ScriptGlobal::Set("Icinga.DbCatStateHistory", DbCatStateHistory, true);
 
-       ScriptGlobal::Set("DbCatEverything", DbCatEverything);
+       ScriptGlobal::Set("Icinga.DbCatEverything", DbCatEverything, true);
 
        m_CategoryFilterMap["DbCatConfig"] = DbCatConfig;
        m_CategoryFilterMap["DbCatState"] = DbCatState;
index 52b1bb5e36154a0bf4c801010499c4b4abaccebd..e1c8d160ca03c233c77cc7850c054e700b5e20fb 100644 (file)
@@ -26,13 +26,13 @@ using namespace icinga;
 REGISTER_TYPE(CheckResult);
 
 INITIALIZE_ONCE([]() {
-       ScriptGlobal::Set("ServiceOK", ServiceOK);
-       ScriptGlobal::Set("ServiceWarning", ServiceWarning);
-       ScriptGlobal::Set("ServiceCritical", ServiceCritical);
-       ScriptGlobal::Set("ServiceUnknown", ServiceUnknown);
+       ScriptGlobal::Set("Icinga.ServiceOK", ServiceOK, true);
+       ScriptGlobal::Set("Icinga.ServiceWarning", ServiceWarning, true);
+       ScriptGlobal::Set("Icinga.ServiceCritical", ServiceCritical, true);
+       ScriptGlobal::Set("Icinga.ServiceUnknown", ServiceUnknown, true);
 
-       ScriptGlobal::Set("HostUp", HostUp);
-       ScriptGlobal::Set("HostDown", HostDown);
+       ScriptGlobal::Set("Icinga.HostUp", HostUp, true);
+       ScriptGlobal::Set("Icinga.HostDown", HostDown, true);
 })
 
 double CheckResult::CalculateExecutionTime() const
index 4db75d852017e6794a65a4e4609615b1533b0101..fab5187a6b75d4b14db7889a1649c2d2be5f3f37 100644 (file)
@@ -41,7 +41,7 @@ using namespace icinga;
 static Timer::Ptr l_RetentionTimer;
 
 REGISTER_TYPE(IcingaApplication);
-INITIALIZE_ONCE(&IcingaApplication::StaticInitialize);
+INITIALIZE_ONCE_WITH_PRIORITY(&IcingaApplication::StaticInitialize, 50);
 
 void IcingaApplication::StaticInitialize()
 {
@@ -59,9 +59,16 @@ void IcingaApplication::StaticInitialize()
 
        ScriptGlobal::Set("NodeName", node_name);
 
-       ScriptGlobal::Set("ApplicationType", "IcingaApplication");
+       ScriptGlobal::Set("System.ApplicationType", "IcingaApplication", true);
 
-       ScriptGlobal::Set("ApplicationVersion", Application::GetAppVersion());
+       ScriptGlobal::Set("System.ApplicationVersion", Application::GetAppVersion(), true);
+
+       Namespace::Ptr globalNS = ScriptGlobal::GetGlobals();
+
+       auto icingaNSBehavior = new ConstNamespaceBehavior();
+       icingaNSBehavior->Freeze();
+       Namespace::Ptr icingaNS = new Namespace(icingaNSBehavior);
+       globalNS->SetAttribute("Icinga", std::make_shared<ConstEmbeddedNamespaceValue>(icingaNS));
 }
 
 REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);
index ea3fdc90e5dc56ff321bf7292ff9f07f8a6fbb32..a53c17e1224c834f875c1c9fdcde933ea82e1e14 100644 (file)
@@ -79,22 +79,22 @@ Dictionary::Ptr NotificationNameComposer::ParseName(const String& name) const
 
 void Notification::StaticInitialize()
 {
-       ScriptGlobal::Set("OK", "OK");
-       ScriptGlobal::Set("Warning", "Warning");
-       ScriptGlobal::Set("Critical", "Critical");
-       ScriptGlobal::Set("Unknown", "Unknown");
-       ScriptGlobal::Set("Up", "Up");
-       ScriptGlobal::Set("Down", "Down");
-
-       ScriptGlobal::Set("DowntimeStart", "DowntimeStart");
-       ScriptGlobal::Set("DowntimeEnd", "DowntimeEnd");
-       ScriptGlobal::Set("DowntimeRemoved", "DowntimeRemoved");
-       ScriptGlobal::Set("Custom", "Custom");
-       ScriptGlobal::Set("Acknowledgement", "Acknowledgement");
-       ScriptGlobal::Set("Problem", "Problem");
-       ScriptGlobal::Set("Recovery", "Recovery");
-       ScriptGlobal::Set("FlappingStart", "FlappingStart");
-       ScriptGlobal::Set("FlappingEnd", "FlappingEnd");
+       ScriptGlobal::Set("Icinga.OK", "OK", true);
+       ScriptGlobal::Set("Icinga.Warning", "Warning", true);
+       ScriptGlobal::Set("Icinga.Critical", "Critical", true);
+       ScriptGlobal::Set("Icinga.Unknown", "Unknown", true);
+       ScriptGlobal::Set("Icinga.Up", "Up", true);
+       ScriptGlobal::Set("Icinga.Down", "Down", true);
+
+       ScriptGlobal::Set("Icinga.DowntimeStart", "DowntimeStart", true);
+       ScriptGlobal::Set("Icinga.DowntimeEnd", "DowntimeEnd", true);
+       ScriptGlobal::Set("Icinga.DowntimeRemoved", "DowntimeRemoved", true);
+       ScriptGlobal::Set("Icinga.Custom", "Custom", true);
+       ScriptGlobal::Set("Icinga.Acknowledgement", "Acknowledgement", true);
+       ScriptGlobal::Set("Icinga.Problem", "Problem", true);
+       ScriptGlobal::Set("Icinga.Recovery", "Recovery", true);
+       ScriptGlobal::Set("Icinga.FlappingStart", "FlappingStart", true);
+       ScriptGlobal::Set("Icinga.FlappingEnd", "FlappingEnd", true);
 
        m_StateFilterMap["OK"] = StateFilterOK;
        m_StateFilterMap["Warning"] = StateFilterWarning;
index b8057ef18b0bd588f6ae3a7e09a164f087caac91..0f77502b2d19b82b1dcac7e059d851faf1f9e289 100644 (file)
 
 using namespace icinga;
 
-REGISTER_FUNCTION(System, get_host, &Host::GetByName, "name");
-REGISTER_FUNCTION(System, get_service, &ObjectUtils::GetService, "host:name");
-REGISTER_FUNCTION(System, get_services, &ObjectUtils::GetServices, "host");
-REGISTER_FUNCTION(System, get_user, &User::GetByName, "name");
-REGISTER_FUNCTION(System, get_check_command, &CheckCommand::GetByName, "name");
-REGISTER_FUNCTION(System, get_event_command, &EventCommand::GetByName, "name");
-REGISTER_FUNCTION(System, get_notification_command, &NotificationCommand::GetByName, "name");
-REGISTER_FUNCTION(System, get_host_group, &HostGroup::GetByName, "name");
-REGISTER_FUNCTION(System, get_service_group, &ServiceGroup::GetByName, "name");
-REGISTER_FUNCTION(System, get_user_group, &UserGroup::GetByName, "name");
-REGISTER_FUNCTION(System, get_time_period, &TimePeriod::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_host, &Host::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_service, &ObjectUtils::GetService, "host:name");
+REGISTER_FUNCTION(Icinga, get_services, &ObjectUtils::GetServices, "host");
+REGISTER_FUNCTION(Icinga, get_user, &User::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_check_command, &CheckCommand::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_event_command, &EventCommand::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_notification_command, &NotificationCommand::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_host_group, &HostGroup::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_service_group, &ServiceGroup::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_user_group, &UserGroup::GetByName, "name");
+REGISTER_FUNCTION(Icinga, get_time_period, &TimePeriod::GetByName, "name");
 
 Service::Ptr ObjectUtils::GetService(const Value& host, const String& name)
 {