#13078 write plugin if not exist

This commit is contained in:
Daniel Cebrian 2024-04-01 13:21:09 +02:00
parent 29e5cf9658
commit abc1114dc1

View File

@ -1292,10 +1292,18 @@ if ($update_agent) {
// Get all plugins (BASIC OPTIONS).
$agent = new PandoraFMS\Agent($id_agente);
$plugins = $agent->getPlugins();
$pluginsToWrite = [
'security_hardening' => [
'write' => $security_hardening,
'raw' => "module_begin \nmodule_plugin /usr/share/pandora_agent/plugins/pandora_hardening -t 150 \nmodule_absoluteinterval 7d \nmodule_end",
],
];
foreach ($plugins as $key => $row) {
// Only check plugins when agent package is bigger than 774.
if ($options_package === '1') {
if (preg_match('/pandora_hardening/', $row['raw']) === 1) {
$pluginsToWrite['security_hardening']['write'] = 0;
if ($security_hardening === 1) {
if ($row['disabled'] === 1) {
$agent->enablePlugins($row['raw']);
@ -1347,6 +1355,12 @@ if ($update_agent) {
}
}
foreach ($pluginsToWrite as $name => $val) {
if ($val['write'] === 1) {
$result = $agent->addPlugins(io_safe_output($val['raw']), true);
}
}
$modules = $agent->getModules();
foreach ($modules as $key => $row) {