Skip to content

Commit

Permalink
feat: Add guessed Total ESX memory size as memory component
Browse files Browse the repository at this point in the history
  • Loading branch information
g-bougard committed Jan 7, 2025
1 parent e1740b4 commit 36fd2bb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions lib/GLPI/Agent/Task/ESX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) = @_;

Expand Down
10 changes: 10 additions & 0 deletions resources/esx/esx-4.1.0-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 36fd2bb

Please sign in to comment.