76 lines
2.5 KiB
PHP
76 lines
2.5 KiB
PHP
<?php
|
|
|
|
// Pandora FMS - the Flexible Monitoring System
|
|
// ============================================
|
|
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
|
|
// Please see http://pandora.sourceforge.net for full contribution list
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU Lesser General Public License (LGPL)
|
|
// as published by the Free Software Foundation for version 2.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
/**
|
|
* Copy a module defined in an agent to other agent.
|
|
*
|
|
* This function avoid duplicated by comparing module names.
|
|
*
|
|
* @param int Source agent module id.
|
|
* @param int Detiny agent id.
|
|
*
|
|
* @return New agent module id on success. Existing module id if it already exists.
|
|
* False on error.
|
|
*/
|
|
function copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent) {
|
|
$module = get_agent_module ($id_agent_module);
|
|
if ($module === false)
|
|
return false;
|
|
|
|
$modules = get_agent_modules ($id_destiny_agent, false,
|
|
array ('nombre' => $module['nombre']));
|
|
if (! empty ($modules))
|
|
return array_pop (array_keys ($modules));
|
|
|
|
/* PHP copy arrays on assignment */
|
|
$new_module = $module;
|
|
|
|
/* Rewrite different values */
|
|
$new_module['id_agente'] = $id_destiny_agent;
|
|
$new_module['ip_target'] = get_agent_address ($id_destiny_agent);
|
|
|
|
/* Unset numeric indexes or SQL would fail */
|
|
$len = count ($new_module) / 2;
|
|
for ($i = 0; $i < $len; $i++)
|
|
unset ($new_module[$i]);
|
|
/* Unset original agent module id */
|
|
unset ($new_module['id_agente_modulo']);
|
|
|
|
$id_new_module = process_sql_insert ('tagente_modulo', $new_module);
|
|
if ($id_new_module === false) {
|
|
return false;
|
|
}
|
|
|
|
$values = array ();
|
|
$values['id_agente_modulo'] = $id_new_module;
|
|
$values['id_agente'] = $id_destiny_agent;
|
|
|
|
if (! in_array ($new_module['id_tipo_modulo'], array (2, 6, 9, 18, 21, 100)))
|
|
/* Not proc modules uses a special estado (status) value */
|
|
$values['estado'] = 100;
|
|
|
|
$result = process_sql_insert ('tagente_estado', $values);
|
|
if ($result === false)
|
|
return false;
|
|
|
|
return $id_new_module;
|
|
}
|
|
|
|
?>
|