]> granicus.if.org Git - icinga2/commitdiff
Fix URL parameters for filters
authorGunnar Beutner <gunnar@beutner.name>
Thu, 30 Jul 2015 06:30:17 +0000 (08:30 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 30 Jul 2015 06:30:39 +0000 (08:30 +0200)
refs #9077

lib/remote/filterutility.cpp
lib/remote/statusqueryhandler.cpp

index 26d893cfb928e8c51c442a519636589d99d5dcd5..2764b2c0e9a4e7162a47b0d8a856ac70158165ce 100644 (file)
@@ -75,7 +75,7 @@ std::vector<DynamicObject::Ptr> FilterUtility::GetFilterTargets(const QueryDescr
                boost::algorithm::to_lower(attr);
 
                if (query->Contains(attr)) {
-                       String name = query->Get(attr);
+                       String name = HttpUtility::GetLastParameter(query, attr);
                        DynamicObject::Ptr obj = GetObjectByTypeAndName(type->GetName(), name);
                        if (!obj)
                                BOOST_THROW_EXCEPTION(std::invalid_argument("Object does not exist."));
@@ -87,21 +87,28 @@ std::vector<DynamicObject::Ptr> FilterUtility::GetFilterTargets(const QueryDescr
 
                if (query->Contains(attr)) {
                        Array::Ptr names = query->Get(attr);
-                       ObjectLock olock(names);
-                       BOOST_FOREACH(const String& name, names) {
-                               DynamicObject::Ptr obj = GetObjectByTypeAndName(type->GetName(), name);
-                               if (!obj)
-                                       BOOST_THROW_EXCEPTION(std::invalid_argument("Object does not exist."));
-                               result.push_back(obj);
+                       if (names) {
+                               ObjectLock olock(names);
+                               BOOST_FOREACH(const String& name, names) {
+                                       DynamicObject::Ptr obj = GetObjectByTypeAndName(type->GetName(), name);
+                                       if (!obj)
+                                               BOOST_THROW_EXCEPTION(std::invalid_argument("Object does not exist."));
+                                       result.push_back(obj);
+                               }
                        }
                }
        }
 
-       if (query->Contains("filter")) {
+       if (query->Contains("filter") || result.empty()) {
                if (!query->Contains("type"))
                        BOOST_THROW_EXCEPTION(std::invalid_argument("Type must be specified when using a filter."));
 
-               String filter = HttpUtility::GetLastParameter(query, "filter");
+               String filter;
+               if (!query->Contains("filter"))
+                       filter = "true";
+               else
+                       filter = HttpUtility::GetLastParameter(query, "filter");
+
                String type = HttpUtility::GetLastParameter(query, "type");
 
                Log(LogInformation, "FilterUtility", filter);
index d78dac78f6392950b6cd5452231de26175ce38b9..d66d362401ca2b59d4939341dbaec51d9bb1f534 100644 (file)
@@ -52,8 +52,6 @@ bool StatusQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
                String attr = type->GetName();
                boost::algorithm::to_lower(attr);
                params->Set(attr, request.RequestUrl->GetPath()[2]);
-       } else if (!params->Contains("filter")) {
-               params->Set("filter", "true");
        }
 
        std::vector<DynamicObject::Ptr> objs = FilterUtility::GetFilterTargets(qd, params);
@@ -78,10 +76,6 @@ bool StatusQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
                        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;