glpi-project / glpi-agent

GLPI Agent
GNU General Public License v2.0
241 stars 60 forks source link

Missing LXC container memory limit #132

Closed mightyspiky closed 2 years ago

mightyspiky commented 2 years ago

Code of Conduct

Is there an existing issue for this?

Version

10.0

Bug description

In the GLPI web interface, manually editing the comment field of an LXC container brought up by automatic inventory (in the virtualization section of a computer object) erase the value for the memory field.

Relevant log output

No response

Page URL

No response

Steps To reproduce

  1. Get some virtual machines or containers automatically inventoried with glpi-agent on a physical host
  2. In GLPI interface, go to "virtualization" section in the computer object of your physical host.
  3. See that there is a value for the memory field of a specific container/vm
  4. Edit the comment field of this vm/container
  5. See that the value for the memory field has disappeared

Your GLPI setup information

Informations sur le système, l'installation et la configuration
GLPI 10.0.0 (/glpi => /var/www/html/glpi)
Installation mode: TARBALL
Current language:fr_FR

Server
 
Operating system: Linux zesty 5.4.17-2136.307.3.1.el8uek.x86_64 glpi-project/glpi#2 SMP Mon May 9 17:29:47 PDT 2022 x86_64
PHP 7.4.28 apache2handler (Core, FFI, PDO, Phar, Reflection, SPL, SimpleXML, Zend OPcache, apache2handler, bz2, calendar, ctype,
    curl, date, dom, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, intl, json, libxml, mbstring, mysqli, mysqlnd, openssl,
    pcre, pdo_mysql, posix, readline, session, shmop, sockets, sodium, standard, sysvmsg, sysvsem, sysvshm, tokenizer, xml,
    xmlreader, xmlwriter, xsl, zip, zlib)
Setup: max_execution_time="30" memory_limit="128M" post_max_size="8M" safe_mode="" session.save_handler="files"
    upload_max_filesize="2M" 
Software: Apache/2.4.53 (Debian) (Apache/2.4.53 (Debian) Server at zesty.local Port 80
)
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15
Server Software: Debian 11
    Server Version: 10.5.15-MariaDB-0+deb11u1
    Server SQL Mode: STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    Parameters: glpi@localhost/glpi
    Host info: Localhost via UNIX socket

PHP version (7.4.28) is supported.
Sessions configuration is OK.
Allocated memory is sufficient.
mysqli extension is installed.
Following extensions are installed: dom, fileinfo, json, simplexml.
curl extension is installed.
gd extension is installed.
intl extension is installed.
libxml extension is installed.
zlib extension is installed.
The constant SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES is present.
Database engine version (10.5.15) is supported.
The log file has been created successfully.
Write access to /var/www/html/glpi/files/_cache has been validated.
Write access to /var/www/html/glpi/config has been validated.
Write access to /var/www/html/glpi/files/_cron has been validated.
Write access to /var/www/html/glpi/files has been validated.
Write access to /var/www/html/glpi/files/_dumps has been validated.
Write access to /var/www/html/glpi/files/_graphs has been validated.
Write access to /var/www/html/glpi/files/_lock has been validated.
Write access to /var/www/html/glpi/files/_pictures has been validated.
Write access to /var/www/html/glpi/files/_plugins has been validated.
Write access to /var/www/html/glpi/files/_rss has been validated.
Write access to /var/www/html/glpi/files/_sessions has been validated.
Write access to /var/www/html/glpi/files/_tmp has been validated.
Write access to /var/www/html/glpi/files/_uploads has been validated.
Web access to the files directory should not be allowed but this cannot be checked automatically on this instance.
Make sure access to error log file (/glpi/files/_log/php-errors.log) is forbidden; otherwise review .htaccess file and web server configuration.
exif extension is installed.
ldap extension is not present.
openssl extension is installed.
zip extension is installed.
bz2 extension is installed.
Zend OPcache extension is installed.
Following extensions are installed: ctype, iconv, mbstring, sodium.
Write access to /var/www/html/glpi/marketplace has been validated.
Access to timezone database (mysql) is not allowed.

GLPI constants
 
