Icinga / icingaweb2-module-vspheredb

The easiest way to monitor a VMware vSphere environment.
https://icinga.com/docs/vsphere/latest
GNU General Public License v2.0
100 stars 34 forks source link

Memory Capacity is language/locale dependent #458

Closed Virsacer closed 1 year ago

Virsacer commented 1 year ago

Expected Behavior

Same capacity for all languages And capacity > 0

Current Behavior

image image But also happens for non-translated languages like spanish: image

Your Environment

Thomas-Gelf commented 1 year ago

Hi @Virsacer,

I'm unable to reproduce this. Does it happen for all objects, just for specific ones, if the latter: do they have something in common?

Thanks, Thomas

Virsacer commented 1 year ago

Well, the servers with "0 TiB" have between 1000 and 1023 GiB memory. But I have 2 Servers which seem to have exactly 1024 GiB and they show as "1 TiB" in german.

Thomas-Gelf commented 1 year ago

This helped, please give the following patch a try:

--- a/library/Vspheredb/Format.php
+++ b/library/Vspheredb/Format.php
@@ -22,6 +22,7 @@ class Format
         // Problem: %.3G is 0.978 for $value = 1001 / 1024, but we want to see 0.98
         $output = sprintf('%.3G', $result);
         if (preg_match('/^0[,.]/', $output)) {
+            $output = str_replace(',', '.', $output);
             $output = sprintf('%.3G', round((float) $output, 2));
         }
Virsacer commented 1 year ago

Yes, that fixed it. Now it shows "1 TiB" Thanks!