]> granicus.if.org Git - icinga2/commitdiff
Improve function metadata by adding arguments
authorGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 27 Mar 2017 12:26:56 +0000 (14:26 +0200)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 27 Mar 2017 12:43:19 +0000 (14:43 +0200)
fixes #5087

35 files changed:
lib/base/array-script.cpp
lib/base/boolean-script.cpp
lib/base/configobject-script.cpp
lib/base/datetime-script.cpp
lib/base/dictionary-script.cpp
lib/base/function.cpp
lib/base/function.hpp
lib/base/function.ti
lib/base/json-script.cpp
lib/base/math-script.cpp
lib/base/number-script.cpp
lib/base/object-script.cpp
lib/base/scriptutils.cpp
lib/base/string-script.cpp
lib/base/string.hpp
lib/base/typetype-script.cpp
lib/config/configitem.cpp
lib/config/vmops.hpp
lib/db_ido/idochecktask.cpp
lib/icinga/checkable-script.cpp
lib/icinga/legacytimeperiod.cpp
lib/icinga/objectutils.cpp
lib/icinga/perfdatavalue.cpp
lib/methods/clrchecktask.cpp
lib/methods/clusterchecktask.cpp
lib/methods/clusterzonechecktask.cpp
lib/methods/exceptionchecktask.cpp
lib/methods/icingachecktask.cpp
lib/methods/nullchecktask.cpp
lib/methods/nulleventtask.cpp
lib/methods/pluginchecktask.cpp
lib/methods/plugineventtask.cpp
lib/methods/pluginnotificationtask.cpp
lib/methods/randomchecktask.cpp
lib/methods/timeperiodtask.cpp

index a00d5c2dcd501278ba48178dc5f834ae424dc913..03ae2cae8d83ae2a6ea9e0b148c8d95993d57a94 100644 (file)
@@ -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;
index 5b03ea73fba6b36601ded53516d9687fadc3a1e0..75c979ada254e7e24193323c21a13c71796cf29a 100644 (file)
@@ -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;
index e3450081e78268daf34474bec9e3fb4cf36368ba..dfe4455b6dbaeca0d2cdbfe6309aad6a5402cb21 100644 (file)
@@ -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;
index 35beb06b23b20535086dda69a6879fdd447ff955..7d9a14cc2e3ba2c45d606eff72d68a0c9d9e2a9a 100644 (file)
@@ -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;
index a988ba59a4fb228daf02c8f2e5777266811ebad8..908b719b210f8b249b031e219892bc81c95b8c0c 100644 (file)
@@ -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;
index b9beff6f34f1cf56983c0c64070d743972ed580e..8cc2337742f8abdd326ab0859c52c63ad6832c21 100644 (file)
 
 #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)
index efff4116fb390b4506914cc532b1de30bc04fde5..faf64ad92a86de6e96fec997ac920b20cf3edbd0 100644 (file)
@@ -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)
 
index f51b189b4356fc86fb83df165bdc556b073b5883..b42e90ee824dcb717917875a7eebd4ceb6fda823 100644 (file)
@@ -29,6 +29,7 @@ abstract class Function
        [config] String "name";
        [config] bool side_effect_free;
        [config] bool deprecated;
+       [config] Array::Ptr arguments;
 };
 
 }
index 70c9e3af060b1cbc302bd24f6c41c47098725e30..e342f5ee2ab54660a37c7cf7358d0b295141a488 100644 (file)
@@ -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);
 });
index a25c0e26224809cbf6abc2b7d73372d15a6572b5..eb1f4b44989ffaa0ed81af923df64be6ed88345f 100644 (file)
@@ -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);
 });