GLPI_ROOT: /var/www/html/glpi
GLPI_CONFIG_DIR: /var/www/html/glpi/config
GLPI_VAR_DIR: /var/www/html/glpi/files
GLPI_MARKETPLACE_DIR: /var/www/html/glpi/marketplace
GLPI_USE_CSRF_CHECK: 1
GLPI_CSRF_EXPIRES: 7200
GLPI_CSRF_MAX_TOKENS: 100
GLPI_USE_IDOR_CHECK: 1
GLPI_IDOR_EXPIRES: 7200
GLPI_ALLOW_IFRAME_IN_RICH_TEXT: 
GLPI_TELEMETRY_URI: https://telemetry.glpi-project.org
GLPI_INSTALL_MODE: TARBALL
GLPI_NETWORK_MAIL: glpi@teclib.com
GLPI_NETWORK_SERVICES: https://services.glpi-network.com
GLPI_MARKETPLACE_ALLOW_OVERRIDE: 1
GLPI_MARKETPLACE_MANUAL_DOWNLOADS: 1
GLPI_USER_AGENT_EXTRA_COMMENTS: 
GLPI_DISABLE_ONLY_FULL_GROUP_BY_SQL_MODE: 1
GLPI_AJAX_DASHBOARD: 1
GLPI_CALDAV_IMPORT_STATE: 0
GLPI_DEMO_MODE: 0
GLPI_CENTRAL_WARNINGS: 1
GLPI_DOC_DIR: /var/www/html/glpi/files
GLPI_CACHE_DIR: /var/www/html/glpi/files/_cache
GLPI_CRON_DIR: /var/www/html/glpi/files/_cron
GLPI_DUMP_DIR: /var/www/html/glpi/files/_dumps
GLPI_GRAPH_DIR: /var/www/html/glpi/files/_graphs
GLPI_LOCAL_I18N_DIR: /var/www/html/glpi/files/_locales
GLPI_LOCK_DIR: /var/www/html/glpi/files/_lock
GLPI_LOG_DIR: /var/www/html/glpi/files/_log
GLPI_PICTURE_DIR: /var/www/html/glpi/files/_pictures
GLPI_PLUGIN_DOC_DIR: /var/www/html/glpi/files/_plugins
GLPI_RSS_DIR: /var/www/html/glpi/files/_rss
GLPI_SESSION_DIR: /var/www/html/glpi/files/_sessions
GLPI_TMP_DIR: /var/www/html/glpi/files/_tmp
GLPI_UPLOAD_DIR: /var/www/html/glpi/files/_uploads
GLPI_INVENTORY_DIR: /var/www/html/glpi/files/_inventories
GLPI_NETWORK_REGISTRATION_API_URL: https://services.glpi-network.com/api/registration/
GLPI_MARKETPLACE_PLUGINS_API_URI: https://services.glpi-network.com/api/glpi-plugins/
GLPI_I18N_DIR: /var/www/html/glpi/locales
GLPI_VERSION: 10.0.0
GLPI_SCHEMA_VERSION: 10.0.0@9eb698d8fd49f9256d7bd63a6d747587e0effaff
GLPI_MARKETPLACE_PRERELEASES: 
GLPI_MIN_PHP: 7.4.0
GLPI_MAX_PHP: 8.2.0
GLPI_YEAR: 2022

Libraries
 
