glpi-project / glpi-agent

GLPI Agent
GNU General Public License v2.0
249 stars 61 forks source link

[GLPI10] error 500 in netdiscovery #64

Closed ASLLR closed 2 years ago

ASLLR commented 2 years ago

Bug reporting acknowledgment

Yes, I read it

Professional support

Yes, I know

Describe the bug

Hi everyone,

i test inventory with glpi-inventory agent and his plugin but when i try to do a netdiscovery i've an error 500 like :

[info] running task NetDiscovery
[debug] initializing job 25
[debug] initializing block XX.XX.XX.XX-XX.XX.XX.XX
[debug] Current run expiration timeout: few minutes
[debug] [thread 1] creation
[debug] [http client] Using Compress::Zlib for compression
[debug] [thread 1] glpi-project/glpi-agent#1, scanning XX.XX.XX.XX
[debug] [thread 1] glpi-project/glpi-agent#1, full match for sysobjectID .1.3.6.1.4.1.367.1.1 in database
[debug] [thread 1] glpi-project/glpi-agent#1, /etc/glpi-agent/toolbox.yaml configuration not found
[debug] [thread 1] glpi-project/glpi-agent#1, sysobjectID match: xxxx-printer mib support enabled
[debug] [thread 1] glpi-project/glpi-agent#1, - scanning XX.XX.XX.XX with SNMP, credentials 2: success
[debug] [thread 1] glpi-project/glpi-agent#1, - scanning XX.XX.XX.XX with netbios: success
[debug] [thread 1] glpi-project/glpi-agent#1, - scanning XX.XX.XX.XX with echo ping: success
[debug] [thread 1] glpi-project/glpi-agent#1, - scanning XX.XX.XX.XX in arp table: no result
[debug] [thread 1] glpi-project/glpi-agent#1, [http client] Using Compress::Zlib for compression
[error] [thread 1] glpi-project/glpi-agent#1, [http client] communication error: 500 Internal Server Error
[debug] [thread 1] termination

The job on server side is successful but with "Processed: 0 Created: 0 Updated: 0".

Did he use a proxy for snmp scan ? for information this inventory work with GLPI 9.5.6 and fusioninventory-plugin.

Thank you in advance,

To reproduce

  1. Create a task in glpiinventory to discover snmp equipments.
  2. get the task ready
  3. lauch glpi-agent on the agent side with --debug

Expected behavior

Have a SNMP inventory who work.

Operating system

Linux

GLPI Agent version

1.1

GLPI version

10.0.0-rc1

GLPIInventory plugin or FusionInventory for GLPI plugin version

1.0.0-rc4

Additional context

No response

g-bougard commented 2 years ago

Hi @ASLLR thank you for your report. with such error 500, can you check the php-errors.log file for an error at the same time ?

ASLLR commented 2 years ago

Hi @g-bougard thank you for your answer.

i've got nothing in php-errors.log under the _log folder of GLPI. And nothing too in apache2 log directory... i try to search other informations...

Best regards,

ASLLR commented 2 years ago

So, after doing a tcpdump on my server (client and server are on the same VM) i can see how arrive the error 500 :

i hope that help you

Best regards,

g-bougard commented 2 years ago

Can you check your http daemon error log ?

Can you also try to produce the device info with the glpi-netdiscovery script ? You may then try to import the created XML with glpi-injector or directly from GLPI.

ASLLR commented 2 years ago

I've nothing on http daemon log...

that's works with glpi-netdiscovery, a xml file is generated. glpi-netdiscovery --host XX.XX.XX.XX --protocol [SNMPPROTO] --community [SNMPCOMMUNITY] -i

But, I would like the process to be automatic because I have a lot of equipments...

g-bougard commented 2 years ago

Of course this should work automatically. But we are trying to debug your case right now. Are you able to import manually the generated XML ? The question we are trying to answer right now is if the problem is the XML or the communication. If you can import the XML, this would mean the XML is not a problem.

You may also try to enable debug2 and restart the task to see if we have more debugging information.

ASLLR commented 2 years ago

With glpi-injector that's works 👍 do you want i try to import manually also ?

i'll try to have more debug info quickly.

