mirror of https://github.com/Icinga/icinga2.git
Implement the __get_object function
This commit is contained in:
parent
43267d7759
commit
e5bd573756
|
@ -24,6 +24,7 @@
|
||||||
#include "base/json.hpp"
|
#include "base/json.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
|
#include "base/dynamictype.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -42,6 +43,7 @@ REGISTER_SCRIPTFUNCTION(exit, &ScriptUtils::Exit);
|
||||||
REGISTER_SCRIPTFUNCTION(typeof, &ScriptUtils::TypeOf);
|
REGISTER_SCRIPTFUNCTION(typeof, &ScriptUtils::TypeOf);
|
||||||
REGISTER_SCRIPTFUNCTION(keys, &ScriptUtils::Keys);
|
REGISTER_SCRIPTFUNCTION(keys, &ScriptUtils::Keys);
|
||||||
REGISTER_SCRIPTFUNCTION(random, &Utility::Random);
|
REGISTER_SCRIPTFUNCTION(random, &Utility::Random);
|
||||||
|
REGISTER_SCRIPTFUNCTION(__get_object, &ScriptUtils::GetObject);
|
||||||
|
|
||||||
bool ScriptUtils::Regex(const String& pattern, const String& text)
|
bool ScriptUtils::Regex(const String& pattern, const String& text)
|
||||||
{
|
{
|
||||||
|
@ -210,3 +212,13 @@ Array::Ptr ScriptUtils::Keys(const Dictionary::Ptr& dict)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DynamicObject::Ptr ScriptUtils::GetObject(const String& type, const String& name)
|
||||||
|
{
|
||||||
|
DynamicType::Ptr dtype = DynamicType::GetByName(type);
|
||||||
|
|
||||||
|
if (!dtype)
|
||||||
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type name"));
|
||||||
|
|
||||||
|
return dtype->GetObject(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "base/array.hpp"
|
#include "base/array.hpp"
|
||||||
#include "base/dictionary.hpp"
|
#include "base/dictionary.hpp"
|
||||||
#include "base/type.hpp"
|
#include "base/type.hpp"
|
||||||
|
#include "base/dynamicobject.hpp"
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
@ -44,6 +45,7 @@ public:
|
||||||
static void Exit(int code);
|
static void Exit(int code);
|
||||||
static Type::Ptr TypeOf(const Value& value);
|
static Type::Ptr TypeOf(const Value& value);
|
||||||
static Array::Ptr Keys(const Dictionary::Ptr& dict);
|
static Array::Ptr Keys(const Dictionary::Ptr& dict);
|
||||||
|
static DynamicObject::Ptr GetObject(const String& type, const String& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScriptUtils(void);
|
ScriptUtils(void);
|
||||||
|
|
Loading…
Reference in New Issue