Skip to content

Commit 36fd2bb

Browse files
committed
feat: Add guessed Total ESX memory size as memory component
1 parent e1740b4 commit 36fd2bb

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ esx:
6969
* Support reporting of ESX virtualmachines ip and operating system. It requires
7070
inventory_format schema v1.1.36 on server-side included in GLPI v10.0.17.
7171
* Add --glpi-version option support to glpi-esx script
72+
* Add guessed Total ESX memory size as memory component
7273

7374
toolbox:
7475
* Fix task log reset for enabled tasks

lib/GLPI/Agent/Task/ESX.pm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ sub createInventory {
7777

7878
$inventory->setHardware( $host->getHardwareInfo() );
7979

80+
# Add a virtual memory component to report total memory size for system. This remains
81+
# an extrapolated total size based on the reported available system memory size.
82+
my $memory = $inventory->getHardware("MEMORY");
83+
if ($memory) {
84+
$inventory->addEntry(
85+
section => 'MEMORIES',
86+
entry => _esxTotalMemory($memory),
87+
);
88+
}
89+
8090
$inventory->setOperatingSystem( $host->getOperatingSystemInfo() );
8191

8292
foreach my $cpu ($host->getCPUs()) {
@@ -126,6 +136,27 @@ sub createInventory {
126136

127137
}
128138

139+
# Return a total size memory component with capacity rounded to the upper multiple of
140+
# 1GB if size is lower than 16GB, 4GB for greater size but lower than 100GB and 16GB
141+
# for even larger values. With $size given in MB.
142+
sub _esxTotalMemory {
143+
my ($size) = @_;
144+
145+
return unless $size && $size =~ /^\d+$/;
146+
147+
my $base = $size < 16384 ? 1024 : $size >= 102400 ? 16384 : 4096;
148+
my $capacity = (int(int($size)/$base)+1) * $base;
149+
150+
return {
151+
CAPACITY => $capacity,
152+
CAPTION => "ESX Guessed Total Memory",
153+
DESCRIPTION => "ESX Memory",
154+
TYPE => "Total",
155+
MANUFACTURER => "VMware",
156+
NUMSLOTS => "0",
157+
};
158+
}
159+
129160
sub getHostIds {
130161
my ($self) = @_;
131162

resources/esx/esx-4.1.0-1.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@
278278
"vmsystem": "Physical",
279279
"workgroup": "teclib.local"
280280
},
281+
"memories": [
282+
{
283+
"capacity": 8192,
284+
"caption": "ESX Guessed Total Memory",
285+
"type": "Total",
286+
"description": "ESX Memory",
287+
"manufacturer": "VMware",
288+
"numslots": 0
289+
}
290+
],
281291
"networks": [
282292
{
283293
"description": "vmk0",

0 commit comments

Comments
 (0)