++ed by:

1 PAUSE user

Gustavo Leite de Mendonça Chaves


OCS::Client - simple interface to OCS's SOAP API


version 0.012


  use OCS::Client;

  my $ocs = OCS::Client->new('http://ocs.example.com', 'user', 'passwd');

  my @computers = $ocs->get_computers_V1(
      id       => 123456,
      checksum => OCS::Client::HARDWARE | OCS::Client::SOFTWARE,

  my $next_computer = $ocs->computer_iterator(asking_for => 'META');
  while (my $meta = $next_computer->()) {
      # ...


OCS is a technical management solution of IT assets. It's home page is http://www.ocsinventory-ng.org/.

This module implements a thin Object Oriented wrapper around OCS's SOAP API, which is somewhat specified in http://wiki.ocsinventory-ng.org/index.php/Developers:Web_services. (This version is known to work against OCS 2.0.1.)


new OCSURL, USER, PASSWD [, <SOAP::Lite arguments>]

The OCS::Client constructor requires three arguments. OCSURL is OCS's base URL from which will be constructed it's SOAP URL. USER and PASSWD are the credentials that will be used to authenticate into OCS. Any other arguments will be passed to the SOAP::Lite object that will be created to talk to OCS.

get_computers_V1 REQUEST-MAP

This method allows for querying inventoried computers.

The REQUEST-MAP is a key-value list of information that is used to construct the XML request structure defined in the OCS documentation (see link above). Any key-value pair passed to the method is appended to the following default list:

    engine     => 'FIRST',
    asking_for => 'INVENTORY',
    checksum   => 0x01FFFF,
    wanted     => 0x000003,
    offset     => 0,

The complete list is used to initialize a hash from which the XML structure is built. Hence, you can override any one of the default values by respecifying it.

The method returns a list of hashes. Each hash represents a computer as a data structure that is converted from its XML original representation into a Perl data structure by the XML::Simple::XMLin function.

computer_iterator REQUEST-MAP

This method returns a closure that you can use to fetch the computers one by one until there is no more. It's usefull because the server usually has a limit to the maximum number of computers that get_computers_V1 can return at once. See an example of its usage in the SYNOPSIS above.


This class method gets a COMPUTER description, as returned by the get_computer_V1 method, and simplifies it by deleting and converting some not so important information. It returns the simplified data structure.

Its original motivation was to get rid of unimportant information and turn it into the barest minimum that I wanted to save in a text file (after converting it into JSON) that I kept under version control. Without pruning the repository became unecessarily big and there were lots of frequently changing information that was uninportant to track.

Note that it tries to convert the custom field names by using the OCS::Client::fields hash. This hash contains by default, the custom field names of my company's OCS instance. You should redefine it in your script if you intend to use this method. (May the source be with you, Luke!)


This module defines some constants to make the calling of methods get_computers_V1 and computer_iterator easier and more readable.

These are for their CHECKSUM parameter.

    'HARDWARE'            => 0x00001,
    'BIOS'                => 0x00002,
    'MEMORY_SLOTS'        => 0x00004,
    'SYSTEM_SLOTS'        => 0x00008,
    'REGISTRY'            => 0x00010,
    'SYSTEM_CONTROLLERS'  => 0x00020,
    'MONITORS'            => 0x00040,
    'SYSTEM_PORTS'        => 0x00080,
    'STORAGE_PERIPHERALS' => 0x00100,
    'LOGICAL_DRIVES'      => 0x00200,
    'INPUT_DEVICES'       => 0x00400,
    'MODEMS'              => 0x00800,
    'NETWORK_ADAPTERS'    => 0x01000,
    'PRINTERS'            => 0x02000,
    'SOUND_ADAPTERS'      => 0x04000,
    'VIDEO_ADAPTERS'      => 0x08000,
    'SOFTWARE'            => 0x10000,

And these are for their WANTED parameter.

    'ACOUNTINFO'          => 0x00001,
    'DICO_SOFT'           => 0x00002,




Gustavo L. de M. Chaves <gnustavo@cpan.org>


This software is copyright (c) 2012 by Gustavo L. de M. Chaves.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.