ocssvn.pl - keep OCS computer data versioned in Subversion.
ocssvn.pl --svn=WCPATH --ocsurl=URL [--checksum=NUM] [--all] [--dont] [--verbose]
Use this script to keep the information from a OCS server (http://www.ocsinventory-ng.org/) versioned in a Subversion repository.
The information about each computer in OCS is kept in a text file in JSON format (http://json.org/), which is a structured and readable format.
First you need to create a dedicated Subversion repository to keep OCS information. Also, you need to create a trunk and a tags directory at the root of the repository. You can do this with these commands:
trunk
tags
$ svnadmin create /path/to/ocssvnrepo $ svn mkdir -m'Create standard root directories' file:///path/to/ocssvnrepo/{trunk,branches,tags}
Then, checkout the trunk directory creating a working copy. The working copy can be in the same computer as the repository or in a remote machine. You need to adjust the URL accordingly.
$ svn checkout file:///path/to/ocssvnrepo/trunk /path/to/ocssvn
Now you can run the script. The two required options are the path to the Subversion working copy that you just created (--svn) and the URL to the OCS server.
--svn
$ ocssvn.pl --svn=/path/to/ocssvn --ocsurl=http://ocs.domain.com/
On its first run, the script will fetch information about all computers registered in OCS and create a file called name.js in the working copy. The name part is taken from the NAME of the computer as fetched from its META information. When all computers are fetched and their files created the script runs a svn add for each file and a svn commit to commit the changed working copy to the repository. Then it creates a tag by copying trunk to a directory which name conforms to tags/YYYYMMDDHHMMSS. The tag name is the time when it was created.
name.js
name
svn add
svn commit
tags/YYYYMMDDHHMMSS
On subsequent runs, the script will first fetch the META information from all computers in OCS and then fetch the complete information only of the computers which have been inventoried since the last tag was created. After doing that it does the commit and a new tag is created. This was you have a new tag for each run, which allows you to have complete versioning of OCS information.
The script fetches the information via OCS's SOAP API, using the OCS::Client module. It asks for the login credentials on interactive calls. If you want to invoke it via cron, you should set the credentials before calling it by setting the environment variables ocsuser and ocspass.
OCS::Client
ocsuser
ocspass
The computer information is pruned before being saved in the JSON file by the OCS::Client::prune routine.
OCS::Client::prune
This required option specifies the path to the Subversion working copy where the computer files are kept.
This required option specifies the OCS server URL.
This option specifies the CHECKSUM parameter that will be passed to OCS::Client::get_computers_V1, in order to tell what information is requested from the computers. Its default has the following bits enabled:
OCS::Client::BIOS OCS::Client::HARDWARE OCS::Client::LOGICAL_DRIVES OCS::Client::MEMORY_SLOTS OCS::Client::MODEMS OCS::Client::NETWORK_ADAPTERS OCS::Client::REGISTRY OCS::Client::SOFTWARE OCS::Client::SOUND_ADAPTERS OCS::Client::STORAGE_PERIPHERALS OCS::Client::VIDEO_ADAPTERS
By default, only computers that have been inventoried since the most recent Subversion tag has been generated or computers which don't yet have a corresponding JSON file are fetched from OCS. This option forces the fetching of all computers.
It's handy when the script JSON output changes and you want to force the refresh of all files.
This option makes the script refrain from making any changes in Subversion.
This option makes the script verbose. If you repeat it it will make the script even more verbose.
Copyright 2012 CPqD.
Gustavo Chaves <gustavo@cpqd.com.br>
To install OCS::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OCS::Client
CPAN shell
perl -MCPAN -e shell install OCS::Client
For more information on module installation, please visit the detailed CPAN module installation guide.