mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
parent
baef781a85
commit
2c17305536
@ -205,6 +205,7 @@ string(value) | Converts the value to a string.
|
|||||||
number(value) | Converts the value to a number.
|
number(value) | Converts the value to a number.
|
||||||
bool(value) | Converts to value to a bool.
|
bool(value) | Converts to value to a bool.
|
||||||
log(value) | Writes a message to the log. Non-string values are converted to a JSON string.
|
log(value) | Writes a message to the log. Non-string values are converted to a JSON string.
|
||||||
|
log(severity, facility, value) | Writes a message to the log. `severity` can be one of `LogDebug`, `LogInformation`, `LogWarning` and `LogCritical`. Non-string values are converted to a JSON string.
|
||||||
exit(integer) | Terminates the application.
|
exit(integer) | Terminates the application.
|
||||||
|
|
||||||
### <a id="operators"></a> Dictionary Operators
|
### <a id="operators"></a> Dictionary Operators
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
#include "base/context.h"
|
#include "base/context.h"
|
||||||
#include "base/convert.h"
|
#include "base/convert.h"
|
||||||
|
#include "base/scriptvariable.h"
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -32,11 +33,20 @@
|
|||||||
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;
|
||||||
bool Logger::m_ConsoleLogEnabled = true;
|
bool Logger::m_ConsoleLogEnabled = true;
|
||||||
|
|
||||||
|
void Logger::StaticInitialize(void)
|
||||||
|
{
|
||||||
|
ScriptVariable::Set("LogDebug", LogDebug, true, true);
|
||||||
|
ScriptVariable::Set("LogInformation", LogInformation, true, true);
|
||||||
|
ScriptVariable::Set("LogWarning", LogWarning, true, true);
|
||||||
|
ScriptVariable::Set("LogCritical", LogCritical, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the Logger class.
|
* Constructor for the Logger class.
|
||||||
*/
|
*/
|
||||||
|
@ -69,6 +69,8 @@ public:
|
|||||||
static void DisableConsoleLog(void);
|
static void DisableConsoleLog(void);
|
||||||
static bool IsConsoleLogEnabled(void);
|
static bool IsConsoleLogEnabled(void);
|
||||||
|
|
||||||
|
static void StaticInitialize(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
@ -28,6 +28,13 @@ Value icinga::ScriptFunctionWrapperVV(void (*function)(void), const std::vector<
|
|||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value icinga::ScriptFunctionWrapperVA(void (*function)(const std::vector<Value>&), const std::vector<Value>& arguments)
|
||||||
|
{
|
||||||
|
function(arguments);
|
||||||
|
|
||||||
|
return Empty;
|
||||||
|
}
|
||||||
|
|
||||||
boost::function<Value (const std::vector<Value>& arguments)> icinga::WrapScriptFunction(void (*function)(void))
|
boost::function<Value (const std::vector<Value>& arguments)> icinga::WrapScriptFunction(void (*function)(void))
|
||||||
{
|
{
|
||||||
return boost::bind(&ScriptFunctionWrapperVV, function, _1);
|
return boost::bind(&ScriptFunctionWrapperVV, function, _1);
|
||||||
|
@ -30,6 +30,7 @@ namespace icinga
|
|||||||
{
|
{
|
||||||
|
|
||||||
Value ScriptFunctionWrapperVV(void (*function)(void), const std::vector<Value>& arguments);
|
Value ScriptFunctionWrapperVV(void (*function)(void), const std::vector<Value>& arguments);
|
||||||
|
Value ScriptFunctionWrapperVA(void (*function)(const std::vector<Value>&), const std::vector<Value>& arguments);
|
||||||
|
|
||||||
boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(void (*function)(void));
|
boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(void (*function)(void));
|
||||||
|
|
||||||
@ -273,6 +274,11 @@ boost::function<TR (const std::vector<Value>& arguments)> WrapScriptFunction(TR
|
|||||||
return boost::bind(function, _1);
|
return boost::bind(function, _1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(void (*function)(const std::vector<Value>&))
|
||||||
|
{
|
||||||
|
return boost::bind(&ScriptFunctionWrapperVA, function, _1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SCRIPTFUNCTION_H */
|
#endif /* SCRIPTFUNCTION_H */
|
||||||
|
@ -104,12 +104,30 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptUtils::Log(const Value& message)
|
void ScriptUtils::Log(const std::vector<Value>& arguments)
|
||||||
{
|
{
|
||||||
|
if (arguments.size() != 1 && arguments.size() != 3)
|
||||||
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid number of arguments for log()"));
|
||||||
|
|
||||||
|
LogSeverity severity;
|
||||||
|
String facility;
|
||||||
|
Value message;
|
||||||
|
|
||||||
|
if (arguments.size() == 1) {
|
||||||
|
severity = LogInformation;
|
||||||
|
facility = "config";
|
||||||
|
message = arguments[0];
|
||||||
|
} else {
|
||||||
|
int sval = static_cast<int>(arguments[0]);
|
||||||
|
severity = static_cast<LogSeverity>(sval);
|
||||||
|
facility = arguments[1];
|
||||||
|
message = arguments[2];
|
||||||
|
}
|
||||||
|
|
||||||
if (message.IsString())
|
if (message.IsString())
|
||||||
::Log(LogInformation, "config", message);
|
::Log(severity, facility, message);
|
||||||
else
|
else
|
||||||
::Log(LogInformation, "config", JsonSerialize(message));
|
::Log(severity, facility, JsonSerialize(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptUtils::Exit(int code)
|
void ScriptUtils::Exit(int code)
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
static int Len(const Value& value);
|
static int Len(const Value& value);
|
||||||
static Array::Ptr Union(const std::vector<Value>& arguments);
|
static Array::Ptr Union(const std::vector<Value>& arguments);
|
||||||
static Array::Ptr Intersection(const std::vector<Value>& arguments);
|
static Array::Ptr Intersection(const std::vector<Value>& arguments);
|
||||||
static void Log(const Value& message);
|
static void Log(const std::vector<Value>& arguments);
|
||||||
static void Exit(int code);
|
static void Exit(int code);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user