index f816796df97a62fcf0a4557e8198380f556f3d81..4366277c74cdb5558108c3e750d55c4791c89277 100644 (file)
@@ -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;
index f905f14217757bb8c8e114d3db1bc1115a2969d7..c8112a402414247dfa378614e3f59bf8479aae96 100644 (file)
@@ -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;
index 3ef5ff3a9bfe77f1e19645b9565f45a6c15f1968..9cbdc1c5f2e9bf5bffc9273a753c177358827dcb 100644 (file)
 
 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)
 {
index 1147de9c4e9088a87030547911bf4c78ca1932cf..e72370e51dc416ed7eac83e527c08b1e65388cba 100644 (file)
@@ -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;
index 38e40a2b88d1a85cb6f4fdfaf5b5f29efda04fee..3016bde34efd07630c5fa7a1c0b4939bfab62876 100644 (file)
@@ -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);
index 60fbcb9d0febf6e7265e35cc6d7f31ef7e8b5e3b..5189845b3e1340505668e52b64cfc6b924a525fb 100644 (file)
@@ -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;
index 86f3118e3dc353499e08dd48f49199c71186604c..d023487f5862ad2f6798aff55d2962ebc2d433e7 100644 (file)
@@ -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.
index 7433b5ef4d347498ad37a03fb1083ce177142789..0c1d45800ac3d3462645d111bf34f4fe358c76fc 100644 (file)
@@ -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,
index f8379dbdde702bf572d38c50d8e5e09195188119..c5766038bf6d01a77f71cd21a8c1ac2941fa618f 100644 (file)
@@ -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)
index c76a61d5d048dbfa549817cc28c6b07ef9a120fd..40626fef916771213347f410586d2e259d97a96c 100644 (file)
@@ -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;
index 4c93daa4a7569b5ecee96e468b34cf1ef4b8949b..6d89839ea69876d2bf99d3bbd38273d59518c00e 100644 (file)
@@ -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)
 {
index eef5fdfdc297b835434b6f07ca6929514df7e991..be58508ba9738f4bf3766bc2323424c26091fc56 100644 (file)
 
 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)
 {
index b41743f276b9e34a265b80708aab79014cf1feb3..d350260bfc988b00cd77459cfee7b3e23a2f02ac 100644 (file)
@@ -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)
 { }
index dac1b37cd518982e92c20227dcef3c3a11cf4d10..576538524baecfb7b79c0343ea9698bfc6e162b7 100644 (file)
@@ -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;
 
index 5b296bcbb25da49828b6787dcccd914c0e6ec4cf..2ad7f6578c567823890f20839d19fc92b2b6c03f 100644 (file)
@@ -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)
index a19464fd5f2c92989937289677bbb20cace5be12..f91c5259c99c4dfa294d3b7533d544ee7a1a647d 100644 (file)
@@ -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)
index 83801bf31fd99b7953ecbbd627d2b145fb86b2b4..0410621ab8535c484962503651375349d6acc93e 100644 (file)
@@ -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)
index c475ac88fb58a1bbef0a01f5e261f214f8295382..7b5c54ec3b37e4fdbcb64ba4668774202133de0e 100644 (file)
@@ -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)
index 48ab036b3a4ea04594616b74a652e5c2434f501c..564f3daf87599300cf0caec0c180b68830447273 100644 (file)
@@ -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)
index 98ef729e9d9abb4a63c0f030eee3f7fdff380ad4..2d56e8a34d955fb4891875166e2ef8c4801fe174 100644 (file)
@@ -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)
 { }
index 96631f8ffb1f142f0c7d3fb135fe7f370731bd47..abf2b0cd511cd33d4b64579268290deeb8c765d3 100644 (file)
@@ -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)
index 56698dfda950ba1cf10bf135454ea557e2897670..48a0b9ce05649c2e7bc03a9344c1b52784c98c60 100644 (file)
@@ -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)
index 64cbb2ca217a69306d6cb433bd5acec658ee6443..42403e7bbe8fe5bf3ea17b132b3da4ad2c885548 100644 (file)
@@ -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,
index 9fd01879572e6222d4f9b0812d532e7a33ce10ce..a0b90ccfe4d3fea8e87b4667cf5030dc92205df9 100644 (file)
@@ -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)
index 09c6693708ca4315d365bc8543ddf0e0cf49dac5..c26b4cedd0506477e918643c79d684ecc1e46524 100644 (file)
@@ -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)
 {