mirror of https://github.com/Icinga/icinga2.git
Implement REGISTER_SCRIPTFUNCTION() and clean up how check types are registered.
This commit is contained in:
parent
7dc761236d
commit
02de634c12
|
@ -37,10 +37,6 @@ void CheckerComponent::Start(void)
|
||||||
m_CheckTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::CheckTimerHandler, this));
|
m_CheckTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::CheckTimerHandler, this));
|
||||||
m_CheckTimer->Start();
|
m_CheckTimer->Start();
|
||||||
|
|
||||||
/* TODO: figure out a way to register check types */
|
|
||||||
PluginCheckTask::Register();
|
|
||||||
NullCheckTask::Register();
|
|
||||||
|
|
||||||
m_ResultTimer = boost::make_shared<Timer>();
|
m_ResultTimer = boost::make_shared<Timer>();
|
||||||
m_ResultTimer->SetInterval(5);
|
m_ResultTimer->SetInterval(5);
|
||||||
m_ResultTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::ResultTimerHandler, this));
|
m_ResultTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::ResultTimerHandler, this));
|
||||||
|
|
|
@ -100,7 +100,7 @@ shared_ptr<T> DynamicObjectFactory(const Dictionary::Ptr& serializedUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REGISTER_TYPE_ALIAS(type, alias, attributeDesc) \
|
#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) \
|
#define REGISTER_TYPE(type, attributeDesc) \
|
||||||
REGISTER_TYPE_ALIAS(type, #type, attributeDesc)
|
REGISTER_TYPE_ALIAS(type, #type, attributeDesc)
|
||||||
|
|
|
@ -52,7 +52,26 @@ private:
|
||||||
static map<String, ScriptFunction::Ptr> m_Functions;
|
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 */
|
#endif /* SCRIPTFUNCTION_H */
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
REGISTER_SCRIPTFUNCTION("native::NullCheck", &NullCheckTask::ScriptFunc);
|
||||||
|
|
||||||
void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
|
void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
|
||||||
{
|
{
|
||||||
if (arguments.size() < 1)
|
if (arguments.size() < 1)
|
||||||
|
@ -37,9 +39,3 @@ void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>&
|
||||||
|
|
||||||
task->FinishResult(cr);
|
task->FinishResult(cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NullCheckTask::Register(void)
|
|
||||||
{
|
|
||||||
ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
|
|
||||||
ScriptFunction::Register("native::NullCheck", func);
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,9 +31,6 @@ namespace icinga
|
||||||
class I2_ICINGA_API NullCheckTask
|
class I2_ICINGA_API NullCheckTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Register(void);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
|
static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
REGISTER_SCRIPTFUNCTION("native::PluginCheck", &PluginCheckTask::ScriptFunc);
|
||||||
|
|
||||||
PluginCheckTask::PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process)
|
PluginCheckTask::PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process)
|
||||||
: m_Task(task), m_Process(process)
|
: m_Task(task), m_Process(process)
|
||||||
{ }
|
{ }
|
||||||
|
@ -124,9 +126,3 @@ void PluginCheckTask::ProcessCheckOutput(const Dictionary::Ptr& result, String&
|
||||||
result->Set("output", text);
|
result->Set("output", text);
|
||||||
result->Set("performance_data_raw", perfdata);
|
result->Set("performance_data_raw", perfdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginCheckTask::Register(void)
|
|
||||||
{
|
|
||||||
ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&PluginCheckTask::ScriptFunc);
|
|
||||||
ScriptFunction::Register("native::PluginCheck", func);
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,10 +31,9 @@ namespace icinga
|
||||||
class I2_ICINGA_API PluginCheckTask
|
class I2_ICINGA_API PluginCheckTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Register(void);
|
static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
|
|
||||||
|
|
||||||
static void ProcessFinishedHandler(PluginCheckTask ct);
|
static void ProcessFinishedHandler(PluginCheckTask ct);
|
||||||
static void ProcessCheckOutput(const Dictionary::Ptr& result, String& output);
|
static void ProcessCheckOutput(const Dictionary::Ptr& result, String& output);
|
||||||
|
|
Loading…
Reference in New Issue