mirror of https://github.com/Icinga/icinga2.git
parent
95093bae3e
commit
5d45c74be3
|
@ -228,21 +228,21 @@ Object::Ptr Array::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("len", new Function("Array#len", WrapFunction(ArrayLen), true));
|
||||
prototype->Set("set", new Function("Array#set", WrapFunction(ArraySet)));
|
||||
prototype->Set("get", new Function("Array#get", WrapFunction(ArrayGet)));
|
||||
prototype->Set("add", new Function("Array#add", WrapFunction(ArrayAdd)));
|
||||
prototype->Set("remove", new Function("Array#remove", WrapFunction(ArrayRemove)));
|
||||
prototype->Set("contains", new Function("Array#contains", WrapFunction(ArrayContains), true));
|
||||
prototype->Set("len", new Function("Array#len", WrapFunction(ArrayLen), {}, true));
|
||||
prototype->Set("set", new Function("Array#set", WrapFunction(ArraySet), { "index", "value" }));
|
||||
prototype->Set("get", new Function("Array#get", WrapFunction(ArrayGet), { "index" }));
|
||||
prototype->Set("add", new Function("Array#add", WrapFunction(ArrayAdd), { "value" }));
|
||||
prototype->Set("remove", new Function("Array#remove", WrapFunction(ArrayRemove), { "index" }));
|
||||
prototype->Set("contains", new Function("Array#contains", WrapFunction(ArrayContains), { "value" }, true));
|
||||
prototype->Set("clear", new Function("Array#clear", WrapFunction(ArrayClear)));
|
||||
prototype->Set("sort", new Function("Array#sort", WrapFunction(ArraySort), true));
|
||||
prototype->Set("shallow_clone", new Function("Array#shallow_clone", WrapFunction(ArrayShallowClone), true));
|
||||
prototype->Set("join", new Function("Array#join", WrapFunction(ArrayJoin), true));
|
||||
prototype->Set("reverse", new Function("Array#reverse", WrapFunction(ArrayReverse), true));
|
||||
prototype->Set("map", new Function("Array#map", WrapFunction(ArrayMap), true));
|
||||
prototype->Set("reduce", new Function("Array#reduce", WrapFunction(ArrayReduce), true));
|
||||
prototype->Set("filter", new Function("Array#filter", WrapFunction(ArrayFilter), true));
|
||||
prototype->Set("unique", new Function("Array#unique", WrapFunction(ArrayUnique), true));
|
||||
prototype->Set("sort", new Function("Array#sort", WrapFunction(ArraySort), { "less_cmp" }, true));
|
||||
prototype->Set("shallow_clone", new Function("Array#shallow_clone", WrapFunction(ArrayShallowClone), {}, true));
|
||||
prototype->Set("join", new Function("Array#join", WrapFunction(ArrayJoin), { "separator" }, true));
|
||||
prototype->Set("reverse", new Function("Array#reverse", WrapFunction(ArrayReverse), {}, true));
|
||||
prototype->Set("map", new Function("Array#map", WrapFunction(ArrayMap), { "func" }, true));
|
||||
prototype->Set("reduce", new Function("Array#reduce", WrapFunction(ArrayReduce), { "reduce" }, true));
|
||||
prototype->Set("filter", new Function("Array#filter", WrapFunction(ArrayFilter), { "func" }, true));
|
||||
prototype->Set("unique", new Function("Array#unique", WrapFunction(ArrayUnique), {}, true));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -38,7 +38,7 @@ Object::Ptr Boolean::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("to_string", new Function("Boolean#to_string", WrapFunction(BooleanToString), true));
|
||||
prototype->Set("to_string", new Function("Boolean#to_string", WrapFunction(BooleanToString), {}, true));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -45,8 +45,8 @@ Object::Ptr ConfigObject::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("modify_attribute", new Function("ConfigObject#modify_attribute", WrapFunction(ConfigObjectModifyAttribute), false));
|
||||
prototype->Set("restore_attribute", new Function("ConfigObject#restore_attribute", WrapFunction(ConfigObjectRestoreAttribute), false));
|
||||
prototype->Set("modify_attribute", new Function("ConfigObject#modify_attribute", WrapFunction(ConfigObjectModifyAttribute), { "attr", "value" }, false));
|
||||
prototype->Set("restore_attribute", new Function("ConfigObject#restore_attribute", WrapFunction(ConfigObjectRestoreAttribute), { "attr", "value" }, false));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -39,7 +39,7 @@ Object::Ptr DateTime::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("format", new Function("DateTime#format", WrapFunction(DateTimeFormat)));
|
||||
prototype->Set("format", new Function("DateTime#format", WrapFunction(DateTimeFormat), { "format" }));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -85,13 +85,13 @@ Object::Ptr Dictionary::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("len", new Function("Dictionary#len", WrapFunction(DictionaryLen), true));
|
||||
prototype->Set("set", new Function("Dictionary#set", WrapFunction(DictionarySet)));
|
||||
prototype->Set("get", new Function("Dictionary#get", WrapFunction(DictionaryGet)));
|
||||
prototype->Set("remove", new Function("Dictionary#remove", WrapFunction(DictionaryRemove)));
|
||||
prototype->Set("contains", new Function("Dictionary#contains", WrapFunction(DictionaryContains), true));
|
||||
prototype->Set("shallow_clone", new Function("Dictionary#shallow_clone", WrapFunction(DictionaryShallowClone), true));
|
||||
prototype->Set("keys", new Function("Dictionary#keys", WrapFunction(DictionaryKeys), true));
|
||||
prototype->Set("len", new Function("Dictionary#len", WrapFunction(DictionaryLen), {}, true));
|
||||
prototype->Set("set", new Function("Dictionary#set", WrapFunction(DictionarySet), { "key", "value" }));
|
||||
prototype->Set("get", new Function("Dictionary#get", WrapFunction(DictionaryGet), { "key" }));
|
||||
prototype->Set("remove", new Function("Dictionary#remove", WrapFunction(DictionaryRemove), { "key" }));
|
||||
prototype->Set("contains", new Function("Dictionary#contains", WrapFunction(DictionaryContains), { "key" }, true));
|
||||
prototype->Set("shallow_clone", new Function("Dictionary#shallow_clone", WrapFunction(DictionaryShallowClone), {}, true));
|
||||
prototype->Set("keys", new Function("Dictionary#keys", WrapFunction(DictionaryKeys), {}, true));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -19,18 +19,21 @@
|
|||
|
||||
#include "base/function.hpp"
|
||||
#include "base/function.tcpp"
|
||||
#include "base/array.hpp"
|
||||
#include "base/scriptframe.hpp"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_TYPE_WITH_PROTOTYPE(Function, Function::GetPrototype());
|
||||
|
||||
Function::Function(const String& name, const Callback& function, bool side_effect_free, bool deprecated)
|
||||
Function::Function(const String& name, const Callback& function, const std::vector<String>& args,
|
||||
bool side_effect_free, bool deprecated)
|
||||
: m_Callback(function)
|
||||
{
|
||||
SetName(name, true);
|
||||
SetSideEffectFree(side_effect_free, true);
|
||||
SetDeprecated(deprecated, true);
|
||||
SetArguments(Array::FromVector(args), true);
|
||||
}
|
||||
|
||||
Value Function::Invoke(const std::vector<Value>& arguments)
|
||||
|
|
|
@ -43,7 +43,8 @@ public:
|
|||
|
||||
typedef boost::function<Value (const std::vector<Value>& arguments)> Callback;
|
||||
|
||||
Function(const String& name, const Callback& function, bool side_effect_free = false, bool deprecated = false);
|
||||
Function(const String& name, const Callback& function, const std::vector<String>& args = std::vector<String>(),
|
||||
bool side_effect_free = false, bool deprecated = false);
|
||||
|
||||
Value Invoke(const std::vector<Value>& arguments = std::vector<Value>());
|
||||
Value Invoke(const Value& otherThis, const std::vector<Value>& arguments = std::vector<Value>());
|
||||
|
@ -66,47 +67,47 @@ private:
|
|||
Callback m_Callback;
|
||||
};
|
||||
|
||||
#define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback) \
|
||||
#define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback, args) \
|
||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), String(args).Split(":"), false); \
|
||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||
}, 10)
|
||||
|
||||
#define REGISTER_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
|
||||
#define REGISTER_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback, args) \
|
||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), String(args).Split(":"), false); \
|
||||
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), String(args).Split(":"), false, true); \
|
||||
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
|
||||
}, 10)
|
||||
|
||||
#define REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
|
||||
#define REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback, args) \
|
||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), String(args).Split(":"), false); \
|
||||
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), String(args).Split(":"), false, true); \
|
||||
ScriptGlobal::Set("Deprecated." #name, dsf); \
|
||||
}, 10)
|
||||
|
||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback) \
|
||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback, args) \
|
||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), String(args).Split(":"), true); \
|
||||
ScriptGlobal::Set(#ns "." #name, sf); \
|
||||
}, 10)
|
||||
|
||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback) \
|
||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_PREFIX(ns, name, callback, args) \
|
||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), String(args).Split(":"), true); \
|
||||
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), String(args).Split(":"), true, true); \
|
||||
ScriptGlobal::Set("Deprecated.__" #name, dsf); \
|
||||
}, 10)
|
||||
|
||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \
|
||||
#define REGISTER_SAFE_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback, args) \
|
||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
|
||||
Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), String(args).Split(":"), true); \
|
||||
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), String(args).Split(":"), true, true); \
|
||||
ScriptGlobal::Set("Deprecated." #name, dsf); \
|
||||
}, 10)
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ abstract class Function
|
|||
[config] String "name";
|
||||
[config] bool side_effect_free;
|
||||
[config] bool deprecated;
|
||||
[config] Array::Ptr arguments;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ INITIALIZE_ONCE([]() {
|
|||
Dictionary::Ptr jsonObj = new Dictionary();
|
||||
|
||||
/* Methods */
|
||||
jsonObj->Set("encode", new Function("Json#encode", WrapFunction(JsonEncodeShim), true));
|
||||
jsonObj->Set("decode", new Function("Json#decode", WrapFunction(JsonDecode), true));
|
||||
jsonObj->Set("encode", new Function("Json#encode", WrapFunction(JsonEncodeShim), { "value" }, true));
|
||||
jsonObj->Set("decode", new Function("Json#decode", WrapFunction(JsonDecode), { "value" }, true));
|
||||
|
||||
ScriptGlobal::Set("Json", jsonObj);
|
||||
});
|
||||
|
|
|
@ -171,27 +171,27 @@ INITIALIZE_ONCE([]() {
|
|||
mathObj->Set("SQRT2", 1.41421356237309504880);
|
||||
|
||||
/* Methods */
|
||||
mathObj->Set("abs", new Function("Math#abs", WrapFunction(MathAbs), true));
|
||||
mathObj->Set("acos", new Function("Math#acos", WrapFunction(MathAcos), true));
|
||||
mathObj->Set("asin", new Function("Math#asin", WrapFunction(MathAsin), true));
|
||||
mathObj->Set("atan", new Function("Math#atan", WrapFunction(MathAtan), true));
|
||||
mathObj->Set("atan2", new Function("Math#atan2", WrapFunction(MathAtan2), true));
|
||||
mathObj->Set("ceil", new Function("Math#ceil", WrapFunction(MathCeil), true));
|
||||
mathObj->Set("cos", new Function("Math#cos", WrapFunction(MathCos), true));
|
||||
mathObj->Set("exp", new Function("Math#exp", WrapFunction(MathExp), true));
|
||||
mathObj->Set("floor", new Function("Math#floor", WrapFunction(MathFloor), true));
|
||||
mathObj->Set("log", new Function("Math#log", WrapFunction(MathLog), true));
|
||||
mathObj->Set("max", new Function("Math#max", WrapFunction(MathMax), true));
|
||||
mathObj->Set("min", new Function("Math#min", WrapFunction(MathMin), true));
|
||||
mathObj->Set("pow", new Function("Math#pow", WrapFunction(MathPow), true));
|
||||
mathObj->Set("random", new Function("Math#random", WrapFunction(MathRandom), true));
|
||||
mathObj->Set("round", new Function("Math#round", WrapFunction(MathRound), true));
|
||||
mathObj->Set("sin", new Function("Math#sin", WrapFunction(MathSin), true));
|
||||
mathObj->Set("sqrt", new Function("Math#sqrt", WrapFunction(MathSqrt), true));
|
||||
mathObj->Set("tan", new Function("Math#tan", WrapFunction(MathTan), true));
|
||||
mathObj->Set("isnan", new Function("Math#isnan", WrapFunction(MathIsnan), true));
|
||||
mathObj->Set("isinf", new Function("Math#isinf", WrapFunction(MathIsinf), true));
|
||||
mathObj->Set("sign", new Function("Math#sign", WrapFunction(MathSign), true));
|
||||
mathObj->Set("abs", new Function("Math#abs", WrapFunction(MathAbs), { "x" }, true));
|
||||
mathObj->Set("acos", new Function("Math#acos", WrapFunction(MathAcos), { "x" }, true));
|
||||
mathObj->Set("asin", new Function("Math#asin", WrapFunction(MathAsin), { "x" }, true));
|
||||
mathObj->Set("atan", new Function("Math#atan", WrapFunction(MathAtan), { "x" }, true));
|
||||
mathObj->Set("atan2", new Function("Math#atan2", WrapFunction(MathAtan2), { "x", "y" }, true));
|
||||
mathObj->Set("ceil", new Function("Math#ceil", WrapFunction(MathCeil), { "x" }, true));
|
||||
mathObj->Set("cos", new Function("Math#cos", WrapFunction(MathCos), { "x" }, true));
|
||||
mathObj->Set("exp", new Function("Math#exp", WrapFunction(MathExp), { "x" }, true));
|
||||
mathObj->Set("floor", new Function("Math#floor", WrapFunction(MathFloor), { "x" }, true));
|
||||
mathObj->Set("log", new Function("Math#log", WrapFunction(MathLog), { "x" }, true));
|
||||
mathObj->Set("max", new Function("Math#max", WrapFunction(MathMax), {}, true));
|
||||
mathObj->Set("min", new Function("Math#min", WrapFunction(MathMin), {}, true));
|
||||
mathObj->Set("pow", new Function("Math#pow", WrapFunction(MathPow), { "x", "y" }, true));
|
||||
mathObj->Set("random", new Function("Math#random", WrapFunction(MathRandom), {}, true));
|
||||
mathObj->Set("round", new Function("Math#round", WrapFunction(MathRound), { "x" }, true));
|
||||
mathObj->Set("sin", new Function("Math#sin", WrapFunction(MathSin), { "x" }, true));
|
||||
mathObj->Set("sqrt", new Function("Math#sqrt", WrapFunction(MathSqrt), { "x" }, true));
|
||||
mathObj->Set("tan", new Function("Math#tan", WrapFunction(MathTan), { "x" }, true));
|
||||
mathObj->Set("isnan", new Function("Math#isnan", WrapFunction(MathIsnan), { "x" }, true));
|
||||
mathObj->Set("isinf", new Function("Math#isinf", WrapFunction(MathIsinf), { "x" }, true));
|
||||
mathObj->Set("sign", new Function("Math#sign", WrapFunction(MathSign), { "x" }, true));
|
||||
|
||||
ScriptGlobal::Set("Math", mathObj);
|
||||
});
|
||||
|
|
|
@ -37,7 +37,7 @@ Object::Ptr Number::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("to_string", new Function("Number#to_string", WrapFunction(NumberToString), true));
|
||||
prototype->Set("to_string", new Function("Number#to_string", WrapFunction(NumberToString), {}, true));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -52,9 +52,9 @@ Object::Ptr Object::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("to_string", new Function("Object#to_string", WrapFunction(ObjectToString), true));
|
||||
prototype->Set("notify_attribute", new Function("Object#notify_attribute", WrapFunction(ObjectNotifyAttribute), false));
|
||||
prototype->Set("clone", new Function("Object#clone", WrapFunction(ObjectClone), true));
|
||||
prototype->Set("to_string", new Function("Object#to_string", WrapFunction(ObjectToString), {}, true));
|
||||
prototype->Set("notify_attribute", new Function("Object#notify_attribute", WrapFunction(ObjectNotifyAttribute), { "attribute" }, false));
|
||||
prototype->Set("clone", new Function("Object#clone", WrapFunction(ObjectClone), {}, true));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -36,36 +36,36 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, regex, &ScriptUtils::Regex);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, match, &Utility::Match);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, cidr_match, &Utility::CidrMatch);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, len, &ScriptUtils::Len);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, union, &ScriptUtils::Union);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, intersection, &ScriptUtils::Intersection);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, log, &ScriptUtils::Log);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, range, &ScriptUtils::Range);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, exit, &Application::Exit);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, typeof, &ScriptUtils::TypeOf);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, keys, &ScriptUtils::Keys);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, random, &Utility::Random);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, get_object, &ScriptUtils::GetObject);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, get_objects, &ScriptUtils::GetObjects);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, assert, &ScriptUtils::Assert);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, string, &ScriptUtils::CastString);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, number, &ScriptUtils::CastNumber);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, bool, &ScriptUtils::CastBool);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, get_time, &Utility::GetTime);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, basename, &Utility::BaseName);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, dirname, &Utility::DirName);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, track_parents, &ScriptUtils::TrackParents);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, escape_shell_cmd, &Utility::EscapeShellCmd);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, escape_shell_arg, &Utility::EscapeShellArg);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, regex, &ScriptUtils::Regex, "pattern:text");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, match, &Utility::Match, "pattern:text");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, cidr_match, &Utility::CidrMatch, "pattern:ip");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, len, &ScriptUtils::Len, "value");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, union, &ScriptUtils::Union, "");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, intersection, &ScriptUtils::Intersection, "");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, log, &ScriptUtils::Log, "severity:facility:value");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, range, &ScriptUtils::Range, "start:end:increment");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, exit, &Application::Exit, "status");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, typeof, &ScriptUtils::TypeOf, "value");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, keys, &ScriptUtils::Keys, "value");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, random, &Utility::Random, "");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, get_object, &ScriptUtils::GetObject, "type:name");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, get_objects, &ScriptUtils::GetObjects, "type");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, assert, &ScriptUtils::Assert, "value");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, string, &ScriptUtils::CastString, "value");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, number, &ScriptUtils::CastNumber, "value");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, bool, &ScriptUtils::CastBool, "value");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, get_time, &Utility::GetTime, "");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, basename, &Utility::BaseName, "path");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, dirname, &Utility::DirName, "path");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim, "component");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, track_parents, &ScriptUtils::TrackParents, "child");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, escape_shell_cmd, &Utility::EscapeShellCmd, "cmd");
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, escape_shell_arg, &Utility::EscapeShellArg, "arg");
|
||||
#ifdef _WIN32
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, escape_create_process_arg, &Utility::EscapeCreateProcessArg);
|
||||
REGISTER_SAFE_SCRIPTFUNCTION_NS(System, escape_create_process_arg, &Utility::EscapeCreateProcessArg, "arg");
|
||||
#endif /* _WIN32 */
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, ptr, &ScriptUtils::Ptr);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, sleep, &Utility::Sleep);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, ptr, &ScriptUtils::Ptr, "object");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, sleep, &Utility::Sleep, "interval");
|
||||
|
||||
String ScriptUtils::CastString(const Value& value)
|
||||
{
|
||||
|
|
|
@ -145,17 +145,17 @@ Object::Ptr String::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("len", new Function("String#len", WrapFunction(StringLen), true));
|
||||
prototype->Set("to_string", new Function("String#to_string", WrapFunction(StringToString), true));
|
||||
prototype->Set("substr", new Function("String#substr", WrapFunction(StringSubstr), true));
|
||||
prototype->Set("upper", new Function("String#upper", WrapFunction(StringUpper), true));
|
||||
prototype->Set("lower", new Function("String#lower", WrapFunction(StringLower), true));
|
||||
prototype->Set("split", new Function("String#split", WrapFunction(StringSplit), true));
|
||||
prototype->Set("find", new Function("String#find", WrapFunction(StringFind), true));
|
||||
prototype->Set("contains", new Function("String#contains", WrapFunction(StringContains), true));
|
||||
prototype->Set("replace", new Function("String#replace", WrapFunction(StringReplace), true));
|
||||
prototype->Set("reverse", new Function("String#reverse", WrapFunction(StringReverse), true));
|
||||
prototype->Set("trim", new Function("String#trim", WrapFunction(StringTrim), true));
|
||||
prototype->Set("len", new Function("String#len", WrapFunction(StringLen), {}, true));
|
||||
prototype->Set("to_string", new Function("String#to_string", WrapFunction(StringToString), {}, true));
|
||||
prototype->Set("substr", new Function("String#substr", WrapFunction(StringSubstr), { "start", "len" }, true));
|
||||
prototype->Set("upper", new Function("String#upper", WrapFunction(StringUpper), {}, true));
|
||||
prototype->Set("lower", new Function("String#lower", WrapFunction(StringLower), {}, true));
|
||||
prototype->Set("split", new Function("String#split", WrapFunction(StringSplit), {}, true));
|
||||
prototype->Set("find", new Function("String#find", WrapFunction(StringFind), { "str", "start" }, true));
|
||||
prototype->Set("contains", new Function("String#contains", WrapFunction(StringContains), { "str" }, true));
|
||||
prototype->Set("replace", new Function("String#replace", WrapFunction(StringReplace), { "search", "replacement" }, true));
|
||||
prototype->Set("reverse", new Function("String#reverse", WrapFunction(StringReverse), {}, true));
|
||||
prototype->Set("trim", new Function("String#trim", WrapFunction(StringTrim), {}, true));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "base/object.hpp"
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <string.h>
|
||||
#include <functional>
|
||||
|
@ -238,6 +239,13 @@ public:
|
|||
return m_Data.substr(first, len);
|
||||
}
|
||||
|
||||
inline std::vector<String> Split(const char *separators) const
|
||||
{
|
||||
std::vector<String> result;
|
||||
boost::algorithm::split(result, m_Data, boost::is_any_of(separators));
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void Replace(SizeType first, SizeType second, const String& str)
|
||||
{
|
||||
m_Data.replace(first, second, str);
|
||||
|
|
|
@ -48,7 +48,7 @@ Object::Ptr TypeType::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("register_attribute_handler", new Function("Type#register_attribute_handler", WrapFunction(TypeRegisterAttributeHandler), false));
|
||||
prototype->Set("register_attribute_handler", new Function("Type#register_attribute_handler", WrapFunction(TypeRegisterAttributeHandler), { "field", "callback" }, false));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -46,7 +46,7 @@ ConfigItem::TypeMap ConfigItem::m_DefaultTemplates;
|
|||
ConfigItem::ItemList ConfigItem::m_UnnamedItems;
|
||||
ConfigItem::IgnoredItemList ConfigItem::m_IgnoredItems;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, run_with_activation_context, &ConfigItem::RunWithActivationContext);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, run_with_activation_context, &ConfigItem::RunWithActivationContext, "func");
|
||||
|
||||
/**
|
||||
* Constructor for the ConfigItem class.
|
||||
|
|
|
@ -113,7 +113,7 @@ public:
|
|||
std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression)
|
||||
{
|
||||
return new Function(name, boost::bind(&FunctionWrapper, _1, args,
|
||||
EvaluateClosedVars(frame, closedVars), expression));
|
||||
EvaluateClosedVars(frame, closedVars), expression), args);
|
||||
}
|
||||
|
||||
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, IdoCheck, &IdoCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, IdoCheck, &IdoCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -39,7 +39,7 @@ Object::Ptr Checkable::GetPrototype(void)
|
|||
|
||||
if (!prototype) {
|
||||
prototype = new Dictionary();
|
||||
prototype->Set("process_check_result", new Function("Checkable#process_check_result", WrapFunction(CheckableProcessCheckResult), false));
|
||||
prototype->Set("process_check_result", new Function("Checkable#process_check_result", WrapFunction(CheckableProcessCheckResult), { "cr" }, false));
|
||||
}
|
||||
|
||||
return prototype;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, LegacyTimePeriod, &LegacyTimePeriod::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, LegacyTimePeriod, &LegacyTimePeriod::ScriptFunc, "tp:begin:end");
|
||||
|
||||
bool LegacyTimePeriod::IsInTimeRange(tm *begin, tm *end, int stride, tm *reference)
|
||||
{
|
||||
|
|
|
@ -29,16 +29,16 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_host, &Host::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_service, &ObjectUtils::GetService);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_user, &User::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_check_command, &CheckCommand::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_event_command, &EventCommand::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_notification_command, &NotificationCommand::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_host_group, &HostGroup::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_service_group, &ServiceGroup::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_user_group, &UserGroup::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_time_period, &TimePeriod::GetByName);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_host, &Host::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_service, &ObjectUtils::GetService, "host:name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_user, &User::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_check_command, &CheckCommand::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_event_command, &EventCommand::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_notification_command, &NotificationCommand::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_host_group, &HostGroup::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_service_group, &ServiceGroup::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_user_group, &UserGroup::GetByName, "name");
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, get_time_period, &TimePeriod::GetByName, "name");
|
||||
|
||||
Service::Ptr ObjectUtils::GetService(const String& host, const String& name)
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
using namespace icinga;
|
||||
|
||||
REGISTER_TYPE(PerfdataValue);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, parse_performance_data, PerfdataValue::Parse);
|
||||
REGISTER_SCRIPTFUNCTION_NS(System, parse_performance_data, PerfdataValue::Parse, "perfdata");
|
||||
|
||||
PerfdataValue::PerfdataValue(void)
|
||||
{ }
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ClrCheck, &ClrCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ClrCheck, &ClrCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
static boost::once_flag l_OnceFlag = BOOST_ONCE_INIT;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterZoneCheck, &ClusterZoneCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterZoneCheck, &ClusterZoneCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, IcingaCheck, &IcingaCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, IcingaCheck, &IcingaCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, NullCheck, &NullCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, NullCheck, &NullCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, NullEvent, &NullEventTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, NullEvent, &NullEventTask::ScriptFunc, "checkable:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void NullEventTask::ScriptFunc(const Checkable::Ptr&, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
{ }
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, PluginCheck, &PluginCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, PluginCheck, &PluginCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, PluginEvent, &PluginEventTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, PluginEvent, &PluginEventTask::ScriptFunc, "checkable:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc, "notification:user:cr:itype:author:comment:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
|
||||
const User::Ptr& user, const CheckResult::Ptr& cr, int itype,
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, RandomCheck, &RandomCheckTask::ScriptFunc);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, RandomCheck, &RandomCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||
|
||||
void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate);
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate, "tp:begin:end");
|
||||
REGISTER_SCRIPTFUNCTION_NS(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate, "tp:begin:end");
|
||||
|
||||
Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double, double)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue