From: Michael Friedrich Date: Fri, 18 Oct 2013 22:19:16 +0000 (+0200) Subject: Add NOTIFICATION{AUTHOR,AUTHORNAME,COMMENT} macros. X-Git-Tag: v0.0.3~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39f11334abcc99c19dda056515517041a8f72fa3;p=icinga2 Add NOTIFICATION{AUTHOR,AUTHORNAME,COMMENT} macros. fixes #4914 --- diff --git a/lib/base/scriptfunctionwrapper.h b/lib/base/scriptfunctionwrapper.h index 4a1e5e33c..694a7dcf4 100644 --- a/lib/base/scriptfunctionwrapper.h +++ b/lib/base/scriptfunctionwrapper.h @@ -185,6 +185,88 @@ boost::function& arguments)> WrapScriptFunction( return boost::bind(&ScriptFunctionWrapperR, function, _1); } +template +Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2, T3, T4), const std::vector& arguments) +{ + if (arguments.size() < 5) + BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); + + function(static_cast(arguments[0]), + static_cast(arguments[1]), + static_cast(arguments[2]), + static_cast(arguments[3]), + static_cast(arguments[4])); + + return Empty; +} + +template +boost::function& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2, T3, T4)) +{ + return boost::bind(&ScriptFunctionWrapperV, function, _1); +} + +template +Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2, T3, T4), const std::vector& arguments) +{ + if (arguments.size() < 5) + BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); + + return function(static_cast(arguments[0]), + static_cast(arguments[1]), + static_cast(arguments[2]), + static_cast(arguments[3]), + static_cast(arguments[4])); +} + +template +boost::function& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2, T3, T4)) +{ + return boost::bind(&ScriptFunctionWrapperR, function, _1); +} + +template +Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2, T3, T4, T5), const std::vector& arguments) +{ + if (arguments.size() < 6) + BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); + + function(static_cast(arguments[0]), + static_cast(arguments[1]), + static_cast(arguments[2]), + static_cast(arguments[3]), + static_cast(arguments[4]), + static_cast(arguments[5])); + + return Empty; +} + +template +boost::function& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2, T3, T4, T5)) +{ + return boost::bind(&ScriptFunctionWrapperV, function, _1); +} + +template +Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2, T3, T4, T5), const std::vector& arguments) +{ + if (arguments.size() < 6) + BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); + + return function(static_cast(arguments[0]), + static_cast(arguments[1]), + static_cast(arguments[2]), + static_cast(arguments[3]), + static_cast(arguments[4]), + static_cast(arguments[5])); +} + +template +boost::function& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2, T3, T4, T5)) +{ + return boost::bind(&ScriptFunctionWrapperR, function, _1); +} + boost::function& arguments)> I2_BASE_API WrapScriptFunction(Value (*function)(const std::vector&)); } diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 3f0ef4f3b..6a0f321e9 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -344,7 +344,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: return; } - command->Execute(GetSelf(), user, cr, type); + command->Execute(GetSelf(), user, cr, type, author, text); { ObjectLock olock(this); diff --git a/lib/icinga/notificationcommand.cpp b/lib/icinga/notificationcommand.cpp index 8639e5810..e9968a5b3 100644 --- a/lib/icinga/notificationcommand.cpp +++ b/lib/icinga/notificationcommand.cpp @@ -25,12 +25,15 @@ using namespace icinga; REGISTER_TYPE(NotificationCommand); Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification, - const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type) + const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type, + const String& author, const String& comment) { std::vector arguments; arguments.push_back(notification); arguments.push_back(user); arguments.push_back(cr); arguments.push_back(type); + arguments.push_back(author); + arguments.push_back(comment); return InvokeMethod("execute", arguments); } diff --git a/lib/icinga/notificationcommand.h b/lib/icinga/notificationcommand.h index 584a4b8b7..47725b947 100644 --- a/lib/icinga/notificationcommand.h +++ b/lib/icinga/notificationcommand.h @@ -40,7 +40,8 @@ public: DECLARE_TYPENAME(NotificationCommand); virtual Dictionary::Ptr Execute(const shared_ptr& notification, - const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type); + const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type, + const String& author, const String& comment); }; } diff --git a/lib/icinga/pluginnotificationtask.cpp b/lib/icinga/pluginnotificationtask.cpp index 4f8f47146..fd26ba4a6 100644 --- a/lib/icinga/pluginnotificationtask.cpp +++ b/lib/icinga/pluginnotificationtask.cpp @@ -34,7 +34,8 @@ using namespace icinga; REGISTER_SCRIPTFUNCTION(PluginNotification, &PluginNotificationTask::ScriptFunc); -void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const User::Ptr& user, const Dictionary::Ptr& cr, int itype) +void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const User::Ptr& user, const Dictionary::Ptr& cr, int itype, + const String& author, const String& comment) { NotificationCommand::Ptr commandObj = notification->GetNotificationCommand(); @@ -46,6 +47,9 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c StaticMacroResolver::Ptr notificationMacroResolver = boost::make_shared(); notificationMacroResolver->Add("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type)); + notificationMacroResolver->Add("NOTIFICATIONAUTHOR", author); + notificationMacroResolver->Add("NOTIFICATIONAUTHORNAME", author); + notificationMacroResolver->Add("NOTIFICATIONCOMMENT", comment); std::vector resolvers; resolvers.push_back(user); diff --git a/lib/icinga/pluginnotificationtask.h b/lib/icinga/pluginnotificationtask.h index 138e1dd89..ef732e017 100644 --- a/lib/icinga/pluginnotificationtask.h +++ b/lib/icinga/pluginnotificationtask.h @@ -35,7 +35,8 @@ class I2_ICINGA_API PluginNotificationTask { public: static void ScriptFunc(const Notification::Ptr& notification, - const User::Ptr& user, const Dictionary::Ptr& cr, int itype); + const User::Ptr& user, const Dictionary::Ptr& cr, int itype, + const String& author, const String& comment); private: PluginNotificationTask(void);