glpi-project / glpi-agent

GLPI Agent
GNU General Public License v2.0
212 stars 51 forks source link

error: 400 Bad Request JSON does not validate. Violations #611

Closed lexcorp closed 4 months ago

lexcorp commented 4 months ago

Bug reporting acknowledgment

Yes, I read it

Professional support

None

Describe the bug

GLPI Server version 10.0.11 I have Glpi Agent 1.7.1 version installed on Virtual Machine with Windows 10 Operating System:

When I run Task Inventory:

[Fri Feb 23 14:20:57 2024][info] New inventory from DESKTOP-9QFCOIE-2024-02-23-13-20-50 for server0 (tag=VirtualPruebas)

After a few seconds, I get this error message:

[Fri Feb 23 14:15:08 2024][error] [http client] communication error: 400 Bad Request, JSON does not validate. Violations:
String expected, ["BOCHS  - 1"] received at #->properties:content->properties:bios->properties:bversion
[Fri Feb 23 14:15:08 2024][error] [http client] server error: JSON does not validate. Violations:
String expected, ["BOCHS  - 1"] received at #->properties:content->properties:bios->properties:bversion

And task inventory do not execute succesfully.

To reproduce

  1. Run Task Inventory from Glpi Agent
  2. View logs and Task starts: [info] New inventory from DESKTOP-9QFCOIE-2024-02-23-13-20-50 for server0 (tag=VirtualPruebas)
  3. After few seconds I get error message:
[error] [http client] communication error: 400 Bad Request, JSON does not validate. Violations:
String expected, ["BOCHS  - 1"] received at #->properties:content->properties:bios->properties:bversion
[error] [http client] server error: JSON does not validate. Violations:
String expected, ["BOCHS  - 1"] received at #->properties:content->properties:bios->properties:bversion
  1. Task inventory do not execute succesfully

Expected behavior

Task inventory execute succesfully and inventory the PC virtual machine

Operating system

Windows, Linux

GLPI Agent version

1.7

GLPI version

10.0.11

GLPIInventory plugin or FusionInventory for GLPI plugin version

GLPI Inventory v1.3.4

Additional context

I test glpi-inventory from cmd:

C:\Program Files\GLPI-Agent>glpi-inventory.bat --partial bios
[info] New inventory from DESKTOP-9QFCOIE-2024-02-23-14-14-38 for local0
{
   "action": "inventory",
   "content": {
      "bios": {
         "bdate": "2014-04-01",
         "bversion": [
            "BOCHS  - 1"
         ],
         "smanufacturer": "BOCHS_",
         "smodel": "BXPC____"
      },
      "hardware": {
         "memory": 6143,
         "name": "DESKTOP-9QFCOIE",
         "vmsystem": "Physical",
         "winlang": "2058",
         "winowner": "Sistemas",
         "winprodid": "00331-10000-00001-AA179",
         "winprodkey": "X269N-FFGWX-23A2B1-4J6X9-V83GX",
         "workgroup": ""
      },
      "versionclient": "GLPI-Inventory_v1.7.1"
   },
   "deviceid": "DESKTOP-9QFCOIE-2024-02-23-14-14-38",
   "itemtype": "Computer",
   "partial": true
}
[info] Inventory dumped on standard output
g-bougard commented 4 months ago

Hi @lexcorp

indeed, this is probably the first time I see the agent reporting an array of one string where we expect directly a string. I can only guess something is wrong in the reported dmidecode output.

Can you report the dmidecode command output running from the glpi-agent folder:

C:\Program Files\GLPI-Agent>cd perl\bin

C:\Program Files\GLPI-Agent\perl\bin>dmidecode

Can you also report the output of the following command ?

wmic path Win32_Bios get /format:list

As far I know, Bochs is related to a virtualized system, so "vmsystem": "Physical", is also probably wrong. Can you describe the used system as I'm not aware of such context ? And so, we may also need to update this support.

lexcorp commented 4 months ago
C:\Program Files\GLPI-Agent>cd perl\bin
C:\Program Files\GLPI-Agent\perl\bin>dmidecode
# dmidecode 3.5
wmic path Win32_Bios get /format:list

BiosCharacteristics=
BIOSVersion={"BOCHS  - 1"}
BuildNumber=
Caption=Default System BIOS
CodeSet=
CurrentLanguage=
Description=Default System BIOS
EmbeddedControllerMajorVersion=
EmbeddedControllerMinorVersion=
IdentificationCode=
InstallableLanguages=
InstallDate=
LanguageEdition=
ListOfLanguages=
Manufacturer=
Name=Default System BIOS
OtherTargetOS=
PrimaryBIOS=TRUE
ReleaseDate=20140401000000.000000+000
SerialNumber=
SMBIOSBIOSVersion=
SMBIOSMajorVersion=
SMBIOSMinorVersion=
SMBIOSPresent=FALSE
SoftwareElementID=Default System BIOS
SoftwareElementState=3
Status=OK
SystemBiosMajorVersion=
SystemBiosMinorVersion=
TargetOperatingSystem=0
Version=BOCHS  - 1

I´m using Proxmox Community Edition to virtualize windows 10

g-bougard commented 4 months ago

Okay, interesting to know you're using Proxmox Community Edition.

About dmidecode output, do you really have only the one line dmidecode version as output or were there troubles during copy/paste ?

If dmidecode output is empty, this can explain why the agent reports an array as it will take BIOSVersion from WMI which seems weirdly reported as an array of string.

In your context, maybe you can check Proxmox community forums or know issues for a known problem with dmidecode on windows. Maybe you have an option to enable on VM. I see WMI reports SMBIOSPresent is false.

As it seems dmidecode is not use, can you share also the output for the following commands ?

wmic path Win32_ComputerSystem get /format:list
wmic path Win32_SystemEnclosure get /format:list
wmic path Win32_BaseBoard get /format:list

I will anyway add a check to avoid having a string array after parsing wmi output.

g-bougard commented 4 months ago

You still can eventually test if the following patch fixes your issue:

diff --git a/lib/GLPI/Agent/Task/Inventory/Win32/Bios.pm b/lib/GLPI/Agent/Task/Inventory/Win32/Bios.pm
index 7cf0ecd57..0bd5ba8f2 100644
--- a/lib/GLPI/Agent/Task/Inventory/Win32/Bios.pm
+++ b/lib/GLPI/Agent/Task/Inventory/Win32/Bios.pm
@@ -105,6 +105,7 @@ sub doInventory {
     }

     foreach (keys %$bios) {
+        $bios->{$_} = shift @{$bios->{$_}} if ref($bios->{$_}) eq 'ARRAY';
         $bios->{$_} =~ s/\s+$// if $bios->{$_};
         delete $bios->{$_} if isInvalidBiosValue($bios->{$_});
     }
lexcorp commented 4 months ago

Hi @g-bougard apply the patch fixes this issue, thank you very much!!!

g-bougard commented 4 months ago

Hi @lexcorp I just pushed the fix in fa2d4e7