Welcome to OCS Inventory NG community support, where you can ask questions and receive answers from other members of the community.

Please ask questions only in English or French.

Release 2.12.3 available

The official documentation can be found on https://wiki.ocsinventory-ng.org. Read it before asking your question.

ocs soap area [closed]

I want to acess the ocs inventory soap area (ip/ocsinterface).

 
I created the user using htpasswd command and edit the ocsinventory.conf, but i can't acess the soap area. 
 
The apache logs say: The LENGTH argument can't be negative at /usr/local/share/perl/5.14.2/SOAP/Transport/HTTP2.pm line 103.\n
 
Anybody helps me?
 
Thanks
closed with the note: SOLVED
in GUI development by (480 points)
closed by

1 Answer

0 votes
You can't just use a browser for that - are you using something that knows how to POST the soap request?
by (1.1k points)
Thank you for your help
 
I could access the webservice through php script, same as the site in perl.
 
 
This is the result I have for browser:
 "
 ["s-gensym1026"]=>
  string(255) "
  569
  2
  ucrania-2014-11-18-16-44-44
  2014-12-02 06:24:58
  2014-12-02 06:24:58 <-- inventory date
  ucrania <--name of computer
  NA

"
  ["s-gensym1028"]=>
  string(255) "
  569
  3
  letonia-2014-11-18-16-44-58
  2014-12-02 06:24:58
  2014-12-02 06:24:58
  letonia
  NA
 
-------------------------------------------------- -----------------------------------
 
Now I would like to know how to show other information from computers.
 
Thanks so much!!!

 

You have to post a request XML as described here:

http://wiki.ocsinventory-ng.org/index.php/Developers:Web_services

(if the link doesn work that's wiki.ocsinventory-ng.org/index.php/Developers:Web_services)
and you get back xml containing the response.   What is returned is controlled by the CHECKSUM value, which you compute by adding the values listed in the perl code  for each of the elements you want.
ok, I understand the theory, but in practice not much ...
 
this is my php code:
 
<?php
 
$proto = 'http';
$host  = 'ip';
$port  = 'port';
$user  = 'user';
$pass  = 'pass';
 
    $options = array(
        'location'     => "${proto}://${host}:${port}/ocsinterface",
        'uri'          => "${proto}://${host}:${port}/Apache/Ocsinventory/Interface", /*caminho*/
        'login'        => $user,
        'password'     => $pass,
        'trace'        => TRUE,
        'soap_version' => SOAP_1_1,
    );
 
    $request = '
        <REQUEST>
            <ENGINE>FIRST</ENGINE>
            <ASKING_FOR>META</ASKING_FOR> 
            <CHECKSUM>131071</CHECKSUM>
            <OFFSET>0</OFFSET>
            <WANTED>131071</WANTED>   
        </REQUEST>';
    
    // INVENTORY
    // Create SOAP client
    try {
        $client = new SoapClient(NULL, $options);
    } catch (Exception $e) {
       echo "<b>Construct Error</b>: ". $e->getMessage() . "<br>";
    }
 
    // Send SOAP request
    try {
        $result = $client->get_computers_V1($request);
        //echo "<b>Headers:</b><pre>". $client->__getLastRequestHeaders() ."</pre><br>";
        //echo "<b>Request:</b><pre>". $client->__getLastRequest() ."</pre><br>";
        //echo "<b>Response:</b><pre>". $client->__getLastResponse() ."</pre><br>";
        echo "<b>RESULTADO:</b><pre>";
        var_dump($result);
        echo "</pre>";
    } catch (Exception $e) {
        echo "<b>Connection Error</b>: ". $e->getMessage() . "<br><br>";
        echo "<b>Headers:</b><pre>\r\n". $client->__getLastRequestHeaders() ."</pre><br>\r\n\r\n";
        echo "<b>Request:</b><pre>\r\n". $client->__getLastRequest() ."</pre>\r\n";
    }
 
 
and this is the return I get:
 
RESULTADO:
array(6) {
  ["s-gensym379"]=>
  string(12) "
"
  ["s-gensym381"]=>
  string(257) "
  65593
  1
  croacia-2014-11-18-16-42-43
  2014-12-02 06:24:58
  2014-12-02 06:24:58
  croacia
  NA
 
"
  ["s-gensym383"]=>
  string(255) "
  569
  2
  ucrania-2014-11-18-16-44-44
  2014-12-02 06:24:58
  2014-12-02 06:24:58
  ucrania
  NA
 
"
  ["s-gensym385"]=>
  string(255) "
  569
  3
  letonia-2014-11-18-16-44-58
  2014-12-02 06:24:58
  2014-12-02 06:24:58
  letonia
  NA
 
"
  ["s-gensym387"]=>
  string(262) "
  262143
  9
  jaceyru-2014-12-15-16-56-00
  2014-12-22 10:32:10
  2014-12-22 10:32:10
  jaceyru
  CLIENT
 
"
  ["s-gensym389"]=>
  string(13) "
"
}
 
 
as I can stylize this output?
 
thank you.
Try ASKING_FOR INVENTORY instead of META to get the full data.

 yes, INVENTORY will show me more complete information.

 
I need is to break the output into individual variables, for example wanted to show in browser
 
NAME: JACEYRU
INVENTORY DATE: 11/11/1111
MEMORY: XXX
 
thanks
That part is up to your php code.  I can sort-of muddle through xml parsing in perl or groovy, but don't know much about the libraries available in php.   Just keep in mind that many of the elements can have multiple instances.

 Hello again,

 
Now I need another favor ... I need to pass a variable to the <ID> tag only can not I, gives the following error:
 

File does not exist: 1 at /usr/share/perl5/Apache/Ocsinventory/Interface/Inventory.pm line 37

 
you know something about it?
 
Thank U !!!
I must have a different version - I don't see any file reference on line 37 of that file.  Does your httpd error log have any more details?    In any case you should be able to include an <ID> </ID> tag in your request, but I think the value has to be the database id of the item you want, not the host name so you may have a hard time knowing that value.
 
Powered by Question2Answer
...