Move constants and functions into different namespaces

This commit is contained in:
Gunnar Beutner 2018-08-07 13:55:41 +02:00
parent 1a8692d972
commit 10d6f70a85
9 changed files with 95 additions and 84 deletions

View File

@ -300,15 +300,15 @@ static int Main()
ScriptGlobal::Set("AttachDebugger", false); ScriptGlobal::Set("AttachDebugger", false);
ScriptGlobal::Set("PlatformKernel", Utility::GetPlatformKernel()); ScriptGlobal::Set("System.PlatformKernel", Utility::GetPlatformKernel(), true);
ScriptGlobal::Set("PlatformKernelVersion", Utility::GetPlatformKernelVersion()); ScriptGlobal::Set("System.PlatformKernelVersion", Utility::GetPlatformKernelVersion(), true);
ScriptGlobal::Set("PlatformName", Utility::GetPlatformName()); ScriptGlobal::Set("System.PlatformName", Utility::GetPlatformName(), true);
ScriptGlobal::Set("PlatformVersion", Utility::GetPlatformVersion()); ScriptGlobal::Set("System.PlatformVersion", Utility::GetPlatformVersion(), true);
ScriptGlobal::Set("PlatformArchitecture", Utility::GetPlatformArchitecture()); ScriptGlobal::Set("System.PlatformArchitecture", Utility::GetPlatformArchitecture(), true);
ScriptGlobal::Set("BuildHostName", ICINGA_BUILD_HOST_NAME); ScriptGlobal::Set("System.BuildHostName", ICINGA_BUILD_HOST_NAME, true);
ScriptGlobal::Set("BuildCompilerName", ICINGA_BUILD_COMPILER_NAME); ScriptGlobal::Set("System.BuildCompilerName", ICINGA_BUILD_COMPILER_NAME, true);
ScriptGlobal::Set("BuildCompilerVersion", ICINGA_BUILD_COMPILER_VERSION); ScriptGlobal::Set("System.BuildCompilerVersion", ICINGA_BUILD_COMPILER_VERSION, true);
if (!autocomplete) if (!autocomplete)
Application::SetResourceLimits(); Application::SetResourceLimits();

View File

