Fixing a 500 error in OCSNG

This is an old, old bug that I just tripped over for the second time. Hopefully this'll save someone else...

In September 2010, I had a problem with Ocsinventory, the inventory software we use to track hour hardware: I kept getting 500 errors when running the OCS client on a machine. I filed a bug, but I wanted to show how I tracked it down.

First off, Apache logs for Ocs can be found at /var/log/httpd/access_log and /var/log/httpd/error_log. Ocs itself logs at /var/log/ocsinventory-server (-client too, but that's not as interesting). However, by default Ocs doesn't log very much -- so let's change that. Logging can be twiddled by editing the Ocs/Apache config file at /etc/httpd/conf.d/ocsinventory-server.conf. Pay attention to this setting: PerlSetEnv OCS_OPT_DBI_PRINT_ERROR. It's set to 0 by default, so set it to 1 to turn it on. Also, note that you have to fully restart Apache in order to make changes to this file take effect

After that, I see this error in /var/log/httpd/error_log:

DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '|CHECKSUM|1),
        NAME='server23',
        WORKGROUP='example.com',
        USERDOMAIN=NU' at line 4 at/usr/lib/perl5/vendor_perl/5.8.8/Apache/Ocsinventory/Server/Inventory/Update/Hardware.pm line 35.

So the fix? Edit Hardware.pm and look for these lines at the top:

package Apache::Ocsinventory::Server::Inventory::Update::Hardware;

use strict;

require Exporter;

our @ISA = qw /Exporter/;

our @EXPORT = qw / _hardware /;

use Apache::Ocsinventory::Server::Constants;
use Apache::Ocsinventory::Server::System qw / :server /;

Add this line right afterward:

use constant CHECKSUM_MAX_VALUE => 262143;

and restart Apache. After that, I see this in httpd/error_log:

Constant subroutine Apache::Ocsinventory::Server::Inventory::Update::Hardware::CHECKSUM_MAX_VALUE redefined at /usr/lib/perl5/5.8.8/constant.pm line 103.

However, it doesn't appear to affect things, and I can now run the client on the machine. Bletcherous hack, but it gets the job done.