Ok, after debugging the functions.php and addhost.php files I finally found the problem, it is related to a parameter in the config.php file.
I didn’t pay enough attention to the config.php.default file and misconfigured the $config[snmp][community] variable.
I thought that I only needed to use an array of communities if I had more than one, so I had the following configuration:
$config['snmp']['community'] = 'MYCOMMUNITY';
I changed to the line below and it worked, since it is not a string anymore, but an array.
$config['snmp']['community'][] = 'MYCOMMUNITY';
Sorry for any inconvenience, the fact that it was working from the Web UI and not from the command line made me think that the configuration was correct.