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("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("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("BuildHostName", ICINGA_BUILD_HOST_NAME);
ScriptGlobal::Set("BuildCompilerName", ICINGA_BUILD_COMPILER_NAME);
ScriptGlobal::Set("BuildCompilerVersion", ICINGA_BUILD_COMPILER_VERSION);
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();

View 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);
});
/**

View 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;

View 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;

View 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;

View 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

View 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);

View 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("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("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.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;

View File

@ -29,17 +29,17 @@
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)
{