htmlawed/htmlawed version 1.2.6 in (/var/www/html/glpi/vendor/htmlawed/htmlawed)
phpmailer/phpmailer version 6.6.0 in (/var/www/html/glpi/vendor/phpmailer/phpmailer/src)
simplepie/simplepie version 1.5.8 in (/var/www/html/glpi/vendor/simplepie/simplepie/library)
mpdf/mpdf in (/var/www/html/glpi/vendor/mpdf/mpdf/src)
michelf/php-markdown in (/var/www/html/glpi/vendor/michelf/php-markdown/Michelf)
true/punycode in (/var/www/html/glpi/vendor/true/punycode/src)
iamcal/lib_autolink in (/var/www/html/glpi/vendor/iamcal/lib_autolink)
sabre/dav in (/var/www/html/glpi/vendor/sabre/dav/lib/DAV)
sabre/http in (/var/www/html/glpi/vendor/sabre/http/lib)
sabre/uri in (/var/www/html/glpi/vendor/sabre/uri/lib)
sabre/vobject in (/var/www/html/glpi/vendor/sabre/vobject/lib)
laminas/laminas-i18n in (/var/www/html/glpi/vendor/laminas/laminas-i18n/src)
laminas/laminas-servicemanager in (/var/www/html/glpi/vendor/laminas/laminas-servicemanager/src)
monolog/monolog in (/var/www/html/glpi/vendor/monolog/monolog/src/Monolog)
sebastian/diff in (/var/www/html/glpi/vendor/sebastian/diff/src)
donatj/phpuseragentparser in (/var/www/html/glpi/vendor/donatj/phpuseragentparser/src/UserAgent)
elvanto/litemoji in (/var/www/html/glpi/vendor/elvanto/litemoji/src)
symfony/console in (/var/www/html/glpi/vendor/symfony/console)
scssphp/scssphp in (/var/www/html/glpi/vendor/scssphp/scssphp/src)
laminas/laminas-mail in (/var/www/html/glpi/vendor/laminas/laminas-mail/src/Protocol)
laminas/laminas-mime in (/var/www/html/glpi/vendor/laminas/laminas-mime/src)
rlanvin/php-rrule in (/var/www/html/glpi/vendor/rlanvin/php-rrule/src)
blueimp/jquery-file-upload in (/var/www/html/glpi/vendor/blueimp/jquery-file-upload/server/php)
ramsey/uuid in (/var/www/html/glpi/vendor/ramsey/uuid/src)
psr/log in (/var/www/html/glpi/vendor/psr/log/Psr/Log)
psr/simple-cache in (/var/www/html/glpi/vendor/psr/simple-cache/src)
psr/cache in (/var/www/html/glpi/vendor/psr/cache/src)
league/csv in (/var/www/html/glpi/vendor/league/csv/src)
mexitek/phpcolors in (/var/www/html/glpi/vendor/mexitek/phpcolors/src/Mexitek/PHPColors)
guzzlehttp/guzzle in (/var/www/html/glpi/vendor/guzzlehttp/guzzle/src)
guzzlehttp/psr7 in (/var/www/html/glpi/vendor/guzzlehttp/psr7/src)
glpi-project/inventory_format in (/var/www/html/glpi/vendor/glpi-project/inventory_format/lib/php)
wapmorgan/unified-archive in (/var/www/html/glpi/vendor/wapmorgan/unified-archive/src)
paragonie/sodium_compat in (/var/www/html/glpi/vendor/paragonie/sodium_compat/src)
symfony/cache in (/var/www/html/glpi/vendor/symfony/cache)
html2text/html2text in (/var/www/html/glpi/vendor/html2text/html2text/src)
symfony/dom-crawler in (/var/www/html/glpi/vendor/symfony/dom-crawler)
twig/twig in (/var/www/html/glpi/vendor/twig/twig/src)
twig/string-extra in (/var/www/html/glpi/vendor/twig/string-extra)
symfony/polyfill-ctype not found
symfony/polyfill-iconv not found
symfony/polyfill-mbstring not found
symfony/polyfill-php80 in (/var/www/html/glpi/vendor/symfony/polyfill-php80)
symfony/polyfill-php81 in (/var/www/html/glpi/vendor/symfony/polyfill-php81)

SQL replicas
 
Not active

Notifications
 
Way of sending emails: PHP

Plugins list
 

Anything else?

No response

cconard96 commented 2 years ago

I cannot recreate the issue following these steps. The only difference is that I made the VM manually.

mightyspiky commented 2 years ago

I cannot recreate the issue following these steps. The only difference is that I made the VM manually.

Hmm.. I initially thought the problem occurs also with automatically inventoried KVM virtual machines but I've just verified and it occurs only with my LXC containers. When I click on a container name in the virtualization section, the loaded page doesn't include the memory amount I see on the overview so when I edit any field and save, empty value is overwriting the old value. It might be good to note that with my LXC containers, the amount of memory is suffixed with "M" for megabytes (ex: 2048M) and it's not the case with my KVM virtual machines (ex: 2048). Could it be related to the problem you think?

cconard96 commented 2 years ago