Thank you,

ASLLR commented 2 years ago

Hi, that the debug2 result' debug2.txt

best regards

g-bougard commented 2 years ago

Okay, I see nothing more interesting. Without any error in php-errors.log, this sounds like a server error to me. Can you put here your GLPI Setup information ? To do so, copy and paste information you will find in GLPI in Setup > General menu, System tab (click on Copy system information button).

ASLLR commented 2 years ago

Hello, sorry for my late answer. This is the system info.

system_info.txt

Best regards,

g-bougard commented 2 years ago

Thanks, it seems you're running GLPI on a Debian with Apache2. Then have you checked the /var/log/apache2/error.log file for errors ?

ASLLR commented 2 years ago

Nothing except an alert on /src/Toolbox.php on line 1166 permission denied.

Do you want i try to erase all my environnement (db, agent, plugin, server) and do a fresh install to see if it reproduce ? i've update this RC from beta1.

Best regards,

g-bougard commented 2 years ago

Hi @ASLLR

yes, it could make sens to reproduce (or not) the problem with a fresh install.

The exception alert is just telling the /marketplace glpi subfolder is not writable. This folder needs to be writable if you want to install plugin via Marketplace but this should not be a problem if you install the GlpiInventory plugin manually under /plugins. So I don't think this is a problem.

ASLLR commented 2 years ago

Hi,

on new fresh environment i've the same error... can you reproduce it yourself or it's just on my environment ?

Best regards,

girtsudrass commented 2 years ago

I have the same issue too when I try to import my Kyocera printer. I exported XML file with NetInventory and imported manually in debug mode and I got message. attels After deleting COPYCOLOR tag from XML it also complains about FAXTOTAL. If it's also deleted then import is successful. Exported XML file: print1.txt

ASLLR commented 2 years ago

Hi @girtsudrass, me too this happens during printer discovery and inventory. I don't have any other equipment to do the test.

best regards,

girtsudrass commented 2 years ago

Right now I have only Kyocera printers available, tomorrow will try to find another brand and test it.

g-bougard commented 2 years ago

@girtsudrass Sorry we missed something in our inventory.schema.json. I just made PR glpi-project/glpi-agent#66 to fix this problem. You can try to apply the patch on your GLPI installation.

g-bougard commented 2 years ago

@ASLLR I tested again netdiscovery and netinventory and this seems to work properly. I don't any error like yours:

[error] [thread 1] glpi-project/glpi-agent#1, [http client] communication error: 500 Internal Server Error

A side question, are you using SSL to reach your server ? Anyway, can I ask you to try next glpi-agent nightly build ? I updated the error handling, maybe the error message will change.

girtsudrass commented 2 years ago

I applied patch and it works now for online printers, but offline printers still gives error 500. By using previous method and importing XML from debug2 manually error is attels Used XML

<?xml version="1.0" encoding="UTF-8" ?>
<REQUEST>
  <CONTENT>
    <DEVICE>
      <ERROR>
        <ID>2</ID>
        <MESSAGE>SNMP communication error: no response from host 1.1.1.1</MESSAGE>
        <TYPE>PRINTER</TYPE>
      </ERROR>
    </DEVICE>
    <MODULEVERSION>5.0</MODULEVERSION>
    <PROCESSNUMBER>46</PROCESSNUMBER>
  </CONTENT>
  <DEVICEID>glpi-2022-02-07-10-32-15</DEVICEID>
  <QUERY>SNMPQUERY</QUERY>
</REQUEST>
ASLLR commented 2 years ago

Hi @g-bougard i try with nightly build of GLPI-AGENT 1.2 but i've the same error message.

that work's when i lauch glpi-netdiscovery and glpi-netinventory but not when i launch only glpi-agent.

Thank in advance,

Best regards,

g-bougard commented 2 years ago

Hi @ASLLR this is probably the time to test I new tool I developed lately last year for such purpose. This tool is named netsim.

Netsim will permit me to emulate your device so I can run netdiscovery task or netinventory task exactly in the same way you did. It has to be run from an agent repository clone for simulation, but it can be used standalone to make a walk and prepare an encrypted archive of the device information. By default, the script embed a public key, you can use to encrypt datas so only me can decrypt it. Then you can safely attach the generated archive to this issue.

