<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 03/02/15 02:28, Maxime Longuet
      wrote:<br>
    </div>
    <blockquote
      cite="mid:C1B4178E-BAA0-45A5-BAE9-0605D32FB06F@itika.net"
      type="cite">
      <pre wrap="">
Anybody have already work with update group from API. I'm search how do you write query param on  :

<a class="moz-txt-link-freetext" href="http://www.rudder-project.org/rudder-api-doc/#api-Groups-updateGroup">http://www.rudder-project.org/rudder-api-doc/#api-Groups-updateGroup</a>


query optional  JSON    

Query to get Nodes. Empty Query is possible, but this group will not have nodes anymore.


I'm think this :

'{"select":"node","composition":"And","where":[{"objectType":"node","attribute":"nodeHostname","comparator":"eq","value":"server01.domaine.com"}]}'



Good ? :)

</pre>
    </blockquote>
    <br>
    You're good :)<br>
    <br>
    I openned that issue (
    <a class="moz-txt-link-freetext" href="http://www.rudder-project.org/redmine/issues/6221">http://www.rudder-project.org/redmine/issues/6221</a> ) to track the
    missing documentation.  <br>
    <br>
    The json structure is organized like that:<br>
    <ul>
      <li>"<b>select</b>" : mandatory value,  "<b>node</b>" or "<b>nodeAndPolicyServer</b>"</li>
      <li>"<b>composition</b>": either "<b>and</b>" or "<b>or</b>".
        Optionnal, default to "and"</li>
      <li>"<b>where</b>": an array of json objects composed of:</li>
      <ul>
        <li>"<b>objectType</b>": the kind of object to look for. They
          are all defined in
          <a class="moz-txt-link-freetext" href="https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/main/scala/com/normation/rudder/domain/queries/DitQueryData.scala">https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/main/scala/com/normation/rudder/domain/queries/DitQueryData.scala</a>
          around line #280 (def objectTypes = Map... ). Some interesting
          ones:</li>
        <ul>
          <li>node : for all the OS, RAM, etc<br>
          </li>
          <li>environmentVariable</li>
          <li>software</li>
        </ul>
        <li>"<b>attribute</b>": the name of the attribute to lookup for
          the given object. The possible names are defined in
          DitQueryData to: it's the huge list of "<span class="pl-en">ObjectCriterion".
            Problem: most use name defined elsewhere in the form of "</span><span
            class="pl-en"><span class="pl-en">A_OS_VERSION" etc. The
              name are defined in one the two files: <br>
            </span></span></li>
        <ul>
          <li><span class="pl-en"><span class="pl-en"><a class="moz-txt-link-freetext" href="https://github.com/Normation/ldap-inventory/blob/branches/rudder/3.0/inventory-repository/src/main/scala/com/normation/inventory/ldap/core/LDAPConstants.scala">https://github.com/Normation/ldap-inventory/blob/branches/rudder/3.0/inventory-repository/src/main/scala/com/normation/inventory/ldap/core/LDAPConstants.scala</a></span></span></li>
          <li><span class="pl-en"><span class="pl-en"><a class="moz-txt-link-freetext" href="https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/main/scala/com/normation/rudder/domain/RudderLDAPConstants.scala">https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/main/scala/com/normation/rudder/domain/RudderLDAPConstants.scala</a></span></span></li>
        </ul>
        <li><span class="pl-en"><span class="pl-en">"<b>comparator</b>":
              the kind of comparator to use:</span></span></li>
        <ul>
          <li>exits / notExists: only check the presence of that kind of
            attribute for the object in the node<br>
            <span class="pl-en"><span class="pl-en"></span></span></li>
          <li><span class="pl-en"><span class="pl-en">eq: equals</span></span></li>
          <li><span class="pl-en"><span class="pl-en">notEq: not equals</span></span></li>
          <li><span class="pl-en"><span class="pl-en">gt / gteq: greater
                than / greater or equals<br>
              </span></span></li>
          <li><span class="pl-en"><span class="pl-en">lt / lteq : lesser
                than / lesser or equals</span></span></li>
          <li><span class="pl-en"><span class="pl-en">regex: match the
                given pattern. The authorized regex are the Java one, as
                defined in
                <a class="moz-txt-link-freetext" href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html</a></span></span></li>
          <li><span class="pl-en"><span class="pl-en">notRegex : all
                entries not matching the given regex</span></span></li>
          <li><span class="pl-s1"><span class="pl-pds"></span></span>and
            there is a special syntax for key=value objects, like "<span
              class="pl-s1">environmentVariable". For them, you use the
              attribute "name.value", the comparator to use, with a new
              one:</span></li>
          <ul>
            <li><span class="pl-s1">hasKey: to only check for the key
                part equals the given value</span></li>
            <li><span class="pl-s1">else, the comparison is done on
                "key=value", and you can do almost anything with regex</span></li>
            <li>Ex:
{"select":"nodeAndPolicyServer","composition":"And","where":[{"objectType":"environmentVariable","attribute":"name.value","comparator":"regex","value":".*NAME=r[o]{2}t"}]}<br>
            </li>
          </ul>
        </ul>
      </ul>
    </ul>
    <br>
    <br>
    There is example in the tests for query:<br>
<a class="moz-txt-link-freetext" href="https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/test/scala/com/normation/rudder/services/queries/TestJsonQueryLexing.scala">https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/test/scala/com/normation/rudder/services/queries/TestJsonQueryLexing.scala</a><br>
<a class="moz-txt-link-freetext" href="https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/test/scala/com/normation/rudder/services/queries/TestQueryProcessor.scala">https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/test/scala/com/normation/rudder/services/queries/TestQueryProcessor.scala</a><br>
    <br>
    So, if you read until hear, you now see that the current format is
    quite ad-hoc - or more preciselly, it reflects far to much the
    underlying storage format. <br>
    A more versatile version is think about, based on the JSON format of
    the node details returned by the API and a XPATH kind of query. But
    well, it's not for now, and the current language is already in the
    nature, so it will be supported :)<br>
    At least, in 3.1 we are going to try to normalize object and
    attribute names so that they match the names in the node details
    returned by the API. <br>
    <br>
    Hope it helps. <br>
    <br>
    <div class="moz-signature">-- <br>
      <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
      <style type="text/css"><!--
    a.redlink:link { color: #962322; text-decoration: none; }
    a.redlink:visited { color: #962322; text-decoration: none; }
    .sig { font-family: sans-serif; font-size: small; }
    .sigsmall { font-family: sans-serif; font-size: x-small; }
  --></style>
      <table width="380" border="0" cellpadding="0" cellspacing="2">
        <tbody>
          <tr>
            <td colspan="2">
              <hr></td>
          </tr>
          <tr>
            <td colspan="2"><b><img alt=""
                  src="cid:part1.03070907.00090506@normation.com"
                  hspace="10" width="50" height="50" align="left"> <span
                  class="sig">François ARMAND</span></b><br>
              <span class="sig"><i>Directeur de la R&D</i></span><br>
              <span class="sig"><a class="redlink"
                  href="http://www.normation.com">Normation</a></span> </td>
          </tr>
          <tr>
            <td colspan="2">
              <hr></td>
          </tr>
          <tr>
            <td colspan="2"><span class="sigsmall"><b>87 rue de Turbigo,
                  75003 Paris, France</b></span></td>
          </tr>
          <tr>
            <td><span class="sigsmall">Telephone:</span></td>
            <td><span class="sigsmall">+33 (0)1 83 62 99 23</span></td>
          </tr>
          <tr>
            <td><span class="sigsmall">Mobile:</span></td>
            <td><span class="sigsmall">+33 (0)6 63 37 60 55</span></td>
          </tr>
          <tr>
            <td colspan="2">
              <hr></td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>