Add NOTIFICATION{AUTHOR,AUTHORNAME,COMMENT} macros.

fixes #4914
This commit is contained in:
Michael Friedrich 2013-10-19 00:19:16 +02:00
parent 886b1c8dd7
commit 39f11334ab
6 changed files with 96 additions and 5 deletions

View 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); 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>&)); boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(Value (*function)(const std::vector<Value>&));
} }

View File

@ -344,7 +344,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
return; return;
} }
command->Execute(GetSelf(), user, cr, type); command->Execute(GetSelf(), user, cr, type, author, text);
{ {
ObjectLock olock(this); ObjectLock olock(this);

View File

@ -25,12 +25,15 @@ using namespace icinga;
REGISTER_TYPE(NotificationCommand); REGISTER_TYPE(NotificationCommand);
Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification, 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; std::vector<Value> arguments;
arguments.push_back(notification); arguments.push_back(notification);
arguments.push_back(user); arguments.push_back(user);
arguments.push_back(cr); arguments.push_back(cr);
arguments.push_back(type); arguments.push_back(type);
arguments.push_back(author);
arguments.push_back(comment);
return InvokeMethod("execute", arguments); return InvokeMethod("execute", arguments);
} }

View File

@ -40,7 +40,8 @@ public:
DECLARE_TYPENAME(NotificationCommand); DECLARE_TYPENAME(NotificationCommand);
virtual Dictionary::Ptr Execute(const shared_ptr<Notification>& notification, 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);
}; };
} }

View File

@ -34,7 +34,8 @@ using namespace icinga;
REGISTER_SCRIPTFUNCTION(PluginNotification, &PluginNotificationTask::ScriptFunc); 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(); NotificationCommand::Ptr commandObj = notification->GetNotificationCommand();
@ -46,6 +47,9 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c
StaticMacroResolver::Ptr notificationMacroResolver = boost::make_shared<StaticMacroResolver>(); StaticMacroResolver::Ptr notificationMacroResolver = boost::make_shared<StaticMacroResolver>();
notificationMacroResolver->Add("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type)); notificationMacroResolver->Add("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type));
notificationMacroResolver->Add("NOTIFICATIONAUTHOR", author);
notificationMacroResolver->Add("NOTIFICATIONAUTHORNAME", author);
notificationMacroResolver->Add("NOTIFICATIONCOMMENT", comment);
std::vector<MacroResolver::Ptr> resolvers; std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(user); resolvers.push_back(user);

View File

@ -35,7 +35,8 @@ class I2_ICINGA_API PluginNotificationTask
{ {
public: public:
static void ScriptFunc(const Notification::Ptr& notification, 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: private:
PluginNotificationTask(void); PluginNotificationTask(void);