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.5 available

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

PHP version of sample Perl web service script

Anybody have a php script that retrieve inventory information thru web service? A version in php of the sample perl script helps me out...
Thanks!
asked in Agent for unix development by (160 points)

1 Answer

+1 vote
 
Best answer

This PHP script returns the inventoried computers

-----------------------------------

<?php

$proto = 'http';
$host  = '111.111.111.11';
$port   = '80';
$user  = '';
$pass = '';
 
$options = array(
    'location'          => "$this->proto://$this->host:$this->port/ocsinterface",
    'uri'                  => "$this->proto://$this->host:$this->port/Apache/Ocsinventory/Interface", 
    'login'               => $this->user,
    'password'       => $this->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>';
 
try {
    $client = new SoapClient(NULL, $options);
} catch (Exception $e) {
    echo "<b>Construct Error</b>: " . $e->getMessage() . "<br>";
}
 
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>Result:</b><pre>";
    var_dump($result);
    echo "</pre><br>";
} catch (Exception $e) {
    echo "<b>Connection Error</b>: " . $e->getMessage() . "<br><br>";
    echo "<b>Headers:</b><pre>\r\n" . $client->__getLastRequestHeaders() . "</pre><br>";
    echo "<b>Request:</b><pre>\r\n" . $client->__getLastRequest() . "</pre>";
}
answered by (480 points)
selected by
 
Powered by Question2Answer
...