<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Le 24/08/2015 15:36, Julien Escario a
      écrit :<br>
    </div>
    <blockquote cite="mid:55DB1DE7.8000309@azylog.net" type="cite">
      <pre wrap="">Hello,</pre>
    </blockquote>
    Hello Julien !<br>
    <blockquote cite="mid:55DB1DE7.8000309@azylog.net" type="cite">
      <pre wrap="">
I'm currently trying to 'play' a bit with rudder to check if this could help us
to manage our managed servers, all Linux.

My first goal is to get the number of package that should be upgraded on a
machine with 'apt-get upgrade'.
</pre>
    </blockquote>
    First, there is no (easy) way to centralize this information with
    Rudder; you can only get compliance status on rules you apply
    (Success/Repaired/Error), I'll elaborate on this below<br>
    <br>
    <blockquote cite="mid:55DB1DE7.8000309@azylog.net" type="cite">
      <pre wrap="">
So, I made a technique 'Nb of packages upgradable by apt' which run :
/bin/sh -c \'! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l\'

On a machine, this return the number of packages that would have been upgraded
by apt-get upgrade.

Next, I made a directive using this technique. This is probably where I'm wrong.
It seems there's nothing to specify except the technique used and rule to be
applied.
I checked the 'Global configuration for all nodes' rule and then goes to node ->
Reports. I can see an item with my rule, directive, component and value.
Value is my command and status is showing 'Missing'.

By checking the log on the machine, here are the revelant lines (hope at least) :
Aug 24 15:17:52 testmachine rudder[799]:
/default/Nb_of_packages_upgradable_by_apt/methods/'method_call'/default/command_execution/commands/'/bin/sh
-c '! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l''[0]: Finished command
related to promiser '/bin/sh -c '! /usr/bin/apt-get -s upgrade | /bin/grep
Inst|wc -l'' -- an error occurred, returned 1
Aug 24 15:17:52 testmachine rudder[799]:
/default/Nb_of_packages_upgradable_by_apt/methods/'method_call'/default/command_execution/commands/'/bin/sh
-c '! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l''[0]: Q: ".../bin/sh -c
'! /": 125
Aug 24 15:17:52 testmachine rudder[799]: R: [ERROR] Promise could not be
repaired, error encountered: Execute the command /bin/sh -c '! /usr/bin/apt-get
-s upgrade | /bin/grep Inst|wc -l'
Aug 24 15:17:53 testmachine rudder[799]:
/default/Nb_of_packages_upgradable_by_apt/methods/'method_call'[0]: Method
'command_execution' failed in some repairs

Not so good for a first try ;-)

So is this possible and ... how ?</pre>
    </blockquote>
    Unfortunately, you are bitten by the following bug :
    <a class="moz-txt-link-freetext" href="http://www.rudder-project.org/redmine/issues/5550">http://www.rudder-project.org/redmine/issues/5550</a> , which we though
    were fixed by another change, but was not<br>
    When you saved the Technique, the ' was escaped to \', which is not
    what we wanted.<br>
    <br>
    The workaround I can suggest is to use the command <br>
    <pre wrap="">! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l
</pre>
    which would do the same.<br>
    <br>
    The consequence will be that the Directive will return status:<br>
    <ul>
      <li>Repaired if there are no package to upgrade</li>
      <li>Error if there are packages to upgrade</li>
    </ul>
    <p>The logic is that command_execution will return status "Repaired"
      for exit code 0, and "Error" for non exit code 0<br>
    </p>
    <br>
    Does that do what you want ?<br>
    <blockquote cite="mid:55DB1DE7.8000309@azylog.net" type="cite">
      <pre wrap="">

Thanks,
Julien Escario (yeah, in France too)
</pre>
    </blockquote>
    Yeah \o/<br>
    <br>
    Nicolas<br>
  </body>
</html>