]> granicus.if.org Git - icinga2/commitdiff
Add NOTIFICATION{AUTHOR,AUTHORNAME,COMMENT} macros.
authorMichael Friedrich <Michael.Friedrich@netways.de>
Fri, 18 Oct 2013 22:19:16 +0000 (00:19 +0200)
committerMichael Friedrich <Michael.Friedrich@netways.de>
Fri, 18 Oct 2013 22:19:16 +0000 (00:19 +0200)
fixes #4914

lib/base/scriptfunctionwrapper.h
lib/icinga/notification.cpp
lib/icinga/notificationcommand.cpp
lib/icinga/notificationcommand.h
lib/icinga/pluginnotificationtask.cpp
lib/icinga/pluginnotificationtask.h

index 4a1e5e33cd094f9cf6c8dc8ca088f30b2525f388..694a7dcf4aa3f862210b8f5daf7a4ef8703f4c2d 100644 (file)
@@ -185,6 +185,88 @@ boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(
        return boost::bind(&ScriptFunctionWrapperR<TR, T0, T1, T2, T3>, function, _1);
 }
 
+template<typename T0, typename T1, typename T2, typename T3, typename T4>
+Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2, T3, T4), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 5)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]),
+           static_cast<T3>(arguments[3]),
+           static_cast<T4>(arguments[4]));
+
+       return Empty;
+}
+
+template<typename T0, typename T1, typename T2, typename T3, typename T4>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2, T3, T4))
+{
+       return boost::bind(&ScriptFunctionWrapperV<T0, T1, T2, T3, T4>, function, _1);
+}
+
+template<typename TR, typename T0, typename T1, typename T2, typename T3, typename T4>
+Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2, T3, T4), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 5)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       return function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]),
+           static_cast<T3>(arguments[3]),
+           static_cast<T4>(arguments[4]));
+}
+
+template<typename TR, typename T0, typename T1, typename T2, typename T3, typename T4>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2, T3, T4))
+{
+       return boost::bind(&ScriptFunctionWrapperR<TR, T0, T1, T2, T3, T4>, function, _1);
+}
+
+template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
+Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2, T3, T4, T5), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 6)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]),
+           static_cast<T3>(arguments[3]),
+           static_cast<T4>(arguments[4]),
+           static_cast<T5>(arguments[5]));
+
+       return Empty;
+}
+
+template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2, T3, T4, T5))
+{
+       return boost::bind(&ScriptFunctionWrapperV<T0, T1, T2, T3, T4, T5>, function, _1);
+}
+
+template<typename TR, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
+Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2, T3, T4, T5), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 6)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       return function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]),
+           static_cast<T3>(arguments[3]),
+           static_cast<T4>(arguments[4]),
+           static_cast<T5>(arguments[5]));
+}
+
+template<typename TR, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2, T3, T4, T5))
+{
+       return boost::bind(&ScriptFunctionWrapperR<TR, T0, T1, T2, T3, T4, T5>, function, _1);
+}
+
 boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(Value (*function)(const std::vector<Value>&));
 
 }
index 3f0ef4f3bc38a17fead9c776e15f0148f974a97c..6a0f321e9a950a1dfa5099b40d791bb923c0851a 100644 (file)
@@ -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);
index 8639e58109e27b55a01fa41b2bef9cefc5a9d084..e9968a5b3bdeaf56bc77597134af0610a77908ec 100644 (file)
@@ -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<Value> 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);
 }
index 584a4b8b7f272520fa00d29ff473676094bc06d4..47725b947fa4d8782a5b2cb0f793d369548a7e92 100644 (file)
@@ -40,7 +40,8 @@ public:
        DECLARE_TYPENAME(NotificationCommand);
 
        virtual Dictionary::Ptr Execute(const shared_ptr<Notification>& 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);
 };
 
 }
index 4f8f47146499efc4f86d5bc981254c56c0f0ece5..fd26ba4a6da0609158429814f50f1247df80f552 100644 (file)
@@ -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<StaticMacroResolver>();
        notificationMacroResolver->Add("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type));
+       notificationMacroResolver->Add("NOTIFICATIONAUTHOR", author);
+       notificationMacroResolver->Add("NOTIFICATIONAUTHORNAME", author);
+       notificationMacroResolver->Add("NOTIFICATIONCOMMENT", comment);
 
        std::vector<MacroResolver::Ptr> resolvers;
        resolvers.push_back(user);
index 138e1dd890ead44b464a86dc0ad9c5cf75d8ed07..ef732e017470f683082940507d0cd9927b37cd19 100644 (file)
@@ -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);