m_CheckTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::CheckTimerHandler, this));
m_CheckTimer->Start();
- /* TODO: figure out a way to register check types */
- PluginCheckTask::Register();
- NullCheckTask::Register();
-
m_ResultTimer = boost::make_shared<Timer>();
m_ResultTimer->SetInterval(5);
m_ResultTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::ResultTimerHandler, this));
}
#define REGISTER_TYPE_ALIAS(type, alias, attributeDesc) \
- static RegisterTypeHelper g_Register ## type(alias, DynamicObjectFactory<type>, attributeDesc, (attributeDesc == NULL) ? 0 : sizeof(attributeDesc) / sizeof((static_cast<AttributeDescription *>(attributeDesc))[0]))
+ static RegisterTypeHelper g_RegisterDT_ ## type(alias, DynamicObjectFactory<type>, attributeDesc, (attributeDesc == NULL) ? 0 : sizeof(attributeDesc) / sizeof((static_cast<AttributeDescription *>(attributeDesc))[0]))
#define REGISTER_TYPE(type, attributeDesc) \
REGISTER_TYPE_ALIAS(type, #type, attributeDesc)
static map<String, ScriptFunction::Ptr> m_Functions;
};
+/**
+ * Helper class for registering ScriptFunction implementation classes.
+ *
+ * @ingroup base
+ */
+class RegisterFunctionHelper
+{
+public:
+ RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function)
+ {
+ if (!ScriptFunction::GetByName(name)) {
+ ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(function);
+ ScriptFunction::Register(name, func);
+ }
+ }
+};
+
+#define REGISTER_SCRIPTFUNCTION(name, callback) \
+ static RegisterFunctionHelper g_RegisterSF_ ## type(name, callback)
+
}
#endif /* SCRIPTFUNCTION_H */
-
using namespace icinga;
+REGISTER_SCRIPTFUNCTION("native::NullCheck", &NullCheckTask::ScriptFunc);
+
void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
{
if (arguments.size() < 1)
task->FinishResult(cr);
}
-
-void NullCheckTask::Register(void)
-{
- ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
- ScriptFunction::Register("native::NullCheck", func);
-}
class I2_ICINGA_API NullCheckTask
{
public:
- static void Register(void);
-
-private:
static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
};
using namespace icinga;
+REGISTER_SCRIPTFUNCTION("native::PluginCheck", &PluginCheckTask::ScriptFunc);
+
PluginCheckTask::PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process)
: m_Task(task), m_Process(process)
{ }
result->Set("output", text);
result->Set("performance_data_raw", perfdata);
}
-
-void PluginCheckTask::Register(void)
-{
- ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&PluginCheckTask::ScriptFunc);
- ScriptFunction::Register("native::PluginCheck", func);
-}
class I2_ICINGA_API PluginCheckTask
{
public:
- static void Register(void);
+ static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
private:
- static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
static void ProcessFinishedHandler(PluginCheckTask ct);
static void ProcessCheckOutput(const Dictionary::Ptr& result, String& output);