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

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

Problems importing XML locally through the web

Hi Folks,

I am having some trouble importing XML files that were generated by the OCS Inventory agent. I am using the OCS Inventory web server in order to import it manually (the XML was generated by manually running the agent with /local /xml=path_to_xml).

I think I am having some problems with some additional fields that I am generating through a plugin that I have built. So, when importing the XML, I got an Internal Server Error message (500). So I have removed the parts that my plugin added to the XML file and I was able to import it with no errors. 

However, now I am trying to add each new element to the XML at a time so that I may find what is wrong. The problem is that I can no longer import this XML because I always get an Internal Server Error (even when I stick to the XML that once worked). I have turned on OCS debuggin flag (OCS_OPT_LOGLEVEL) and I get the following lines in activity.log whenever I try to import this XML:

  • Fri Nov  4 09:01:31 2016;18881;318;MV001534-2016-06-06-17-13-18;127.0.0.1;OCS_local_7009;session;missing
  • Fri Nov  4 09:01:31 2016;18881;114;MV001534-2016-06-06-17-13-18;127.0.0.1;OCS_local_7009;inventory;no_session

As far as I was able to understand, OCS tries to find a corresponding row in prolog_conntrack table, but there is no such row. What should I do? The XML query tag is INVENTORY. I saw that in order to have this row in prolog_conntrack, I should import an XML with PROLOG in the query tag... Is it correct? How can I do it? What could have happened?

I would be very pleased to understand the dynamics behind the import action and prolog. Answers may be in english or french!

Thank you very much,

Rafael GuimarĂ£es

in OCS Inventory NG server for Unix by (280 points)

7 Answers

0 votes

Hi,

Try with ocsinventory-injector.pl script :

perl ocsinventory-injector.pl -v -r -f file.ocs -u http://localhost/ocsinventory

Regards

by (6.2k points)
0 votes
I get the same problem when I try to use ocsinventory-injector.pl...

Loading /root/MV001534-2016-06-06-17-13-18.xml...ERROR: 500 Internal Server Error

And on activity.log:

Fri Nov  4 11:10:03 2016;18875;318;MV001534-2016-06-06-17-13-18;127.0.0.1;OCS-NG_INJECTOR_PL_v3;session;missing
Fri Nov  4 11:10:03 2016;18875;114;MV001534-2016-06-06-17-13-18;127.0.0.1;OCS-NG_INJECTOR_PL_v3;inventory;no_session

What can I do?
by (280 points)
0 votes

See FAQ :

Error 500 :

Solution: OCS engine can't comunicate with mysql server. Probably due to a wrong mysql account. You have to check z-ocsinventory-server.conf (ocsinventory-server.conf on Windows Server), exactly theses few lines

  # Master Database settings
  # Replace localhost by hostname or ip of MySQL server for WRITE
  PerlSetEnv OCS_DB_HOST localhost
  # Replace 3306 by port where running MySQL server, generally 3306
  PerlSetEnv OCS_DB_PORT 3306
  # Name of database
  PerlSetEnv OCS_DB_NAME ocsweb
  PerlSetEnv OCS_DB_LOCAL ocsweb
  # User allowed to connect to database
  PerlSetEnv OCS_DB_USER ocs
  # Password for user
  PerlSetVar OCS_DB_PWD ocs

Modify OCS_DB_USER and OCS_DB_PWD with your own account, restart apache, and finaly launch an inventory.

Regards

by (6.2k points)
0 votes

I have checked it, but that's not the problem.

After debugging the perl modules, I have found that the problem is that the DEVICEID of the XML is not present in the prolog_conntrack table. 

This code is executed in the Inventory.pm:

 # Check prolog
  if( !check_session( \%Apache::Ocsinventory::CURRENT_CONTEXT ) ){
    &_log( 114, 'inventory', 'no_session');
    if( !$Apache::Ocsinventory::CURRENT_CONTEXT{'IS_TRUSTED'} && $ENV{OCS_OPT_INVENTORY_SESSION_ONLY} ){
      &_log( 115, 'inventory', 'refused');
      return(APACHE_FORBIDDEN);
    }
  }
  #Inventory incoming
  &_log(104,'inventory','incoming') if $ENV{'OCS_OPT_LOGLEVEL'};
  # Put the inventory in the database
  return APACHE_SERVER_ERROR if &_update_inventory( \%SECTIONS, \@SECTIONS );

check_session returns false and event 114 is logged. Then, it returns the APACHE_SERVER_ERROR.

That seems to happen because no prolog event was triggered before. When a windows agent send the inventory, I can see from the log that it triggers a prolog event, then it triggers an inventory event. How can I do this locally? What am I doing wrong?

Best regards

by (280 points)
0 votes

The XML file is valid ? Try with an XML file from OCSReports and/or from another agent.

Activity.log sample :

Wed Nov  2 08:57:02 2016;2905;318;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;session;missing
Wed Nov  2 08:57:02 2016;2905;114;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;inventory;no_session
Wed Nov  2 08:57:02 2016;2905;104;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;inventory;incoming
Wed Nov  2 08:57:02 2016;2905;113;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;inventory;u:printers
Wed Nov  2 08:57:02 2016;2905;113;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;inventory;u:uptime
Wed Nov  2 08:57:02 2016;2905;113;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;inventory;u:drives
Wed Nov  2 08:57:02 2016;2905;113;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;inventory;u:sharedfolders
Wed Nov  2 08:57:02 2016;2905;101;PCXXX-2016-01-24-15-19-34;::1;OCS-NG_INJECTOR_PL_v3;inventory;transmitted

Regards

by (6.2k points)
0 votes

I have tried with the XML generated by OCSReports and I get exactly the same error. Is there anything to do with the prolog_conntrack table? I am sticked to this issue because the check_session function in the Inventory.pm module makes a select that returns 0E0, what causes the error.

Any ideas?

sub check_session {
  my $current_context = shift;
  my $dbh = $current_context->{DBI_HANDLE};
  my $deviceId = $current_context->{DEVICEID};

  unless( $ENV{OCS_OPT_SESSION_VALIDITY_TIME} ){
    &_log(317,'session', 'always_true') if $ENV{'OCS_OPT_LOGLEVEL'};
    return 1;
  }

  my $check = $dbh->do('SELECT DEVICEID FROM prolog_conntrack WHERE DEVICEID=? AND (UNIX_TIMESTAMP()-TIMESTAMP<?)',
               {}, $deviceId, $ENV{OCS_OPT_SESSION_VALIDITY_TIME});

  if(!$check){
    &_log(526,'session', 'error') if $ENV{'OCS_OPT_LOGLEVEL'};
    return 0;
  }
  elsif($check==0E0){
    &_log(318,'session', 'missing') if $ENV{'OCS_OPT_LOGLEVEL'};
    return 0;
  }

  else{
    &_log(319,'session', 'found') if $ENV{'OCS_OPT_LOGLEVEL'};
    return 1;
  }
}

by (280 points)
0 votes
Something in apache and mysql error.log ?
by (6.2k points)
 
Powered by Question2Answer
...