So can you dowload the script netsim.sh on the same platform than your GLPI Agent in a dedicated folder, let's say /var/tmp/netsim ? If you don't have them, you have to install python3-virtualenv and python3-pip as they are needed by the snmpsim tool the script will automatically download and setup in a subfolder. Then, you have to run netsim like this:

[g-bougard@test netsim]# export ENCRYPT=teclib
[g-bougard@test netsim]# chmod +x netsim.sh
[g-bougard@test netsim]# ./netsim.sh
...
> walk A.B.C.D
Give a name for the template to generate: ricoh-mp-3055
Give the snmp version [2c]: 1
Give the community: [public]
...
> backup templates
Preparing backup...
Encryption is enabled using 'teclib' authority
Backup file: /var/tmp/netsim/netsim.001.zip
> quit

The export ENCRYPT=teclib definition is required to encrypt the archive. If you don't set ENCRYPT, anyone with who you share the archive could re-use your data with netsim. The walk A.B.C.D asks netsim to create a device template making a walk on the device behind A.B.C.D ip. You'll be asked to provide a template name, give any relevant string. You'll be also asked for snmp credentials, default is to use '2c' as protocol version and 'public' as community if you directly hit <ENTER> to the questions. The backup templates will make an archive giving you the full path to it. Then check the content is unreadable so you can safely attach it here.

ASLLR commented 2 years ago

Thank you for your answer @g-bougard, here is the file. netsim.001.zip

i search too why this work when i use glpi-netinventory and not when i use glpi-agent command but I am at the end of my skills...

Thank you in advance,

g-bougard commented 2 years ago

Hi @ASLLR thank you for your effort, I was able to import the printer: image Btw the task run as expected without logging any '500 Internal Server Error' message. So this makes me confident your device if not the source of the problem, but there's really a problem server-side. And if you see nothing in php-errors.log or in any apache2 related errorlog, I don't know what's going on. Anyway, as you have no related error in php-errors.log, I can only suppose something is making trouble in your apache2+php configuration. You should probably check system logs.

Regarding your tcpdump, can you share the 500 response, eventually after using the -X option ?

ASLLR commented 2 years ago

Hi @g-bougard i try to study the tcpdump capture but i see nothing to be useful.
i've simulated a curl command and i think the response is correct, i can provide you if you want.

I've nothing on php-error.log and apache error.log in relation with this issue.

Best Regards,

ASLLR commented 2 years ago

For information that work with my glpi-agent v1.2 and fusioninventory-plugin 9.5+3.0 on GLPI 9.5.6.

g-bougard commented 2 years ago

Hi @g-bougard i try to study the tcpdump capture but i see nothing to be useful. i've simulated a curl command and i think the response is correct, i can provide you if you want. Yes, anything investigation you did may help us to find the problem or reproduce the case. So don't hesitate to add any data.

About your GLPI 9.5.6 server environment, are you using the same system with same apache2 configuration ?

Anyway, as for glpi-project/glpi-inventory-plugin#56, maybe your glpi installation is not correct, so can you give us the output of the following command which will return the digest of some glpi files so I can check I have the same digest on my environment ?

sha256sum /var/www/html/glpi-test/src/{DbUtils,Search,Socket,Inventory/Inventory,Inventory/Request}.php /var/www/html/glpi-test/inc/define.php /var/www/html/glpi-test/front/inventory.php
ASLLR commented 2 years ago

Hi @g-bougard yes it's on the same server, but in glpi/ folder with same apache config.

