mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
parent
5058c5d75b
commit
b5b09216c6
@ -217,9 +217,8 @@ include(CheckIncludeFileCXX)
|
|||||||
|
|
||||||
check_symbol_exists(__COUNTER__ "" HAVE_COUNTER_MACRO)
|
check_symbol_exists(__COUNTER__ "" HAVE_COUNTER_MACRO)
|
||||||
|
|
||||||
if(NOT HAVE_COUNTER_MACRO AND ICINGA2_UNITY_BUILD)
|
if(NOT HAVE_COUNTER_MACRO)
|
||||||
message(STATUS "Your C/C++ compiler does not support the __COUNTER__ macro. Disabling unity build.")
|
message(FATAL_ERROR "Your C/C++ compiler does not support the __COUNTER__ macro.")
|
||||||
set(ICINGA2_UNITY_BUILD FALSE)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DI2_DEBUG")
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DI2_DEBUG")
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
#cmakedefine HAVE_COUNTER_MACRO
|
|
||||||
#cmakedefine HAVE_BACKTRACE_SYMBOLS
|
#cmakedefine HAVE_BACKTRACE_SYMBOLS
|
||||||
#cmakedefine HAVE_PIPE2
|
#cmakedefine HAVE_PIPE2
|
||||||
#cmakedefine HAVE_VFORK
|
#cmakedefine HAVE_VFORK
|
||||||
|
@ -23,10 +23,19 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&Console::DetectType);
|
|
||||||
|
|
||||||
static ConsoleType l_ConsoleType = Console_Dumb;
|
static ConsoleType l_ConsoleType = Console_Dumb;
|
||||||
|
|
||||||
|
INITIALIZE_ONCE([]() {
|
||||||
|
l_ConsoleType = Console_Dumb;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
if (isatty(1))
|
||||||
|
l_ConsoleType = Console_VT100;
|
||||||
|
#else /* _WIN32 */
|
||||||
|
l_ConsoleType = Console_Windows;
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
});
|
||||||
|
|
||||||
ConsoleColorTag::ConsoleColorTag(int color, ConsoleType consoleType)
|
ConsoleColorTag::ConsoleColorTag(int color, ConsoleType consoleType)
|
||||||
: m_Color(color), m_ConsoleType(consoleType)
|
: m_Color(color), m_ConsoleType(consoleType)
|
||||||
{ }
|
{ }
|
||||||
@ -46,18 +55,6 @@ std::ostream& icinga::operator<<(std::ostream& fp, const ConsoleColorTag& cct)
|
|||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::DetectType(void)
|
|
||||||
{
|
|
||||||
l_ConsoleType = Console_Dumb;
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
if (isatty(1))
|
|
||||||
l_ConsoleType = Console_VT100;
|
|
||||||
#else /* _WIN32 */
|
|
||||||
l_ConsoleType = Console_Windows;
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
}
|
|
||||||
|
|
||||||
void Console::SetType(std::ostream& fp, ConsoleType type)
|
void Console::SetType(std::ostream& fp, ConsoleType type)
|
||||||
{
|
{
|
||||||
if (&fp == &std::cout || &fp == &std::cerr)
|
if (&fp == &std::cout || &fp == &std::cerr)
|
||||||
|
@ -67,66 +67,48 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback) \
|
#define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterFunction(void) { \
|
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
||||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||||
} \
|
}, 10)
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
#define REGISTER_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
|
#define REGISTER_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterFunction(void) { \
|
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
||||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||||
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), false, true); \
|
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), false, true); \
|
||||||
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
|
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
|
||||||
} \
|
}, 10)
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
#define REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
|
#define REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterFunction(void) { \
|
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
||||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||||
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), false, true); \
|
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), false, true); \
|
||||||
ScriptGlobal::Set("Deprecated." #name, dsf); \
|
ScriptGlobal::Set("Deprecated." #name, dsf); \
|
||||||
} \
|
}, 10)
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback) \
|
#define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterFunction(void) { \
|
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
||||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||||
} \
|
}, 10)
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
|
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterFunction(void) { \
|
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
||||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||||
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), true, true); \
|
Function::Ptr dsf = new icinga::Function("Deprecated#__" #name " (deprecated)", WrapFunction(callback), true, true); \
|
||||||
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
|
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
|
||||||
} \
|
}, 10)
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
|
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterFunction(void) { \
|
|
||||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
||||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||||
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), true, true); \
|
Function::Ptr dsf = new icinga::Function("Deprecated#" #name " (deprecated)", WrapFunction(callback), true, true); \
|
||||||
ScriptGlobal::Set("Deprecated." #name, dsf); \
|
ScriptGlobal::Set("Deprecated." #name, dsf); \
|
||||||
} \
|
}, 10)
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,7 @@ static String JsonEncodeShim(const Value& value)
|
|||||||
return JsonEncode(value);
|
return JsonEncode(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitializeJsonObj(void)
|
INITIALIZE_ONCE([]() {
|
||||||
{
|
|
||||||
Dictionary::Ptr jsonObj = new Dictionary();
|
Dictionary::Ptr jsonObj = new Dictionary();
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
@ -40,7 +39,4 @@ static void InitializeJsonObj(void)
|
|||||||
jsonObj->Set("decode", new Function("Json#decode", WrapFunction(JsonDecode), true));
|
jsonObj->Set("decode", new Function("Json#decode", WrapFunction(JsonDecode), true));
|
||||||
|
|
||||||
ScriptGlobal::Set("Json", jsonObj);
|
ScriptGlobal::Set("Json", jsonObj);
|
||||||
}
|
});
|
||||||
|
|
||||||
INITIALIZE_ONCE(InitializeJsonObj);
|
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(Logger);
|
REGISTER_TYPE(Logger);
|
||||||
INITIALIZE_ONCE(&Logger::StaticInitialize);
|
|
||||||
|
|
||||||
std::set<Logger::Ptr> Logger::m_Loggers;
|
std::set<Logger::Ptr> Logger::m_Loggers;
|
||||||
boost::mutex Logger::m_Mutex;
|
boost::mutex Logger::m_Mutex;
|
||||||
@ -39,14 +38,13 @@ bool Logger::m_ConsoleLogEnabled = true;
|
|||||||
bool Logger::m_TimestampEnabled = true;
|
bool Logger::m_TimestampEnabled = true;
|
||||||
LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
|
LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
|
||||||
|
|
||||||
void Logger::StaticInitialize(void)
|
INITIALIZE_ONCE([]() {
|
||||||
{
|
|
||||||
ScriptGlobal::Set("LogDebug", LogDebug);
|
ScriptGlobal::Set("LogDebug", LogDebug);
|
||||||
ScriptGlobal::Set("LogNotice", LogNotice);
|
ScriptGlobal::Set("LogNotice", LogNotice);
|
||||||
ScriptGlobal::Set("LogInformation", LogInformation);
|
ScriptGlobal::Set("LogInformation", LogInformation);
|
||||||
ScriptGlobal::Set("LogWarning", LogWarning);
|
ScriptGlobal::Set("LogWarning", LogWarning);
|
||||||
ScriptGlobal::Set("LogCritical", LogCritical);
|
ScriptGlobal::Set("LogCritical", LogCritical);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the Logger class.
|
* Constructor for the Logger class.
|
||||||
|
@ -90,8 +90,6 @@ public:
|
|||||||
static void SetConsoleLogSeverity(LogSeverity logSeverity);
|
static void SetConsoleLogSeverity(LogSeverity logSeverity);
|
||||||
static LogSeverity GetConsoleLogSeverity(void);
|
static LogSeverity GetConsoleLogSeverity(void);
|
||||||
|
|
||||||
static void StaticInitialize(void);
|
|
||||||
|
|
||||||
virtual void ValidateSeverity(const String& value, const ValidationUtils& utils) override;
|
virtual void ValidateSeverity(const String& value, const ValidationUtils& utils) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -158,8 +158,7 @@ static double MathSign(double x)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitializeMathObj(void)
|
INITIALIZE_ONCE([]() {
|
||||||
{
|
|
||||||
Dictionary::Ptr mathObj = new Dictionary();
|
Dictionary::Ptr mathObj = new Dictionary();
|
||||||
|
|
||||||
/* Constants */
|
/* Constants */
|
||||||
@ -196,7 +195,4 @@ static void InitializeMathObj(void)
|
|||||||
mathObj->Set("sign", new Function("Math#sign", WrapFunction(MathSign), true));
|
mathObj->Set("sign", new Function("Math#sign", WrapFunction(MathSign), true));
|
||||||
|
|
||||||
ScriptGlobal::Set("Math", mathObj);
|
ScriptGlobal::Set("Math", mathObj);
|
||||||
}
|
});
|
||||||
|
|
||||||
INITIALIZE_ONCE(InitializeMathObj);
|
|
||||||
|
|
||||||
|
@ -237,14 +237,11 @@ static void TypeInfoTimerHandler(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StartTypeInfoTimer(void)
|
INITIALIZE_ONCE([]() {
|
||||||
{
|
|
||||||
l_ObjectCountTimer = new Timer();
|
l_ObjectCountTimer = new Timer();
|
||||||
l_ObjectCountTimer->SetInterval(10);
|
l_ObjectCountTimer->SetInterval(10);
|
||||||
l_ObjectCountTimer->OnTimerExpired.connect(boost::bind(TypeInfoTimerHandler));
|
l_ObjectCountTimer->OnTimerExpired.connect(boost::bind(TypeInfoTimerHandler));
|
||||||
l_ObjectCountTimer->Start();
|
l_ObjectCountTimer->Start();
|
||||||
}
|
});
|
||||||
|
|
||||||
INITIALIZE_ONCE(StartTypeInfoTimer);
|
|
||||||
#endif /* I2_LEAK_DEBUG */
|
#endif /* I2_LEAK_DEBUG */
|
||||||
|
|
||||||
|
@ -22,15 +22,12 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static void RegisterObjectType(void)
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
{
|
|
||||||
Type::Ptr type = new ObjectType();
|
Type::Ptr type = new ObjectType();
|
||||||
type->SetPrototype(Object::GetPrototype());
|
type->SetPrototype(Object::GetPrototype());
|
||||||
Type::Register(type);
|
Type::Register(type);
|
||||||
Object::TypeInstance = type;
|
Object::TypeInstance = type;
|
||||||
}
|
}, 20);
|
||||||
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(&RegisterObjectType, 20);
|
|
||||||
|
|
||||||
ObjectType::ObjectType(void)
|
ObjectType::ObjectType(void)
|
||||||
{ }
|
{ }
|
||||||
|
@ -49,27 +49,19 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_BUILTIN_TYPE(type, prototype) \
|
#define REGISTER_BUILTIN_TYPE(type, prototype) \
|
||||||
namespace { namespace UNIQUE_NAME(prt) { namespace prt ## type { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterBuiltinType(void) \
|
|
||||||
{ \
|
|
||||||
icinga::Type::Ptr t = new PrimitiveType(#type, "None"); \
|
icinga::Type::Ptr t = new PrimitiveType(#type, "None"); \
|
||||||
t->SetPrototype(prototype); \
|
t->SetPrototype(prototype); \
|
||||||
icinga::Type::Register(t); \
|
icinga::Type::Register(t); \
|
||||||
} \
|
}, 15)
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterBuiltinType, 15); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
#define REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, factory) \
|
#define REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, factory) \
|
||||||
namespace { namespace UNIQUE_NAME(prt) { namespace prt ## type { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterPrimitiveType(void) \
|
|
||||||
{ \
|
|
||||||
icinga::Type::Ptr t = new PrimitiveType(#type, #base, factory); \
|
icinga::Type::Ptr t = new PrimitiveType(#type, #base, factory); \
|
||||||
t->SetPrototype(prototype); \
|
t->SetPrototype(prototype); \
|
||||||
icinga::Type::Register(t); \
|
icinga::Type::Register(t); \
|
||||||
type::TypeInstance = t; \
|
type::TypeInstance = t; \
|
||||||
} \
|
}, 15); \
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterPrimitiveType, 15); \
|
|
||||||
} } } \
|
|
||||||
DEFINE_TYPE_INSTANCE(type)
|
DEFINE_TYPE_INSTANCE(type)
|
||||||
|
|
||||||
#define REGISTER_PRIMITIVE_TYPE(type, base, prototype) \
|
#define REGISTER_PRIMITIVE_TYPE(type, base, prototype) \
|
||||||
|
@ -56,8 +56,6 @@ static std::map<Process::ConsoleHandle, Process::ProcessHandle> l_FDs[IOTHREADS]
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
static boost::once_flag l_OnceFlag = BOOST_ONCE_INIT;
|
static boost::once_flag l_OnceFlag = BOOST_ONCE_INIT;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&Process::StaticInitialize);
|
|
||||||
|
|
||||||
Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& extraEnvironment)
|
Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& extraEnvironment)
|
||||||
: m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment), m_Timeout(600)
|
: m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment), m_Timeout(600)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -76,8 +74,7 @@ Process::~Process(void)
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::StaticInitialize(void)
|
INITIALIZE_ONCE([]() {
|
||||||
{
|
|
||||||
for (int tid = 0; tid < IOTHREADS; tid++) {
|
for (int tid = 0; tid < IOTHREADS; tid++) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
l_Events[tid] = CreateEvent(NULL, TRUE, FALSE, NULL);
|
l_Events[tid] = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
@ -104,7 +101,7 @@ void Process::StaticInitialize(void)
|
|||||||
# endif /* HAVE_PIPE2 */
|
# endif /* HAVE_PIPE2 */
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
void Process::ThreadInitialize(void)
|
void Process::ThreadInitialize(void)
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,6 @@ public:
|
|||||||
|
|
||||||
static Arguments PrepareCommand(const Value& command);
|
static Arguments PrepareCommand(const Value& command);
|
||||||
|
|
||||||
static void StaticInitialize(void);
|
|
||||||
static void ThreadInitialize(void);
|
static void ThreadInitialize(void);
|
||||||
|
|
||||||
static String PrettyPrintArguments(const Arguments& arguments);
|
static String PrettyPrintArguments(const Arguments& arguments);
|
||||||
|
@ -26,22 +26,19 @@ using namespace icinga;
|
|||||||
boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;
|
boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;
|
||||||
Array::Ptr ScriptFrame::m_Imports;
|
Array::Ptr ScriptFrame::m_Imports;
|
||||||
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(&ScriptFrame::StaticInitialize, 50);
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
|
|
||||||
void ScriptFrame::StaticInitialize(void)
|
|
||||||
{
|
|
||||||
Dictionary::Ptr systemNS = new Dictionary();
|
Dictionary::Ptr systemNS = new Dictionary();
|
||||||
ScriptGlobal::Set("System", systemNS);
|
ScriptGlobal::Set("System", systemNS);
|
||||||
AddImport(systemNS);
|
ScriptFrame::AddImport(systemNS);
|
||||||
|
|
||||||
Dictionary::Ptr typesNS = new Dictionary();
|
Dictionary::Ptr typesNS = new Dictionary();
|
||||||
ScriptGlobal::Set("Types", typesNS);
|
ScriptGlobal::Set("Types", typesNS);
|
||||||
AddImport(typesNS);
|
ScriptFrame::AddImport(typesNS);
|
||||||
|
|
||||||
Dictionary::Ptr deprecatedNS = new Dictionary();
|
Dictionary::Ptr deprecatedNS = new Dictionary();
|
||||||
ScriptGlobal::Set("Deprecated", deprecatedNS);
|
ScriptGlobal::Set("Deprecated", deprecatedNS);
|
||||||
AddImport(deprecatedNS);
|
ScriptFrame::AddImport(deprecatedNS);
|
||||||
}
|
}, 50);
|
||||||
|
|
||||||
ScriptFrame::ScriptFrame(void)
|
ScriptFrame::ScriptFrame(void)
|
||||||
: Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
|
: Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
|
||||||
|
@ -40,8 +40,6 @@ struct I2_BASE_API ScriptFrame
|
|||||||
ScriptFrame(const Value& self);
|
ScriptFrame(const Value& self);
|
||||||
~ScriptFrame(void);
|
~ScriptFrame(void);
|
||||||
|
|
||||||
static void StaticInitialize(void);
|
|
||||||
|
|
||||||
void IncreaseStackDepth(void);
|
void IncreaseStackDepth(void);
|
||||||
void DecreaseStackDepth(void);
|
void DecreaseStackDepth(void);
|
||||||
|
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&StackTrace::StaticInitialize);
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma optimize("", off)
|
# pragma optimize("", off)
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
@ -85,13 +83,12 @@ StackTrace::StackTrace(PEXCEPTION_POINTERS exi)
|
|||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
void StackTrace::StaticInitialize(void)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
INITIALIZE_ONCE([]() {
|
||||||
(void) SymSetOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
|
(void) SymSetOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
|
||||||
(void) SymInitialize(GetCurrentProcess(), NULL, TRUE);
|
(void) SymInitialize(GetCurrentProcess(), NULL, TRUE);
|
||||||
|
});
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a stacktrace to the specified stream.
|
* Prints a stacktrace to the specified stream.
|
||||||
|
@ -62,14 +62,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_STATSFUNCTION(name, callback) \
|
#define REGISTER_STATSFUNCTION(name, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(stf) { namespace stf ## name { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterStatsFunction(void) \
|
|
||||||
{ \
|
|
||||||
StatsFunction::Ptr stf = new StatsFunction(callback); \
|
StatsFunction::Ptr stf = new StatsFunction(callback); \
|
||||||
StatsFunctionRegistry::GetInstance()->Register(#name, stf); \
|
StatsFunctionRegistry::GetInstance()->Register(#name, stf); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterStatsFunction); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,15 +25,12 @@ using namespace icinga;
|
|||||||
|
|
||||||
Type::Ptr Type::TypeInstance;
|
Type::Ptr Type::TypeInstance;
|
||||||
|
|
||||||
static void RegisterTypeType(void)
|
INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
||||||
{
|
|
||||||
Type::Ptr type = new TypeType();
|
Type::Ptr type = new TypeType();
|
||||||
type->SetPrototype(TypeType::GetPrototype());
|
type->SetPrototype(TypeType::GetPrototype());
|
||||||
Type::TypeInstance = type;
|
Type::TypeInstance = type;
|
||||||
Type::Register(type);
|
Type::Register(type);
|
||||||
}
|
}, 20);
|
||||||
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterTypeType, 20);
|
|
||||||
|
|
||||||
String Type::ToString(void) const
|
String Type::ToString(void) const
|
||||||
{
|
{
|
||||||
|
@ -138,30 +138,20 @@ class I2_BASE_API TypeImpl
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_TYPE(type) \
|
#define REGISTER_TYPE(type) \
|
||||||
namespace { namespace UNIQUE_NAME(rt) { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterType ## type(void) \
|
|
||||||
{ \
|
|
||||||
icinga::Type::Ptr t = new TypeImpl<type>(); \
|
icinga::Type::Ptr t = new TypeImpl<type>(); \
|
||||||
type::TypeInstance = t; \
|
type::TypeInstance = t; \
|
||||||
icinga::Type::Register(t); \
|
icinga::Type::Register(t); \
|
||||||
} \
|
}, 10); \
|
||||||
\
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterType ## type, 10); \
|
|
||||||
} } \
|
|
||||||
DEFINE_TYPE_INSTANCE(type)
|
DEFINE_TYPE_INSTANCE(type)
|
||||||
|
|
||||||
#define REGISTER_TYPE_WITH_PROTOTYPE(type, prototype) \
|
#define REGISTER_TYPE_WITH_PROTOTYPE(type, prototype) \
|
||||||
namespace { namespace UNIQUE_NAME(rt) { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterType ## type(void) \
|
|
||||||
{ \
|
|
||||||
icinga::Type::Ptr t = new TypeImpl<type>(); \
|
icinga::Type::Ptr t = new TypeImpl<type>(); \
|
||||||
t->SetPrototype(prototype); \
|
t->SetPrototype(prototype); \
|
||||||
type::TypeInstance = t; \
|
type::TypeInstance = t; \
|
||||||
icinga::Type::Register(t); \
|
icinga::Type::Register(t); \
|
||||||
} \
|
}, 10); \
|
||||||
\
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterType ## type, 10); \
|
|
||||||
} } \
|
|
||||||
DEFINE_TYPE_INSTANCE(type)
|
DEFINE_TYPE_INSTANCE(type)
|
||||||
|
|
||||||
#define DEFINE_TYPE_INSTANCE(type) \
|
#define DEFINE_TYPE_INSTANCE(type) \
|
||||||
|
@ -32,10 +32,6 @@
|
|||||||
#define TOKENPASTE(x, y) x ## y
|
#define TOKENPASTE(x, y) x ## y
|
||||||
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
||||||
|
|
||||||
#ifdef HAVE_COUNTER_MACRO
|
|
||||||
#define UNIQUE_NAME(prefix) TOKENPASTE2(prefix, __COUNTER__)
|
#define UNIQUE_NAME(prefix) TOKENPASTE2(prefix, __COUNTER__)
|
||||||
#else /* HAVE_COUNTER_MACRO */
|
|
||||||
# define UNIQUE_NAME(prefix) prefix
|
|
||||||
#endif /* HAVE_COUNTER_MACRO */
|
|
||||||
|
|
||||||
#endif /* VISIBILITY_H */
|
#endif /* VISIBILITY_H */
|
||||||
|
@ -88,15 +88,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_CLICOMMAND(name, klass) \
|
#define REGISTER_CLICOMMAND(name, klass) \
|
||||||
namespace { namespace UNIQUE_NAME(cli) { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterCommand(void) \
|
|
||||||
{ \
|
|
||||||
std::vector<String> vname; \
|
std::vector<String> vname; \
|
||||||
boost::algorithm::split(vname, name, boost::is_any_of("/")); \
|
boost::algorithm::split(vname, name, boost::is_any_of("/")); \
|
||||||
CLICommand::Register(vname, new klass()); \
|
CLICommand::Register(vname, new klass()); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterCommand); \
|
|
||||||
} }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_BLACKANDWHITELIST_CLICOMMAND(type) \
|
#define REGISTER_BLACKANDWHITELIST_CLICOMMAND(type) \
|
||||||
namespace { namespace UNIQUE_NAME(blackandwhitelist) { namespace blackandwhitelist ## type { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterCommand(void) \
|
|
||||||
{ \
|
|
||||||
String ltype = #type; \
|
String ltype = #type; \
|
||||||
boost::algorithm::to_lower(ltype); \
|
boost::algorithm::to_lower(ltype); \
|
||||||
\
|
\
|
||||||
@ -74,9 +72,7 @@ private:
|
|||||||
\
|
\
|
||||||
name[2] = "list"; \
|
name[2] = "list"; \
|
||||||
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandList)); \
|
CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandList)); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterCommand); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,9 +61,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_REPOSITORY_CLICOMMAND(type) \
|
#define REGISTER_REPOSITORY_CLICOMMAND(type) \
|
||||||
namespace { namespace UNIQUE_NAME(repositoryobject) { namespace repositoryobject ## type { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterCommand(void) \
|
|
||||||
{ \
|
|
||||||
String ltype = #type; \
|
String ltype = #type; \
|
||||||
boost::algorithm::to_lower(ltype); \
|
boost::algorithm::to_lower(ltype); \
|
||||||
\
|
\
|
||||||
@ -78,9 +76,7 @@ private:
|
|||||||
\
|
\
|
||||||
name[2] = "list"; \
|
name[2] = "list"; \
|
||||||
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandList)); \
|
CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandList)); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterCommand); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,7 @@
|
|||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
|
|
||||||
#define REGISTER_CONFIG_FRAGMENT(id, name, fragment) \
|
#define REGISTER_CONFIG_FRAGMENT(id, name, fragment) \
|
||||||
namespace { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
void RegisterConfigFragment(void) \
|
|
||||||
{ \
|
|
||||||
icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \
|
icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \
|
||||||
VERIFY(expression); \
|
VERIFY(expression); \
|
||||||
try { \
|
try { \
|
||||||
@ -40,9 +38,6 @@
|
|||||||
icinga::Application::Exit(1); \
|
icinga::Application::Exit(1); \
|
||||||
} \
|
} \
|
||||||
delete expression; \
|
delete expression; \
|
||||||
} \
|
}, 5)
|
||||||
\
|
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY(RegisterConfigFragment, 5); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIGFRAGMENT_H */
|
#endif /* CONFIGFRAGMENT_H */
|
||||||
|
@ -97,14 +97,10 @@ intrusive_ptr<T> DbObjectFactory(const DbType::Ptr& type, const String& name1, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define REGISTER_DBTYPE(name, table, tid, idcolumn, type) \
|
#define REGISTER_DBTYPE(name, table, tid, idcolumn, type) \
|
||||||
namespace { namespace UNIQUE_NAME(ido) { namespace ido ## name { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterDbType(void) \
|
|
||||||
{ \
|
|
||||||
DbType::Ptr dbtype = new DbType(#name, table, tid, idcolumn, DbObjectFactory<type>); \
|
DbType::Ptr dbtype = new DbType(#name, table, tid, idcolumn, DbObjectFactory<type>); \
|
||||||
DbType::RegisterType(dbtype); \
|
DbType::RegisterType(dbtype); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterDbType); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
|
||||||
REGISTER_DBTYPE(Endpoint, "endpoint", DbObjectTypeEndpoint, "endpoint_object_id", EndpointDbObject);
|
REGISTER_DBTYPE(Endpoint, "endpoint", DbObjectTypeEndpoint, "endpoint_object_id", EndpointDbObject);
|
||||||
|
|
||||||
INITIALIZE_ONCE(&EndpointDbObject::StaticInitialize);
|
INITIALIZE_ONCE(&EndpointDbObject::StaticInitialize);
|
||||||
|
@ -27,12 +27,9 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_TYPE(HelloApplication);
|
REGISTER_TYPE(HelloApplication);
|
||||||
|
|
||||||
INITIALIZE_ONCE(&HelloApplication::StaticInitialize);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void HelloApplication::StaticInitialize(void)
|
|
||||||
{
|
|
||||||
ScriptGlobal::Set("ApplicationType", "HelloApplication");
|
ScriptGlobal::Set("ApplicationType", "HelloApplication");
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entry point for the hello application.
|
* The entry point for the hello application.
|
||||||
|
@ -36,8 +36,6 @@ public:
|
|||||||
DECLARE_OBJECT(HelloApplication);
|
DECLARE_OBJECT(HelloApplication);
|
||||||
DECLARE_OBJECTNAME(HelloApplication);
|
DECLARE_OBJECTNAME(HelloApplication);
|
||||||
|
|
||||||
static void StaticInitialize(void);
|
|
||||||
|
|
||||||
virtual int Main(void) override;
|
virtual int Main(void) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,15 +30,12 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&Dependency::RegisterApplyRuleHandler);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void Dependency::RegisterApplyRuleHandler(void)
|
|
||||||
{
|
|
||||||
std::vector<String> targets;
|
std::vector<String> targets;
|
||||||
targets.push_back("Host");
|
targets.push_back("Host");
|
||||||
targets.push_back("Service");
|
targets.push_back("Service");
|
||||||
ApplyRule::RegisterType("Dependency", targets);
|
ApplyRule::RegisterType("Dependency", targets);
|
||||||
}
|
});
|
||||||
|
|
||||||
bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
||||||
{
|
{
|
||||||
|
@ -49,8 +49,6 @@ public:
|
|||||||
|
|
||||||
bool IsAvailable(DependencyType dt) const;
|
bool IsAvailable(DependencyType dt) const;
|
||||||
|
|
||||||
static void RegisterApplyRuleHandler(void);
|
|
||||||
|
|
||||||
virtual void ValidateStates(const Array::Ptr& value, const ValidationUtils& utils) override;
|
virtual void ValidateStates(const Array::Ptr& value, const ValidationUtils& utils) override;
|
||||||
|
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
||||||
|
@ -31,12 +31,9 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_TYPE(HostGroup);
|
REGISTER_TYPE(HostGroup);
|
||||||
|
|
||||||
INITIALIZE_ONCE(&HostGroup::RegisterObjectRuleHandler);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void HostGroup::RegisterObjectRuleHandler(void)
|
|
||||||
{
|
|
||||||
ObjectRule::RegisterType("HostGroup");
|
ObjectRule::RegisterType("HostGroup");
|
||||||
}
|
});
|
||||||
|
|
||||||
bool HostGroup::EvaluateObjectRule(const Host::Ptr& host, const ConfigItem::Ptr& group)
|
bool HostGroup::EvaluateObjectRule(const Host::Ptr& host, const ConfigItem::Ptr& group)
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,6 @@ public:
|
|||||||
|
|
||||||
bool ResolveGroupMembership(const Host::Ptr& host, bool add = true, int rstack = 0);
|
bool ResolveGroupMembership(const Host::Ptr& host, bool add = true, int rstack = 0);
|
||||||
|
|
||||||
static void RegisterObjectRuleHandler(void);
|
|
||||||
|
|
||||||
static void EvaluateObjectRules(const Host::Ptr& host);
|
static void EvaluateObjectRules(const Host::Ptr& host);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -30,15 +30,12 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&Notification::RegisterApplyRuleHandler);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void Notification::RegisterApplyRuleHandler(void)
|
|
||||||
{
|
|
||||||
std::vector<String> targets;
|
std::vector<String> targets;
|
||||||
targets.push_back("Host");
|
targets.push_back("Host");
|
||||||
targets.push_back("Service");
|
targets.push_back("Service");
|
||||||
ApplyRule::RegisterType("Notification", targets);
|
ApplyRule::RegisterType("Notification", targets);
|
||||||
}
|
});
|
||||||
|
|
||||||
bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
||||||
{
|
{
|
||||||
|
@ -104,8 +104,6 @@ public:
|
|||||||
|
|
||||||
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
|
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
|
||||||
|
|
||||||
static void RegisterApplyRuleHandler(void);
|
|
||||||
|
|
||||||
virtual void Validate(int types, const ValidationUtils& utils) override;
|
virtual void Validate(int types, const ValidationUtils& utils) override;
|
||||||
|
|
||||||
virtual void ValidateStates(const Array::Ptr& value, const ValidationUtils& utils) override;
|
virtual void ValidateStates(const Array::Ptr& value, const ValidationUtils& utils) override;
|
||||||
|
@ -29,15 +29,12 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&ScheduledDowntime::RegisterApplyRuleHandler);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void ScheduledDowntime::RegisterApplyRuleHandler(void)
|
|
||||||
{
|
|
||||||
std::vector<String> targets;
|
std::vector<String> targets;
|
||||||
targets.push_back("Host");
|
targets.push_back("Host");
|
||||||
targets.push_back("Service");
|
targets.push_back("Service");
|
||||||
ApplyRule::RegisterType("ScheduledDowntime", targets);
|
ApplyRule::RegisterType("ScheduledDowntime", targets);
|
||||||
}
|
});
|
||||||
|
|
||||||
bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
||||||
{
|
{
|
||||||
|
@ -48,8 +48,6 @@ public:
|
|||||||
|
|
||||||
Checkable::Ptr GetCheckable(void) const;
|
Checkable::Ptr GetCheckable(void) const;
|
||||||
|
|
||||||
static void RegisterApplyRuleHandler(void);
|
|
||||||
|
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
||||||
|
|
||||||
|
@ -29,14 +29,11 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&Service::RegisterApplyRuleHandler);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void Service::RegisterApplyRuleHandler(void)
|
|
||||||
{
|
|
||||||
std::vector<String> targets;
|
std::vector<String> targets;
|
||||||
targets.push_back("Host");
|
targets.push_back("Host");
|
||||||
ApplyRule::RegisterType("Service", targets);
|
ApplyRule::RegisterType("Service", targets);
|
||||||
}
|
});
|
||||||
|
|
||||||
bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule)
|
||||||
{
|
{
|
||||||
|
@ -54,8 +54,6 @@ public:
|
|||||||
static StateType StateTypeFromString(const String& state);
|
static StateType StateTypeFromString(const String& state);
|
||||||
static String StateTypeToString(StateType state);
|
static String StateTypeToString(StateType state);
|
||||||
|
|
||||||
static void RegisterApplyRuleHandler(void);
|
|
||||||
|
|
||||||
static void EvaluateApplyRules(const Host::Ptr& host);
|
static void EvaluateApplyRules(const Host::Ptr& host);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -31,12 +31,9 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_TYPE(ServiceGroup);
|
REGISTER_TYPE(ServiceGroup);
|
||||||
|
|
||||||
INITIALIZE_ONCE(&ServiceGroup::RegisterObjectRuleHandler);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void ServiceGroup::RegisterObjectRuleHandler(void)
|
|
||||||
{
|
|
||||||
ObjectRule::RegisterType("ServiceGroup");
|
ObjectRule::RegisterType("ServiceGroup");
|
||||||
}
|
});
|
||||||
|
|
||||||
bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigItem::Ptr& group)
|
bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigItem::Ptr& group)
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,6 @@ public:
|
|||||||
|
|
||||||
bool ResolveGroupMembership(const Service::Ptr& service, bool add = true, int rstack = 0);
|
bool ResolveGroupMembership(const Service::Ptr& service, bool add = true, int rstack = 0);
|
||||||
|
|
||||||
static void RegisterObjectRuleHandler(void);
|
|
||||||
|
|
||||||
static void EvaluateObjectRules(const Service::Ptr& service);
|
static void EvaluateObjectRules(const Service::Ptr& service);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -31,12 +31,9 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_TYPE(UserGroup);
|
REGISTER_TYPE(UserGroup);
|
||||||
|
|
||||||
INITIALIZE_ONCE(&UserGroup::RegisterObjectRuleHandler);
|
INITIALIZE_ONCE([]() {
|
||||||
|
|
||||||
void UserGroup::RegisterObjectRuleHandler(void)
|
|
||||||
{
|
|
||||||
ObjectRule::RegisterType("UserGroup");
|
ObjectRule::RegisterType("UserGroup");
|
||||||
}
|
});
|
||||||
|
|
||||||
bool UserGroup::EvaluateObjectRule(const User::Ptr& user, const ConfigItem::Ptr& group)
|
bool UserGroup::EvaluateObjectRule(const User::Ptr& user, const ConfigItem::Ptr& group)
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,6 @@ public:
|
|||||||
|
|
||||||
bool ResolveGroupMembership(const User::Ptr& user, bool add = true, int rstack = 0);
|
bool ResolveGroupMembership(const User::Ptr& user, bool add = true, int rstack = 0);
|
||||||
|
|
||||||
static void RegisterObjectRuleHandler(void);
|
|
||||||
|
|
||||||
static void EvaluateObjectRules(const User::Ptr& user);
|
static void EvaluateObjectRules(const User::Ptr& user);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -73,9 +73,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_APIACTION(name, types, callback) \
|
#define REGISTER_APIACTION(name, types, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(apia) { namespace apia ## name { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterAction(void) \
|
|
||||||
{ \
|
|
||||||
String registerName = #name; \
|
String registerName = #name; \
|
||||||
boost::algorithm::replace_all(registerName, "_", "-"); \
|
boost::algorithm::replace_all(registerName, "_", "-"); \
|
||||||
std::vector<String> registerTypes; \
|
std::vector<String> registerTypes; \
|
||||||
@ -84,9 +82,7 @@ public:
|
|||||||
boost::algorithm::split(registerTypes, typeNames, boost::is_any_of(";")); \
|
boost::algorithm::split(registerTypes, typeNames, boost::is_any_of(";")); \
|
||||||
ApiAction::Ptr action = new ApiAction(registerTypes, callback); \
|
ApiAction::Ptr action = new ApiAction(registerTypes, callback); \
|
||||||
ApiActionRegistry::GetInstance()->Register(registerName, action); \
|
ApiActionRegistry::GetInstance()->Register(registerName, action); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterAction); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,14 +67,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_APIFUNCTION(name, ns, callback) \
|
#define REGISTER_APIFUNCTION(name, ns, callback) \
|
||||||
namespace { namespace UNIQUE_NAME(apif) { namespace apif ## name { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterFunction(void) \
|
|
||||||
{ \
|
|
||||||
ApiFunction::Ptr func = new ApiFunction(callback); \
|
ApiFunction::Ptr func = new ApiFunction(callback); \
|
||||||
ApiFunctionRegistry::GetInstance()->Register(#ns "::" #name, func); \
|
ApiFunctionRegistry::GetInstance()->Register(#ns "::" #name, func); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterFunction); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,17 +31,13 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
INITIALIZE_ONCE(&ApiListener::StaticInitialize);
|
|
||||||
|
|
||||||
REGISTER_APIFUNCTION(UpdateObject, config, &ApiListener::ConfigUpdateObjectAPIHandler);
|
REGISTER_APIFUNCTION(UpdateObject, config, &ApiListener::ConfigUpdateObjectAPIHandler);
|
||||||
REGISTER_APIFUNCTION(DeleteObject, config, &ApiListener::ConfigDeleteObjectAPIHandler);
|
REGISTER_APIFUNCTION(DeleteObject, config, &ApiListener::ConfigDeleteObjectAPIHandler);
|
||||||
|
|
||||||
|
INITIALIZE_ONCE([]() {
|
||||||
void ApiListener::StaticInitialize(void)
|
|
||||||
{
|
|
||||||
ConfigObject::OnActiveChanged.connect(&ApiListener::ConfigUpdateObjectHandler);
|
ConfigObject::OnActiveChanged.connect(&ApiListener::ConfigUpdateObjectHandler);
|
||||||
ConfigObject::OnVersionChanged.connect(&ApiListener::ConfigUpdateObjectHandler);
|
ConfigObject::OnVersionChanged.connect(&ApiListener::ConfigUpdateObjectHandler);
|
||||||
}
|
});
|
||||||
|
|
||||||
void ApiListener::ConfigUpdateObjectHandler(const ConfigObject::Ptr& object, const Value& cookie)
|
void ApiListener::ConfigUpdateObjectHandler(const ConfigObject::Ptr& object, const Value& cookie)
|
||||||
{
|
{
|
||||||
|
@ -55,8 +55,6 @@ public:
|
|||||||
DECLARE_OBJECT(ApiListener);
|
DECLARE_OBJECT(ApiListener);
|
||||||
DECLARE_OBJECTNAME(ApiListener);
|
DECLARE_OBJECTNAME(ApiListener);
|
||||||
|
|
||||||
static void StaticInitialize(void);
|
|
||||||
|
|
||||||
static boost::signals2::signal<void(bool)> OnMasterChanged;
|
static boost::signals2::signal<void(bool)> OnMasterChanged;
|
||||||
|
|
||||||
ApiListener(void);
|
ApiListener(void);
|
||||||
|
@ -24,11 +24,6 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
static bool ObjectNameLessComparer(const ConfigObject::Ptr& a, const ConfigObject::Ptr& b)
|
|
||||||
{
|
|
||||||
return a->GetName() < b->GetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApiListener::UpdateObjectAuthority(void)
|
void ApiListener::UpdateObjectAuthority(void)
|
||||||
{
|
{
|
||||||
Zone::Ptr my_zone = Zone::GetLocalZone();
|
Zone::Ptr my_zone = Zone::GetLocalZone();
|
||||||
@ -55,7 +50,11 @@ void ApiListener::UpdateObjectAuthority(void)
|
|||||||
if (num_total > 1 && endpoints.size() <= 1 && (mainTime == 0 || Utility::GetTime() - mainTime < 60))
|
if (num_total > 1 && endpoints.size() <= 1 && (mainTime == 0 || Utility::GetTime() - mainTime < 60))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::sort(endpoints.begin(), endpoints.end(), ObjectNameLessComparer);
|
std::sort(endpoints.begin(), endpoints.end(),
|
||||||
|
[](const ConfigObject::Ptr& a, const ConfigObject::Ptr& b) {
|
||||||
|
return a->GetName() < b->GetName();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
for (const Type::Ptr& type : Type::GetAllTypes()) {
|
||||||
|
@ -57,15 +57,12 @@ static void ScriptFrameCleanupHandler(void)
|
|||||||
l_ApiScriptFrames.erase(key);
|
l_ApiScriptFrames.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitScriptFrameCleanup(void)
|
INITIALIZE_ONCE([]() {
|
||||||
{
|
|
||||||
l_FrameCleanupTimer = new Timer();
|
l_FrameCleanupTimer = new Timer();
|
||||||
l_FrameCleanupTimer->OnTimerExpired.connect(boost::bind(ScriptFrameCleanupHandler));
|
l_FrameCleanupTimer->OnTimerExpired.connect(boost::bind(ScriptFrameCleanupHandler));
|
||||||
l_FrameCleanupTimer->SetInterval(30);
|
l_FrameCleanupTimer->SetInterval(30);
|
||||||
l_FrameCleanupTimer->Start();
|
l_FrameCleanupTimer->Start();
|
||||||
}
|
});
|
||||||
|
|
||||||
INITIALIZE_ONCE(InitScriptFrameCleanup);
|
|
||||||
|
|
||||||
bool ConsoleHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params)
|
bool ConsoleHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params)
|
||||||
{
|
{
|
||||||
|
@ -61,15 +61,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_URLHANDLER(url, klass) \
|
#define REGISTER_URLHANDLER(url, klass) \
|
||||||
namespace { namespace UNIQUE_NAME(apif) { namespace apif ## name { \
|
INITIALIZE_ONCE([]() { \
|
||||||
void RegisterHandler(void) \
|
|
||||||
{ \
|
|
||||||
Url::Ptr uurl = new Url(url); \
|
Url::Ptr uurl = new Url(url); \
|
||||||
HttpHandler::Ptr handler = new klass(); \
|
HttpHandler::Ptr handler = new klass(); \
|
||||||
HttpHandler::Register(uurl, handler); \
|
HttpHandler::Register(uurl, handler); \
|
||||||
} \
|
})
|
||||||
INITIALIZE_ONCE(RegisterHandler); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,15 +31,12 @@ REGISTER_APIFUNCTION(Heartbeat, event, &JsonRpcConnection::HeartbeatAPIHandler);
|
|||||||
|
|
||||||
static Timer::Ptr l_HeartbeatTimer;
|
static Timer::Ptr l_HeartbeatTimer;
|
||||||
|
|
||||||
static void StartHeartbeatTimer(void)
|
INITIALIZE_ONCE([]() {
|
||||||
{
|
|
||||||
l_HeartbeatTimer = new Timer();
|
l_HeartbeatTimer = new Timer();
|
||||||
l_HeartbeatTimer->OnTimerExpired.connect(boost::bind(&JsonRpcConnection::HeartbeatTimerHandler));
|
l_HeartbeatTimer->OnTimerExpired.connect(boost::bind(&JsonRpcConnection::HeartbeatTimerHandler));
|
||||||
l_HeartbeatTimer->SetInterval(10);
|
l_HeartbeatTimer->SetInterval(10);
|
||||||
l_HeartbeatTimer->Start();
|
l_HeartbeatTimer->Start();
|
||||||
}
|
});
|
||||||
|
|
||||||
INITIALIZE_ONCE(StartHeartbeatTimer);
|
|
||||||
|
|
||||||
void JsonRpcConnection::HeartbeatTimerHandler(void)
|
void JsonRpcConnection::HeartbeatTimerHandler(void)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user