mirror of https://github.com/Icinga/icinga2.git
Implement support for limiting output attributes
refs #9077 fixes #9614
This commit is contained in:
parent
5fd7c42faf
commit
a97782b3e5
|
@ -19,7 +19,20 @@
|
||||||
|
|
||||||
#include "icinga/checkresult.hpp"
|
#include "icinga/checkresult.hpp"
|
||||||
#include "icinga/checkresult.tcpp"
|
#include "icinga/checkresult.tcpp"
|
||||||
|
#include "base/scriptglobal.hpp"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(CheckResult);
|
REGISTER_TYPE(CheckResult);
|
||||||
|
INITIALIZE_ONCE(&CheckResult::StaticInitialize);
|
||||||
|
|
||||||
|
void CheckResult::StaticInitialize(void)
|
||||||
|
{
|
||||||
|
ScriptGlobal::Set("ServiceOK", ServiceOK);
|
||||||
|
ScriptGlobal::Set("ServiceWarning", ServiceWarning);
|
||||||
|
ScriptGlobal::Set("ServiceCritical", ServiceCritical);
|
||||||
|
ScriptGlobal::Set("ServiceUnknown", ServiceUnknown);
|
||||||
|
|
||||||
|
ScriptGlobal::Set("HostUp", HostUp);
|
||||||
|
ScriptGlobal::Set("HostDown", HostDown);
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ class I2_ICINGA_API CheckResult : public ObjectImpl<CheckResult>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_OBJECT(CheckResult);
|
DECLARE_OBJECT(CheckResult);
|
||||||
|
|
||||||
|
static void StaticInitialize(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "remote/filterutility.hpp"
|
#include "remote/filterutility.hpp"
|
||||||
#include "base/serializer.hpp"
|
#include "base/serializer.hpp"
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
@ -40,6 +41,9 @@ bool StatusQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
|
||||||
QueryDescription qd;
|
QueryDescription qd;
|
||||||
qd.Types.insert(type);
|
qd.Types.insert(type);
|
||||||
|
|
||||||
|
std::vector<String> joinTypes;
|
||||||
|
joinTypes.push_back(type->GetName());
|
||||||
|
|
||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
params->Set("type", type->GetName());
|
params->Set("type", type->GetName());
|
||||||
|
@ -56,9 +60,38 @@ bool StatusQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
|
||||||
|
|
||||||
Array::Ptr results = new Array();
|
Array::Ptr results = new Array();
|
||||||
|
|
||||||
|
std::set<String> attrs;
|
||||||
|
Array::Ptr uattrs = params->Get("attrs");
|
||||||
|
|
||||||
|
if (uattrs) {
|
||||||
|
ObjectLock olock(uattrs);
|
||||||
|
BOOST_FOREACH(const String& uattr, uattrs) {
|
||||||
|
attrs.insert(uattr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const DynamicObject::Ptr& obj, objs) {
|
BOOST_FOREACH(const DynamicObject::Ptr& obj, objs) {
|
||||||
Value result1 = Serialize(obj, FAConfig | FAState);
|
BOOST_FOREACH(const String& joinType, joinTypes) {
|
||||||
results->Add(result1);
|
String prefix = joinType;
|
||||||
|
boost::algorithm::to_lower(prefix);
|
||||||
|
|
||||||
|
Dictionary::Ptr result1 = new Dictionary();
|
||||||
|
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
|
||||||
|
Field field = type->GetFieldInfo(fid);
|
||||||
|
|
||||||
|
if ((field.Attributes & (FAConfig|FAState)) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String aname = prefix + "." + field.Name;
|
||||||
|
if (!attrs.empty() && attrs.find(aname) == attrs.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Value val = static_cast<Object::Ptr>(obj)->GetField(fid);
|
||||||
|
Value sval = Serialize(val, FAConfig | FAState);
|
||||||
|
result1->Set(aname, sval);
|
||||||
|
}
|
||||||
|
results->Add(result1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr result = new Dictionary();
|
Dictionary::Ptr result = new Dictionary();
|
||||||
|
|
Loading…
Reference in New Issue