@ -49,11 +49,11 @@ bool Logger::m_TimestampEnabled = true;
LogSeverity Logger::m_ConsoleLogSeverity = LogInformation; LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
INITIALIZE_ONCE([]() { INITIALIZE_ONCE([]() {
ScriptGlobal::Set("LogDebug", LogDebug); ScriptGlobal::Set("System.LogDebug", LogDebug, true);
ScriptGlobal::Set("LogNotice", LogNotice); ScriptGlobal::Set("System.LogNotice", LogNotice, true);
ScriptGlobal::Set("LogInformation", LogInformation); ScriptGlobal::Set("System.LogInformation", LogInformation, true);
ScriptGlobal::Set("LogWarning", LogWarning); ScriptGlobal::Set("System.LogWarning", LogWarning, true);
ScriptGlobal::Set("LogCritical", LogCritical); ScriptGlobal::Set("System.LogCritical", LogCritical, true);
}); });
/** /**

View File

@ -35,26 +35,26 @@ std::map<String, int> SyslogLogger::m_FacilityMap;
void SyslogLogger::StaticInitialize() void SyslogLogger::StaticInitialize()
{ {
ScriptGlobal::Set("FacilityAuth", "LOG_AUTH"); ScriptGlobal::Set("System.FacilityAuth", "LOG_AUTH", true);
ScriptGlobal::Set("FacilityAuthPriv", "LOG_AUTHPRIV"); ScriptGlobal::Set("System.FacilityAuthPriv", "LOG_AUTHPRIV", true);
ScriptGlobal::Set("FacilityCron", "LOG_CRON"); ScriptGlobal::Set("System.FacilityCron", "LOG_CRON", true);
ScriptGlobal::Set("FacilityDaemon", "LOG_DAEMON"); ScriptGlobal::Set("System.FacilityDaemon", "LOG_DAEMON", true);
ScriptGlobal::Set("FacilityFtp", "LOG_FTP"); ScriptGlobal::Set("System.FacilityFtp", "LOG_FTP", true);
ScriptGlobal::Set("FacilityKern", "LOG_KERN"); ScriptGlobal::Set("System.FacilityKern", "LOG_KERN", true);
ScriptGlobal::Set("FacilityLocal0", "LOG_LOCAL0"); ScriptGlobal::Set("System.FacilityLocal0", "LOG_LOCAL0", true);
ScriptGlobal::Set("FacilityLocal1", "LOG_LOCAL1"); ScriptGlobal::Set("System.FacilityLocal1", "LOG_LOCAL1", true);
ScriptGlobal::Set("FacilityLocal2", "LOG_LOCAL2"); ScriptGlobal::Set("System.FacilityLocal2", "LOG_LOCAL2", true);
ScriptGlobal::Set("FacilityLocal3", "LOG_LOCAL3"); ScriptGlobal::Set("System.FacilityLocal3", "LOG_LOCAL3", true);
ScriptGlobal::Set("FacilityLocal4", "LOG_LOCAL4"); ScriptGlobal::Set("System.FacilityLocal4", "LOG_LOCAL4", true);
ScriptGlobal::Set("FacilityLocal5", "LOG_LOCAL5"); ScriptGlobal::Set("System.FacilityLocal5", "LOG_LOCAL5", true);
ScriptGlobal::Set("FacilityLocal6", "LOG_LOCAL6"); ScriptGlobal::Set("System.FacilityLocal6", "LOG_LOCAL6", true);
ScriptGlobal::Set("FacilityLocal7", "LOG_LOCAL7"); ScriptGlobal::Set("System.FacilityLocal7", "LOG_LOCAL7", true);
ScriptGlobal::Set("FacilityLpr", "LOG_LPR"); ScriptGlobal::Set("System.FacilityLpr", "LOG_LPR", true);
ScriptGlobal::Set("FacilityMail", "LOG_MAIL"); ScriptGlobal::Set("System.FacilityMail", "LOG_MAIL", true);
ScriptGlobal::Set("FacilityNews", "LOG_NEWS"); ScriptGlobal::Set("System.FacilityNews", "LOG_NEWS", true);
ScriptGlobal::Set("FacilitySyslog", "LOG_SYSLOG"); ScriptGlobal::Set("System.FacilitySyslog", "LOG_SYSLOG", true);
ScriptGlobal::Set("FacilityUser", "LOG_USER"); ScriptGlobal::Set("System.FacilityUser", "LOG_USER", true);
ScriptGlobal::Set("FacilityUucp", "LOG_UUCP"); ScriptGlobal::Set("System.FacilityUucp", "LOG_UUCP", true);
m_FacilityMap["LOG_AUTH"] = LOG_AUTH; m_FacilityMap["LOG_AUTH"] = LOG_AUTH;
m_FacilityMap["LOG_AUTHPRIV"] = LOG_AUTHPRIV; m_FacilityMap["LOG_AUTHPRIV"] = LOG_AUTHPRIV;

View File

@ -145,7 +145,11 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
if (!success) if (!success)
return false; 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()) { if (ConfigItem::GetItems(appType).empty()) {
ConfigItemBuilder builder; ConfigItemBuilder builder;

View File

@ -29,22 +29,22 @@ std::map<String, int> DbQuery::m_CategoryFilterMap;
void DbQuery::StaticInitialize() void DbQuery::StaticInitialize()
{ {
ScriptGlobal::Set("DbCatConfig", DbCatConfig); ScriptGlobal::Set("Icinga.DbCatConfig", DbCatConfig, true);
ScriptGlobal::Set("DbCatState", DbCatState); ScriptGlobal::Set("Icinga.DbCatState", DbCatState, true);
ScriptGlobal::Set("DbCatAcknowledgement", DbCatAcknowledgement); ScriptGlobal::Set("Icinga.DbCatAcknowledgement", DbCatAcknowledgement, true);
ScriptGlobal::Set("DbCatComment", DbCatComment); ScriptGlobal::Set("Icinga.DbCatComment", DbCatComment, true);
ScriptGlobal::Set("DbCatDowntime", DbCatDowntime); ScriptGlobal::Set("Icinga.DbCatDowntime", DbCatDowntime, true);
ScriptGlobal::Set("DbCatEventHandler", DbCatEventHandler); ScriptGlobal::Set("Icinga.DbCatEventHandler", DbCatEventHandler, true);
ScriptGlobal::Set("DbCatExternalCommand", DbCatExternalCommand); ScriptGlobal::Set("Icinga.DbCatExternalCommand", DbCatExternalCommand, true);
ScriptGlobal::Set("DbCatFlapping", DbCatFlapping); ScriptGlobal::Set("Icinga.DbCatFlapping", DbCatFlapping, true);
ScriptGlobal::Set("DbCatCheck", DbCatCheck); ScriptGlobal::Set("Icinga.DbCatCheck", DbCatCheck, true);
ScriptGlobal::Set("DbCatLog", DbCatLog); ScriptGlobal::Set("Icinga.DbCatLog", DbCatLog, true);
ScriptGlobal::Set("DbCatNotification", DbCatNotification); ScriptGlobal::Set("Icinga.DbCatNotification", DbCatNotification, true);
ScriptGlobal::Set("DbCatProgramStatus", DbCatProgramStatus); ScriptGlobal::Set("Icinga.DbCatProgramStatus", DbCatProgramStatus, true);
ScriptGlobal::Set("DbCatRetention", DbCatRetention); ScriptGlobal::Set("Icinga.DbCatRetention", DbCatRetention, true);
ScriptGlobal::Set("DbCatStateHistory", DbCatStateHistory); ScriptGlobal::Set("Icinga.DbCatStateHistory", DbCatStateHistory, true);
ScriptGlobal::Set("DbCatEverything", DbCatEverything); ScriptGlobal::Set("Icinga.DbCatEverything", DbCatEverything, true);
m_CategoryFilterMap["DbCatConfig"] = DbCatConfig; m_CategoryFilterMap["DbCatConfig"] = DbCatConfig;
m_CategoryFilterMap["DbCatState"] = DbCatState; m_CategoryFilterMap["DbCatState"] = DbCatState;

View File

@ -26,13 +26,13 @@ using namespace icinga;
REGISTER_TYPE(CheckResult); REGISTER_TYPE(CheckResult);
INITIALIZE_ONCE([]() { INITIALIZE_ONCE([]() {
ScriptGlobal::Set("ServiceOK", ServiceOK); ScriptGlobal::Set("Icinga.ServiceOK", ServiceOK, true);
ScriptGlobal::Set("ServiceWarning", ServiceWarning); ScriptGlobal::Set("Icinga.ServiceWarning", ServiceWarning, true);
ScriptGlobal::Set("ServiceCritical", ServiceCritical); ScriptGlobal::Set("Icinga.ServiceCritical", ServiceCritical, true);
ScriptGlobal::Set("ServiceUnknown", ServiceUnknown); ScriptGlobal::Set("Icinga.ServiceUnknown", ServiceUnknown, true);
ScriptGlobal::Set("HostUp", HostUp); ScriptGlobal::Set("Icinga.HostUp", HostUp, true);
ScriptGlobal::Set("HostDown", HostDown); ScriptGlobal::Set("Icinga.HostDown", HostDown, true);
}) })
double CheckResult::CalculateExecutionTime() const double CheckResult::CalculateExecutionTime() const

View File

@ -41,7 +41,7 @@ using namespace icinga;
static Timer::Ptr l_RetentionTimer; static Timer::Ptr l_RetentionTimer;
REGISTER_TYPE(IcingaApplication); REGISTER_TYPE(IcingaApplication);
INITIALIZE_ONCE(&IcingaApplication::StaticInitialize); INITIALIZE_ONCE_WITH_PRIORITY(&IcingaApplication::StaticInitialize, 50);
void IcingaApplication::StaticInitialize() void IcingaApplication::StaticInitialize()
{ {
@ -59,9 +59,16 @@ void IcingaApplication::StaticInitialize()
ScriptGlobal::Set("NodeName", node_name); 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); REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);

View File

@ -79,22 +79,22 @@ Dictionary::Ptr NotificationNameComposer::ParseName(const String& name) const
void Notification::StaticInitialize() void Notification::StaticInitialize()
{ {
ScriptGlobal::Set("OK", "OK"); ScriptGlobal::Set("Icinga.OK", "OK", true);
ScriptGlobal::Set("Warning", "Warning"); ScriptGlobal::Set("Icinga.Warning", "Warning", true);
ScriptGlobal::Set("Critical", "Critical"); ScriptGlobal::Set("Icinga.Critical", "Critical", true);
ScriptGlobal::Set("Unknown", "Unknown"); ScriptGlobal::Set("Icinga.Unknown", "Unknown", true);
ScriptGlobal::Set("Up", "Up"); ScriptGlobal::Set("Icinga.Up", "Up", true);
ScriptGlobal::Set("Down", "Down"); ScriptGlobal::Set("Icinga.Down", "Down", true);
ScriptGlobal::Set("DowntimeStart", "DowntimeStart"); ScriptGlobal::Set("Icinga.DowntimeStart", "DowntimeStart", true);
ScriptGlobal::Set("DowntimeEnd", "DowntimeEnd"); ScriptGlobal::Set("Icinga.DowntimeEnd", "DowntimeEnd", true);
ScriptGlobal::Set("DowntimeRemoved", "DowntimeRemoved"); ScriptGlobal::Set("Icinga.DowntimeRemoved", "DowntimeRemoved", true);
ScriptGlobal::Set("Custom", "Custom"); ScriptGlobal::Set("Icinga.Custom", "Custom", true);
ScriptGlobal::Set("Acknowledgement", "Acknowledgement"); ScriptGlobal::Set("Icinga.Acknowledgement", "Acknowledgement", true);
ScriptGlobal::Set("Problem", "Problem"); ScriptGlobal::Set("Icinga.Problem", "Problem", true);
ScriptGlobal::Set("Recovery", "Recovery"); ScriptGlobal::Set("Icinga.Recovery", "Recovery", true);
ScriptGlobal::Set("FlappingStart", "FlappingStart"); ScriptGlobal::Set("Icinga.FlappingStart", "FlappingStart", true);
ScriptGlobal::Set("FlappingEnd", "FlappingEnd"); ScriptGlobal::Set("Icinga.FlappingEnd", "FlappingEnd", true);
m_StateFilterMap["OK"] = StateFilterOK; m_StateFilterMap["OK"] = StateFilterOK;
m_StateFilterMap["Warning"] = StateFilterWarning; m_StateFilterMap["Warning"] = StateFilterWarning;

View File

@ -29,17 +29,17 @@
using namespace icinga; using namespace icinga;
REGISTER_FUNCTION(System, get_host, &Host::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_host, &Host::GetByName, "name");
REGISTER_FUNCTION(System, get_service, &ObjectUtils::GetService, "host:name"); REGISTER_FUNCTION(Icinga, get_service, &ObjectUtils::GetService, "host:name");
REGISTER_FUNCTION(System, get_services, &ObjectUtils::GetServices, "host"); REGISTER_FUNCTION(Icinga, get_services, &ObjectUtils::GetServices, "host");
REGISTER_FUNCTION(System, get_user, &User::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_user, &User::GetByName, "name");
REGISTER_FUNCTION(System, get_check_command, &CheckCommand::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_check_command, &CheckCommand::GetByName, "name");
REGISTER_FUNCTION(System, get_event_command, &EventCommand::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_event_command, &EventCommand::GetByName, "name");
REGISTER_FUNCTION(System, get_notification_command, &NotificationCommand::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_notification_command, &NotificationCommand::GetByName, "name");
REGISTER_FUNCTION(System, get_host_group, &HostGroup::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_host_group, &HostGroup::GetByName, "name");
REGISTER_FUNCTION(System, get_service_group, &ServiceGroup::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_service_group, &ServiceGroup::GetByName, "name");
REGISTER_FUNCTION(System, get_user_group, &UserGroup::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_user_group, &UserGroup::GetByName, "name");
REGISTER_FUNCTION(System, get_time_period, &TimePeriod::GetByName, "name"); REGISTER_FUNCTION(Icinga, get_time_period, &TimePeriod::GetByName, "name");
Service::Ptr ObjectUtils::GetService(const Value& host, const String& name) Service::Ptr ObjectUtils::GetService(const Value& host, const String& name)
{ {