The UI for VMs should only accept numeric values but I do see that the database stores the data as a string. This may explain how the value gets removed after saving the form, but the suffixed value "2048M" should not have shown like that at all in the form. It may have shown in other places like search results and the list on the VMs tab though.

The native inventory feature seems to remove some suffixes like B, KB, and MB and ensures the value is converted into the number of MB (without the suffix). I don't see it handling suffixed like "M" though.

mightyspiky commented 2 years ago

The UI for VMs should only accept numeric values but I do see that the database stores the data as a string. This may explain how the value gets removed after saving the form, but the suffixed value "2048M" should not have shown like that at all in the form. It may have shown in other places like search results and the list on the VMs tab though.

The native inventory feature seems to remove some suffixes like B, KB, and MB and ensures the value is converted into the number of MB (without the suffix). I don't see it handling suffixed like "M" though.

My LXC containers first got inventoried with Fusion-Inventory agent but I moved to glpi-agent when I upgraded to GLPI 10. Shouldn't the new native agent modify the value to remove the "M" ? If not, can I safely manually remove the "M" and presume the memory amount will still get updated automatically in GLPI (without adding the "M") if I change the memory amount of my LXC containers in LXC configuration?

mightyspiky commented 2 years ago

By the way, I re-read your last post and the value for the memory field gets removed after loading the form, not after saving it. The value with "M" is only shown in the overview of the virtualization section.

cconard96 commented 2 years ago

I don't know if there are locks for VM fields that would prevent the inventory from updating it once it is manually changed. However, if it does get updated by the inventory agent, it would still get the bad value unless the agent is changed to send just memory size in MB without the suffix or with an expected suffix, or the server side is updated to handle more possible suffixes.

The official format for the inventory file states the VM memory value should be "Memory size in MB" and an integer type so no suffixes should be used.

mightyspiky commented 2 years ago

So, if the bug is in GLPI agent and not GLPI server, am I at the right place? Is there a Github page specific to GLPI agent?

cconard96 commented 2 years ago

I'll let someone who knows the agent/inventory part better but from what I saw, the LXC inventory in GLPI Agent should get the memory size in bytes but I don't see it being transformed to MB or having a suffix added.

Can you provide the version of the FusionInventory agent and plugin that it was initially inventoried with, and the current GLPI agent version?

On the server side, I guess supporting shortened suffixes would be OK as long as it is safe to assume they stand for Megabyte (1000 1000 bytes) for example and not Mebibyte (1024 1024 bytes).

mightyspiky commented 2 years ago

I really can't remember the initial FusionInventory agent version I've used, sorry, but it's from many years ago. As for GLPI agent, I have the rpm version installed and it's 1.2-1 . As for my problem, I think I might have a clue: In my LXC configuration for a specific container, I have this:

lxc.cgroup.memory.limit_in_bytes = 2048M

The parameter specifies in its name that I should write the value in bytes but I have always used the "M" suffix with success (it works without problem in LXC). Maybe if I write the value in bytes in my LXC conf, I would have no more problem in GLPI interface after the next automatic inventory..? I still think though that GLPI should handle this correctly since the "M" suffix is a valid way to specify memory amount in LXC.

cconard96 commented 2 years ago

I saw the config name and it didn't occur to me that it was a user-defined value (I don't know LXC either). In that case, it seems like something that needs handled on the agent side.

g-bougard commented 2 years ago

Hi @mightyspiky please try next glpi-agent nightly build.

mightyspiky commented 2 years ago

I've just tried the nightly build and it works perfect now! I had to delete manually the containers that had the "M" suffix in the GLPI interface but, after that, I re-ran the agent, containers reappear and memory amount for them appears correctly without the "M". Thanks Guillaume!!

mightyspiky commented 2 years ago

I'm now running glpi-agent 1.4 and it seems LXC containers memory limit get inventoried correctly the first time, but if I change the memory limit in an lxc container's config and then run glpi-agent again, the memory limit in GLPI doesn't get updated. I must delete the container in GLPI and then re-inventory again to get the memory limit update so I would like to re-open the issue. Also, I don't know if I must post here or on https://github.com/glpi-project/glpi/issues/11734 so I'm waiting for your answer g-bougard or anyone else.