583e21d911d6a7418ef5f84141a8a1578e50b5d62fb1b1116d9a85d19eaf912d  /var/www/html/glpi-test/src/DbUtils.php
3ac87514996ee2aacce430b24b2c6b89f1e80527a2ec2593fee3512d110f9a01  /var/www/html/glpi-test/src/Search.php
bd95b1857752e17fa9bb93bc352c55108f0488f7e1ce727f77741347672df7a5  /var/www/html/glpi-test/src/Socket.php
aae3c352a19126d2b8744581edd55ef9bfa0e7e3435000bd771ab8f5f78285b6  /var/www/html/glpi-test/src/Inventory/Inventory.php
edf49d4992a33a4fa3d8a028ad31e0a3259afc1e28fdc4031beed3fba8bb8d59  /var/www/html/glpi-test/src/Inventory/Request.php
3491a3f83961bddc552085dd35fef2c5ccdf2e91327a6261e81abcbe73bdeade  /var/www/html/glpi-test/inc/define.php
a731ccee7ce274a380d947b1f5017d41212b16c14f60e7789feee33bfe708fb3  /var/www/html/glpi-test/front/inventory.php 

Thank you in advance,

g-bougard commented 2 years ago

Hi @ASLLR this seems correct, so I really don't know what's going on. About the "php-errors.log", are you sure to check the right one as you have 2 installations on the same server ? Maybe you should try on another server. Anyway if you have no other information that can help us to understand/reproduce the case. I'm over, sorry.

ASLLR commented 2 years ago

Yes, the only error on this file is PHP Warning (2): count(): Parameter must be an array or an object that implements Countable in /var/www/html/glpi-test/src/Dashboard/Dashboard.php at line 486

I understand, i will try to search anymore. Thank yo very much for your time. If i found anything i tell here.

Have a nice Day,

ASLLR commented 2 years ago

Hi,

little update after try with glpi10-rc2 and glpiinventory plugin rc5 and glpi-agent nighlybuild of 2022-03-04 02:26.

That's worst than earlier ...

i'm disappointed...

Best Regards,

g-bougard commented 2 years ago

Hi @ASLLR

regarding the WakeOnLan error, this task is not supported at the moment, you can simply disable it with no-task option or not install it if you can. If you need WakeOnLan task, feel free to open a dedicated issue. As far I know, this task should probably be removed.

Now you upgraded your instance, can you check the agent_base_url ? You may suffer the same issue than on glpi-project/glpi-inventory-plugin#56 and need to set the full address with https and a slash at the end to avoid redirections. You should find this URL on root entity at “Home->Administration->Entities[root]->Assets”.

Also, it seems to me, looking at the content your reporting, that your http server is configured to show PHP errors in rendered output. This is due to a not recommanded php configuration. You should disable the related option in your php.ini. When inserted in answers to agent, this will prevent the agent to correctly parse the answer. Then if you trigger any PHP Error, it will only be logged in the php-errors.log file under GLPI files/_log folder.

ASLLR commented 2 years ago

Hi @g-bougard

i try to set the agent base url but that's not change anything.

i disable the log file of my apache and when i lauch inventory i've that on php-errors.log

[2022-03-07 14:55:51] glpiphplog.WARNING:   *** PHP Warning (2): First parameter must either be an object or the name of an existing class in /var/www/html/glpi-test/src/Inventory/Inventory.php at line 187
  Backtrace :
  src/Inventory/Inventory.php:187                    property_exists()
  src/Inventory/Inventory.php:210                    Glpi\Inventory\Inventory->extractMetadata()
  src/Inventory/Request.php:319                      Glpi\Inventory\Inventory->contact()
  src/Inventory/Request.php:76                       Glpi\Inventory\Request->contact()
  src/Agent/Communication/AbstractRequest.php:305    Glpi\Inventory\Request->handleAction()
  src/Agent/Communication/AbstractRequest.php:219    Glpi\Agent\Communication\AbstractRequest->handleJSONRequest()
  front/inventory.php:67                             Glpi\Agent\Communication\AbstractRequest->handleRequest()
  plugins/glpiinventory/front/communication.php:72   include_once()
  plugins/glpiinventory/index.php:45                 include_once()

Thank you in advance,

g-bougard commented 2 years ago

Hi @ASLLR can you try to apply glpi-project/glpi#10845 on your GLPI installation ? It seems this error should be fixed by this GLPI PR.

ASLLR commented 2 years ago

Hi, with this commit it work !! the netdiscovery and inventory works !!

i'm very happy !

really thank you @g-bougard

have a nice day.

g-bougard commented 2 years ago

Great ! Thank you for your perseverance ;-)