From 36fd2bb0577cc6918e314426ee65a32414a9726f Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Tue, 7 Jan 2025 18:31:03 +0100 Subject: [PATCH] feat: Add guessed Total ESX memory size as memory component --- Changes | 1 + lib/GLPI/Agent/Task/ESX.pm | 31 +++++++++++++++++++++++++++++++ resources/esx/esx-4.1.0-1.json | 10 ++++++++++ 3 files changed, 42 insertions(+) diff --git a/Changes b/Changes index 561b3a8dd..fbaa0664a 100644 --- a/Changes +++ b/Changes @@ -69,6 +69,7 @@ esx: * Support reporting of ESX virtualmachines ip and operating system. It requires inventory_format schema v1.1.36 on server-side included in GLPI v10.0.17. * Add --glpi-version option support to glpi-esx script +* Add guessed Total ESX memory size as memory component toolbox: * Fix task log reset for enabled tasks diff --git a/lib/GLPI/Agent/Task/ESX.pm b/lib/GLPI/Agent/Task/ESX.pm index 7b0c3d325..6833858f9 100644 --- a/lib/GLPI/Agent/Task/ESX.pm +++ b/lib/GLPI/Agent/Task/ESX.pm @@ -77,6 +77,16 @@ sub createInventory { $inventory->setHardware( $host->getHardwareInfo() ); + # Add a virtual memory component to report total memory size for system. This remains + # an extrapolated total size based on the reported available system memory size. + my $memory = $inventory->getHardware("MEMORY"); + if ($memory) { + $inventory->addEntry( + section => 'MEMORIES', + entry => _esxTotalMemory($memory), + ); + } + $inventory->setOperatingSystem( $host->getOperatingSystemInfo() ); foreach my $cpu ($host->getCPUs()) { @@ -126,6 +136,27 @@ sub createInventory { } +# Return a total size memory component with capacity rounded to the upper multiple of +# 1GB if size is lower than 16GB, 4GB for greater size but lower than 100GB and 16GB +# for even larger values. With $size given in MB. +sub _esxTotalMemory { + my ($size) = @_; + + return unless $size && $size =~ /^\d+$/; + + my $base = $size < 16384 ? 1024 : $size >= 102400 ? 16384 : 4096; + my $capacity = (int(int($size)/$base)+1) * $base; + + return { + CAPACITY => $capacity, + CAPTION => "ESX Guessed Total Memory", + DESCRIPTION => "ESX Memory", + TYPE => "Total", + MANUFACTURER => "VMware", + NUMSLOTS => "0", + }; +} + sub getHostIds { my ($self) = @_; diff --git a/resources/esx/esx-4.1.0-1.json b/resources/esx/esx-4.1.0-1.json index ad1c598b2..163e9f43e 100644 --- a/resources/esx/esx-4.1.0-1.json +++ b/resources/esx/esx-4.1.0-1.json @@ -278,6 +278,16 @@ "vmsystem": "Physical", "workgroup": "teclib.local" }, + "memories": [ + { + "capacity": 8192, + "caption": "ESX Guessed Total Memory", + "type": "Total", + "description": "ESX Memory", + "manufacturer": "VMware", + "numslots": 0 + } + ], "networks": [ { "description": "vmk0",