2009-02-16 Esteban Sanchez <estebans@artica.es>
* godmode/agentes/alert_manager.php: Moved AJAX interface for get_agent_alerts_simple operation here. * godmode/agentes/manage_config.php: Complete rewritten to give support to new alert system and a new improved UI. * godmode/alerts/configure_alert_compound.php: Removed AJAX code relative to groups and agents. Include jQuery and style files with the new way. * godmode/groups/group_list.php: Moved AJAX interface for get_group_agents operation here. * include/styles/pandora.css: Added styling for new manage config interface. Added style for fieldset elements. * include/functions_alerts.php: Added filter parameter to get_alerts_agent_module(). Added copy_alert_agent_module_to_agent_module(). * include/functions_db.php: Added special character * to get_agent_modules() to get all the row. Added format_array_to_where_clause_sql() to transform an array of values to a WHERE clause. Use this function in process_sql_update(). * include/functions_modules.php: Added to repository. New file to add modules operation functions. Added copy_agent_module_to_agent() * operation/agentes/ver_agente.php: AJAX interface for get_agent_modules_json can now receive an additional filter. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1457 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
0f823fd085
commit
28a5d8abf1
|
@ -1,3 +1,36 @@
|
|||
2009-02-16 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* godmode/agentes/alert_manager.php: Moved AJAX interface for
|
||||
get_agent_alerts_simple operation here.
|
||||
|
||||
* godmode/agentes/manage_config.php: Complete rewritten to give
|
||||
support to new alert system and a new improved UI.
|
||||
|
||||
* godmode/alerts/configure_alert_compound.php: Removed AJAX code
|
||||
relative to groups and agents. Include jQuery and style files with the
|
||||
new way.
|
||||
|
||||
* godmode/groups/group_list.php: Moved AJAX interface for
|
||||
get_group_agents operation here.
|
||||
|
||||
* include/styles/pandora.css: Added styling for new manage config
|
||||
interface. Added style for fieldset elements.
|
||||
|
||||
* include/functions_alerts.php: Added filter parameter to
|
||||
get_alerts_agent_module(). Added
|
||||
copy_alert_agent_module_to_agent_module().
|
||||
|
||||
* include/functions_db.php: Added special character * to
|
||||
get_agent_modules() to get all the row. Added
|
||||
format_array_to_where_clause_sql() to transform an array of values to
|
||||
a WHERE clause. Use this function in process_sql_update().
|
||||
|
||||
* include/functions_modules.php: Added to repository. New file to add
|
||||
modules operation functions. Added copy_agent_module_to_agent()
|
||||
|
||||
* operation/agentes/ver_agente.php: AJAX interface for
|
||||
get_agent_modules_json can now receive an additional filter.
|
||||
|
||||
2009-02-13 Evi Vanoost <vanooste@rcbi.rochester.edu>
|
||||
|
||||
* general/logon_ok.php: Simplified and added correct ampersand tags
|
||||
|
|
|
@ -20,6 +20,47 @@
|
|||
require_once ('include/config.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
|
||||
|
||||
if (defined ('AJAX')) {
|
||||
$get_agent_alerts_simple = (bool) get_parameter ('get_agent_alerts_simple');
|
||||
|
||||
if ($get_agent_alerts_simple) {
|
||||
$id_agent = (int) get_parameter ('id_agent');
|
||||
if ($id_agent <= 0) {
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
$id_group = get_agent_group ($id_agent);
|
||||
|
||||
if (! give_acl ($config['id_user'], $id_group, "AR")) {
|
||||
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
|
||||
"Trying to access Alert Management");
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
|
||||
require_once ('include/functions_agents.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
|
||||
$alerts = get_agent_alerts_simple ($id_agent);
|
||||
if (empty ($alerts)) {
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
|
||||
$retval = array ();
|
||||
foreach ($alerts as $alert) {
|
||||
$alert['template'] = get_alert_template ($alert['id_alert_template']);
|
||||
$alert['module_name'] = get_agentmodule_name ($alert['id_agent_module']);
|
||||
$alert['agent_name'] = get_agentmodule_agent_name ($alert['id_agent_module']);
|
||||
$retval[$alert['id']] = $alert;
|
||||
}
|
||||
|
||||
echo json_encode ($retval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset ($id_agente)) {
|
||||
die ("Not Authorized");
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
// Load global vars
|
||||
require_once ("include/config.php");
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! give_acl ($config['id_user'], 0, "LM")) {
|
||||
|
@ -28,442 +26,384 @@ if (! give_acl ($config['id_user'], 0, "LM")) {
|
|||
return;
|
||||
}
|
||||
|
||||
require_once ('include/functions_agents.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
require_once ('include/functions_modules.php');
|
||||
|
||||
$id_group = (int) get_parameter ("id_group");
|
||||
$origen = (int) get_parameter_post ("origen", -1);
|
||||
$update_agent = (int) get_parameter ("update_agent", -1);
|
||||
$update_group = (int) get_parameter ("update_group", -1);
|
||||
$destino = (array) get_parameter_post ("destino", array ());
|
||||
$origen_modulo = (array) get_parameter_post ("origen_modulo", array ());
|
||||
echo '<h2>'.__('Agent configuration'). ' » '. __('Configuration Management').'</h2>';
|
||||
|
||||
// Operations
|
||||
// ---------------
|
||||
|
||||
// DATA COPY
|
||||
// ---------
|
||||
if (isset($_POST["copy"])) {
|
||||
echo "<h2>".__('Data Copy')."</h2>";
|
||||
|
||||
if (empty ($destino)) {
|
||||
echo '<h3 class="error">ERROR: '.__('No selected agents to copy').'</h3>';
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty ($origen_modulo)) {
|
||||
echo '<h3 class="error">ERROR: '.__('No modules have been selected').'</h3>';
|
||||
return;
|
||||
function process_manage_config ($source_id_agent, $destiny_id_agents) {
|
||||
if (empty ($source_id_agent)) {
|
||||
echo '<h3 class="error">'.__('No source agent to copy').'</h3>';
|
||||
return false;
|
||||
}
|
||||
|
||||
$copy_modules = (bool) get_parameter ('modules');
|
||||
$copy_alerts = (bool) get_parameter ('alerts');
|
||||
|
||||
if (! $copy_alerts && ! $copy_modules) {
|
||||
echo '<h3 class="error">ERROR: '.__('You must check modules and/or alerts to be copied').'</h3>';
|
||||
return;
|
||||
if (empty ($destiny_id_agents)) {
|
||||
echo '<h3 class="error">'.__('No destiny agent(s) to copy').'</h3>';
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once ("include/functions_alerts.php");
|
||||
$copy_modules = (bool) get_parameter ('copy_modules');
|
||||
$copy_alerts = (bool) get_parameter ('copy_alerts');
|
||||
|
||||
$origin_name = get_agent_name ($origen);
|
||||
|
||||
// Copy
|
||||
$errors = 0;
|
||||
$id_new_module = 0;
|
||||
process_sql ("SET AUTOCOMMIT = 0;");
|
||||
process_sql ("START TRANSACTION;");
|
||||
|
||||
foreach ($origen_modulo as $id_module) {
|
||||
//For each selected module
|
||||
$module = get_db_row ("tagente_modulo", "id_agente_modulo", $id_module);
|
||||
if ($copy_modules) {
|
||||
$target_modules = (array) get_parameter ('target_modules', array ());
|
||||
if (empty ($target_modules)) {
|
||||
echo '<h3 class="error">'.__('No modules have been selected').'</h3>';
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($destino as $id_agent_dest) {
|
||||
//For each destination agent
|
||||
$destiny_name = get_agent_name ($id_agent_dest);
|
||||
|
||||
if ($copy_modules) {
|
||||
echo '<br /><br />'.__('Copying module').'<b> ['.$origin_name.' - '.$module["nombre"].'] -> ['.$destiny_name.']</b>';
|
||||
$sql = sprintf ('INSERT INTO tagente_modulo
|
||||
(id_agente, id_tipo_modulo, descripcion,
|
||||
nombre, max, min, module_interval,
|
||||
tcp_port, tcp_send, tcp_rcv,
|
||||
snmp_community, snmp_oid, ip_target,
|
||||
id_module_group, flag, id_modulo,
|
||||
disabled, id_export,
|
||||
plugin_user, plugin_pass,
|
||||
plugin_parameter, id_plugin,
|
||||
post_process, prediction_module,
|
||||
max_timeout)
|
||||
VALUES (%d, %d, "%s", "%s", %f, %f, %d,
|
||||
%d, "%s", "%s", "%s", "%s", "%s", %d,
|
||||
%d, %d, %d, %d, "%s", "%s", "%s", %d,
|
||||
%f, %d, %d)',
|
||||
$id_agent_dest, $module["id_tipo_modulo"],
|
||||
$module["descripcion"],
|
||||
$module["nombre"], $module["max"],
|
||||
$module["min"],
|
||||
$module["module_interval"],
|
||||
$module["tcp_port"],
|
||||
$module["tcp_send"],
|
||||
$module["tcp_rcv"],
|
||||
$module["snmp_community"],
|
||||
$module["snmp_oid"],
|
||||
get_agent_address ($id_agent_dest),
|
||||
$module["id_module_group"],
|
||||
$module["flag"],
|
||||
$module["id_modulo"],
|
||||
$module["disabled"],
|
||||
$module["id_export"],
|
||||
$module["plugin_user"],
|
||||
$module["plugin_pass"],
|
||||
$module["plugin_parameter"],
|
||||
$module["id_plugin"],
|
||||
$module["post_process"],
|
||||
$module["prediction_module"],
|
||||
$module["max_timeout"]);
|
||||
process_sql ('SET AUTOCOMMIT = 0');
|
||||
process_sql ('START TRANSACTION');
|
||||
$error = false;
|
||||
$alerts = array ();
|
||||
foreach ($destiny_id_agents as $id_destiny_agent) {
|
||||
foreach ($target_modules as $id_agent_module) {
|
||||
$result = copy_agent_module_to_agent ($id_agent_module,
|
||||
$id_destiny_agent);
|
||||
|
||||
$id_new_module = process_sql ($sql, "insert_id");
|
||||
if (empty ($id_new_module)) {
|
||||
$errors++;
|
||||
} else {
|
||||
switch ($module["id_tipo_modulo"]) {
|
||||
case 2:
|
||||
case 6:
|
||||
case 9:
|
||||
case 100:
|
||||
case 21:
|
||||
case 18:
|
||||
$sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, utimestamp)
|
||||
VALUES (%d, 0,'0000-00-00 00:00:00',0,0, %d, 0)", $id_new_module, $id_agent_dest);
|
||||
break;
|
||||
default:
|
||||
$sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, utimestamp)
|
||||
VALUES (%d, 0,'0000-00-00 00:00:00',0,100, %d, 0)", $id_new_module, $id_agent_dest);
|
||||
}
|
||||
$result = process_sql ($sql);
|
||||
if ($result === false)
|
||||
$errors++;
|
||||
}//If empty id_new_module
|
||||
} //If modulos
|
||||
|
||||
if ($copy_alerts) {
|
||||
if (empty ($id_new_module)) {
|
||||
//If we didn't copy modules or if we
|
||||
//didn't create new modules we have to
|
||||
//look for the module id
|
||||
$sql = sprintf ('SELECT id_agente_modulo
|
||||
FROM tagente_modulo
|
||||
WHERE nombre = "%s"
|
||||
AND id_agente = %d',
|
||||
$module['nombre'], $id_agent_dest);
|
||||
$id_new_module = get_db_sql ($sql);
|
||||
if (empty ($id_new_module))
|
||||
// We can't find a module belonging to this agent
|
||||
continue;
|
||||
if ($result === false) {
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$alerts = get_db_all_rows_field_filter ('talert_template_modules',
|
||||
'id_agent_module', $id_module);
|
||||
if (empty ($alerts))
|
||||
// The module doesn't have alerts
|
||||
$id_destiny_module = $result;
|
||||
if (! isset ($alerts[$id_agent_module]))
|
||||
$alerts[$id_agent_module] = get_alerts_agent_module ($id_agent_module,
|
||||
true);
|
||||
|
||||
if ($alerts[$id_agent_module] === false)
|
||||
continue;
|
||||
|
||||
foreach ($alerts as $alert) {
|
||||
echo '<br />'.__('Copying alert').'<b> ['.$origin_name.' - '.$module["nombre"].'] -> ['.$destiny_name.']</b>';
|
||||
if (!empty ($alert["id_agent"])) {
|
||||
//Compound alert
|
||||
$alert["id_agent"] = $id_agent_dest;
|
||||
if ($copy_alerts) {
|
||||
foreach ($alerts[$id_agent_module] as $alert) {
|
||||
$result = copy_alert_agent_module_to_agent_module ($alert['id'],
|
||||
$id_destiny_module);
|
||||
if ($result === false) {
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$values = array ('id_agent_module' => (int) $id_new_module,
|
||||
'id_alert_template' => (int) $alert['id_alert_template']);
|
||||
$id_alert = process_sql_insert ('talert_template_modules',
|
||||
$values);
|
||||
|
||||
if ($id_alert === false) {
|
||||
$errors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$actions = get_alert_agent_module_actions ($alert['id']);
|
||||
if (empty ($actions))
|
||||
continue;
|
||||
foreach ($actions as $action) {
|
||||
$values = array ('id_alert_template_module' => (int) $id_alert,
|
||||
'id_alert_action' => (int) $action['id'],
|
||||
'fires_min' => (int) $action['fires_min'],
|
||||
'fires_max' => (int) $action['fires_max']);
|
||||
$result = process_sql_insert ('talert_template_module_actions',
|
||||
$values);
|
||||
if ($result === false)
|
||||
$errors++;
|
||||
}
|
||||
|
||||
/* TODO: Copy compound alerts */
|
||||
|
||||
} //foreach alert
|
||||
} //if alerts
|
||||
} //Foreach destino
|
||||
} //Foreach origen_modulo
|
||||
if ($errors > 1) {
|
||||
echo '<h3 class="error">'.__('There was an error copying the module, the copy has been cancelled').'</h3>';
|
||||
process_sql ("ROLLBACK;");
|
||||
} else {
|
||||
echo '<h3 class="suc">'.__('Successfully copied module').'</h3>';
|
||||
process_sql ("COMMIT;");
|
||||
}
|
||||
process_sql ("SET AUTOCOMMIT = 1;");
|
||||
return; //Page shouldn't continue anymore
|
||||
} //end of copy modules or alerts
|
||||
|
||||
// -----------
|
||||
// DELETE DATA
|
||||
// -----------
|
||||
if (isset ($_POST["delete"])) {
|
||||
echo "<h2>".__('Agent Module Data Deletion')."</h2>";
|
||||
|
||||
if (empty ($destino)) {
|
||||
echo '<h3 class="error">ERROR: '.__('No selected agents to copy').'</h3>';
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty ($origen_modulo)) {
|
||||
echo '<h3 class="error">ERROR: '.__('No modules have been selected').'</h3>';
|
||||
return;
|
||||
}
|
||||
|
||||
// If selected modules or alerts
|
||||
if (isset($_POST["alerts"])) {
|
||||
$alertas = 1;
|
||||
} else {
|
||||
$alertas = 0;
|
||||
}
|
||||
|
||||
if (isset($_POST["modules"])) {
|
||||
$modulos = 1;
|
||||
$alertas = 1;
|
||||
} else {
|
||||
$modulos = 0;
|
||||
}
|
||||
|
||||
if (($alertas + $modulos) == 0){
|
||||
echo '<h3 class="error">ERROR: '.__('You must check modules and/or alerts to be deleted').'</h3>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Deletion
|
||||
// ----
|
||||
$errors = 0;
|
||||
|
||||
process_sql ("SET AUTOCOMMIT = 0;");
|
||||
process_sql ("START TRANSACTION;"); //Start a transaction
|
||||
|
||||
function temp_sql_delete ($table, $row, $value) {
|
||||
global $errors; //Globalize the errors variable
|
||||
$sql = sprintf ("DELETE FROM %s WHERE %s = %s", $table, $row, $value);
|
||||
|
||||
$result = process_sql ($sql);
|
||||
|
||||
if ($result === false)
|
||||
$errors++;
|
||||
}
|
||||
|
||||
foreach ($origen_modulo as $id_module_src) {
|
||||
$nombre_src = get_db_value ("nombre", "tagente_modulo", "id_agente_modulo", $id_module_src);
|
||||
|
||||
foreach ($destino as $agent_dest) {
|
||||
$sql = sprintf ("SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = '%s' AND id_agente = %d", $nombre_src, $agent_dest);
|
||||
$id_module_dest = get_db_sql ($sql);
|
||||
if ($id_module_dest === false)
|
||||
continue; //If we don't have a module like that in the agent, then don't try deleting
|
||||
|
||||
if ($alertas == 1) {
|
||||
//Alert
|
||||
/* TODO: Delete compound alerts */
|
||||
|
||||
temp_sql_delete ('talert_template_modules', "id_agent_module", $id_module_dest);
|
||||
}
|
||||
}
|
||||
|
||||
if ($modulos == 1) {
|
||||
//Standard data
|
||||
temp_sql_delete ("tagente_datos", "id_agente_modulo", $id_module_dest);
|
||||
|
||||
//Incremental Data
|
||||
temp_sql_delete ("tagente_datos_inc", "id_agente_modulo", $id_module_dest);
|
||||
|
||||
//String data
|
||||
temp_sql_delete ("tagente_datos_string", "id_agente_modulo", $id_module_dest);
|
||||
|
||||
//Events (up/down monitors)
|
||||
temp_sql_delete ("tevento", "id_agentmodule", $id_module_dest);
|
||||
|
||||
//Graphs, layouts & reports
|
||||
temp_sql_delete ("tgraph_source", "id_agent_module", $id_module_dest);
|
||||
temp_sql_delete ("tlayout_data", "id_agente_modulo", $id_module_dest);
|
||||
temp_sql_delete ("treport_content", "id_agent_module", $id_module_dest);
|
||||
|
||||
//The status of the module
|
||||
temp_sql_delete ("tagente_estado", "id_agente_modulo", $id_module_dest);
|
||||
|
||||
//The actual modules, don't put anything based on
|
||||
//tagente_modulo after this
|
||||
temp_sql_delete ("tagente_modulo", "id_agente_modulo", $id_module_dest);
|
||||
} //if modulos
|
||||
} //foreach destino
|
||||
} //foreach origen_modulo
|
||||
|
||||
if ($errors > 1) {
|
||||
echo '<h3 class="error">'.__('There was an error removing the module data, the removal has been cancelled').'</h3>';
|
||||
process_sql ("ROLLBACK;");
|
||||
} else {
|
||||
echo '<h3 class="suc">'.__('Successfully removed module data').'</h3>';
|
||||
process_sql ("COMMIT;");
|
||||
}
|
||||
process_sql ("SET AUTOCOMMIT = 1;");
|
||||
return; //Page shouldn't continue anymore
|
||||
} //if $_POST['delete']
|
||||
|
||||
// -----------
|
||||
// DELETE AGENT
|
||||
// -----------
|
||||
|
||||
if (isset ($_POST["delete_agent"])) {
|
||||
echo "<h2>".__('Deleting Agent')."</h2>";
|
||||
// Initial checkings
|
||||
|
||||
// if selected more than 0 agents
|
||||
$destino = get_parameter_post ("destino", array ());
|
||||
|
||||
if (empty ($destino)) {
|
||||
echo '<h3 class="error">ERROR: '.__('You must select at least one agent to be removed').'</h3>';
|
||||
return;
|
||||
}
|
||||
|
||||
$result = delete_agent ($destino);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<h3 class="error">'.__('There was an error removing the agents. Removal has been cancelled').'</h3>';
|
||||
} else {
|
||||
echo '<h3 class="suc">'.__('Successfully removed agents').'</h3>';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// ============
|
||||
// Form view
|
||||
// ============
|
||||
if ($error)
|
||||
break;
|
||||
}
|
||||
|
||||
// title
|
||||
echo '<h2>'.__('Agent configuration'). ' > '. __('Configuration Management').'</h2>';
|
||||
echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/agentes/manage_config&operacion=1">';
|
||||
echo '<table width="650" border="0" cellspacing="4" cellpadding="4" class="databox">';
|
||||
|
||||
// Source group
|
||||
echo '<tr><td class="datost"><b>'. __('Source group'). '</b><br /><br />';
|
||||
$groups = get_user_groups ($config['id_user']);
|
||||
|
||||
print_select ($groups, "id_group", $id_group, 'javascript:this.form.submit();', '', 0, false, false, false, '" style="width:200px');
|
||||
echo '<noscript> ';
|
||||
print_submit_button (__('Filter'), "update_group", false, 'class="sub upd"');
|
||||
echo '</noscript><br /><br />';
|
||||
|
||||
// Source agent
|
||||
echo '<b>'. __('Source agent').'</b><br /><br />';
|
||||
|
||||
// Show combo with SOURCE agents
|
||||
if ($id_group > 1) { //Group -1, 0 and 1 all mean that we should select ALL
|
||||
$result = get_db_all_rows_field_filter ("tagente", "id_grupo", $id_group, "nombre");
|
||||
} else {
|
||||
$result = get_db_all_rows_in_table ("tagente", "nombre");
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
$result = array ();
|
||||
$result[0]["id_grupo"] = 0;
|
||||
$result[0]["id_agente"] = 0;
|
||||
$result[0]["nombre"] = __('No Agents in this Group');
|
||||
if ($error) {
|
||||
echo '<h3 class="error">'.__('There was an error copying the agent configuration, the copy has been cancelled').'</h3>';
|
||||
process_sql ('ROLLBACK');
|
||||
} else {
|
||||
echo '<h3 class="suc">'.__('Successfully copied').'</h3>';
|
||||
process_sql ('COMMIT');
|
||||
}
|
||||
process_sql ('SET AUTOCOMMIT = 1');
|
||||
}
|
||||
}
|
||||
|
||||
$agents = array ();
|
||||
foreach ($result as $row) {
|
||||
if (give_acl ($config["id_user"], $row["id_grupo"], "AR"))
|
||||
$agents[$row["id_agente"]] = $row["nombre"];
|
||||
$source_id_group = (int) get_parameter ('source_id_group');
|
||||
$source_id_agent = (int) get_parameter ('source_id_agent');
|
||||
$destiny_id_group = (int) get_parameter ('destiny_id_group');
|
||||
$destiny_id_agents = (array) get_parameter ('destiny_id_agent', array ());
|
||||
|
||||
$do_operation = (bool) get_parameter ('do_operation');
|
||||
|
||||
if ($do_operation) {
|
||||
process_manage_config ($source_id_agent, $destiny_id_agents);
|
||||
}
|
||||
|
||||
if ($origen == -1 || ($id_group > 1 && dame_id_grupo ($origen) != $id_group)) {
|
||||
$origen = $result[0]["id_agente"];
|
||||
//If the agent selected is not in the group selected (that
|
||||
//happens if an agent was selected and then the group was changed)
|
||||
}
|
||||
$groups = get_user_groups ();
|
||||
|
||||
$table->class = 'databox';
|
||||
$table->width = '95%';
|
||||
$table->data = array ();
|
||||
$table->style = array ();
|
||||
$table->style[0] = 'font-weight: bold; vertical-align:top';
|
||||
$table->style[2] = 'font-weight: bold';
|
||||
$table->size = array ();
|
||||
$table->size[0] = '10%';
|
||||
$table->size[1] = '40%';
|
||||
$table->size[2] = '10%';
|
||||
$table->size[3] = '40%';
|
||||
|
||||
/* Source selection */
|
||||
$table->id = 'source_table';
|
||||
$table->data[0][0] = __('Group');
|
||||
$table->data[0][1] = print_select ($groups, 'source_id_group', $source_id_group,
|
||||
false, '', '', true);
|
||||
$table->data[0][2] = __('Agent');
|
||||
$table->data[0][3] = print_select (get_group_agents ($source_id_group, false, "none"),
|
||||
'source_id_agent', $source_id_agent, false, __('Select'), 0, true);
|
||||
$table->data[0][3] .= '<span id="source_agent_loading" class="invisible">';
|
||||
$table->data[0][3] .= '<img src="images/spinner.gif" />';
|
||||
$table->data[0][3] .= '</span>';
|
||||
|
||||
echo '<form id="manage_config_form" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/manage_config">';
|
||||
|
||||
echo '<fieldset id="fieldset_source">';
|
||||
echo '<legend><span>'.__('Source');
|
||||
pandora_help ('manageconfig');
|
||||
echo '</span></legend>';
|
||||
print_table ($table);
|
||||
echo '</fieldset>';
|
||||
|
||||
/* Target selection */
|
||||
$table->id = 'target_table';
|
||||
$table->data = array ();
|
||||
|
||||
print_select ($agents, "origen", $origen, 'javascript:this.form.submit();', '', 0, false, false, false, '" style="width:200px');
|
||||
echo '<noscript> ';
|
||||
print_submit_button (__('Get Info'), "update_agent", false, 'class="sub upd"');
|
||||
echo '</noscript><br /><br />';
|
||||
|
||||
// Source Module(s)
|
||||
$result = get_db_all_rows_field_filter ("tagente_modulo", "id_agente", $origen, "nombre");
|
||||
$modules = array ();
|
||||
if ($source_id_agent)
|
||||
$modules = get_agent_modules ($source_id_agent, 'nombre');
|
||||
|
||||
if ($result === false) {
|
||||
$result = array ();
|
||||
$result[0]["id_agente_modulo"] = -1;
|
||||
if ($origen > 0) {
|
||||
$result[0]["nombre"] = __('No modules for this agent');
|
||||
} else {
|
||||
$result[0]["nombre"] = __('No agent selected');
|
||||
}
|
||||
}
|
||||
foreach ($result as $row) {
|
||||
$modules[$row["id_agente_modulo"]] = $row["nombre"];
|
||||
$table->data['operations'][0] = __('Operations');
|
||||
$table->data['operations'][1] = '<span class="with_modules"'.(empty ($modules) ? ' class="invisible"': '').'>';
|
||||
$table->data['operations'][1] .= print_checkbox ('copy_modules', 1, true, true);
|
||||
$table->data['operations'][1] .= print_label (__('Copy modules'), 'checkbox-copy_modules', true);
|
||||
$table->data['operations'][1] .= '</span><br />';
|
||||
|
||||
$table->data['operations'][1] .= '<span class="with_alerts"'.(empty ($alerts) ? ' class="invisible"': '').'>';
|
||||
$table->data['operations'][1] .= print_checkbox ('copy_alerts', 1, true, true);
|
||||
$table->data['operations'][1] .= print_label (__('Copy alerts'), 'checkbox-copy_alerts', true);
|
||||
$table->data['operations'][1] .= '</span>';
|
||||
|
||||
$table->data[1][0] = __('Modules');
|
||||
$table->data[1][1] = '<span class="with_modules"'.(empty ($modules) ? ' class="invisible"': '').'>';
|
||||
$table->data[1][1] .= print_select ($modules,
|
||||
'target_modules[]', 0, false, '', '', true, true);
|
||||
$table->data[1][1] .= '</span>';
|
||||
$table->data[1][1] .= '<span class="without_modules"'.(! empty ($modules) ? ' class="invisible"': '').'>';
|
||||
$table->data[1][1] .= '<em>'.__('No modules for this agent').'</em>';
|
||||
$table->data[1][1] .= '</span>';
|
||||
|
||||
$table->data[2][0] = __('Alerts');
|
||||
|
||||
$agent_alerts = array ();
|
||||
if ($source_id_agent)
|
||||
$agent_alerts = get_agent_alerts_simple ($source_id_agent);
|
||||
$alerts = array ();
|
||||
foreach ($agent_alerts as $alert) {
|
||||
$name = get_alert_template_name ($alert['id_alert_template']);
|
||||
$name .= ' (<em>'.$modules[$alert['id_agent_module']].'</em>)';
|
||||
$alerts[$alert['id']] = $name;
|
||||
}
|
||||
|
||||
echo '<b>'.__('Modules').'</b><br /><br />';
|
||||
print_select ($modules, "origen_modulo[]", '', '', '', 0, false, true, false, '" style="width:250px');
|
||||
echo '</td>';
|
||||
|
||||
echo '<td class="datost">';
|
||||
echo '<b>'.__('Targets'). '</b>';
|
||||
pandora_help ('manageconfig');
|
||||
echo '<br /><br />';
|
||||
echo '<table>';
|
||||
echo '<tr><td class="datos">'.__('Modules').'</td><td class="datos">';
|
||||
print_checkbox_extended ("modules", "1", false, false, '', 'class="chk"');
|
||||
$table->data[2][1] = '<span class="with_alerts"'.(empty ($alerts) ? ' class="invisible"': '').'>';
|
||||
$table->data[2][1] .= print_select ($alerts,
|
||||
'target_alerts[]', 0, false, '', '', true, true);
|
||||
$table->data[2][1] .= '</span>';
|
||||
$table->data[2][1] .= '<span class="without_alerts"'.(! empty ($modules) ? ' class="invisible"': '').'>';
|
||||
$table->data[2][1] .= '<em>'.__('No alerts for this agent').'</em>';
|
||||
$table->data[2][1] .= '</span>';
|
||||
|
||||
echo '</td></tr><tr><td class="datos">'.__('Alerts').'<td class="datos">';
|
||||
print_checkbox_extended ("alerts", "1", false, false, '', 'class="chk"');
|
||||
echo '</td></tr></table></td></tr>';
|
||||
|
||||
echo '<div id="modules_loading" class="loading invisible">';
|
||||
echo '<img src="images/spinner.gif" />';
|
||||
echo __('Loading').'…';
|
||||
echo '</div>';
|
||||
|
||||
// Destination agent
|
||||
$result = get_db_all_rows_in_table ("tagente", "nombre");
|
||||
$agents = array ();
|
||||
if ($result === false) {
|
||||
$result = array ();
|
||||
}
|
||||
echo '<fieldset id="fieldset_targets"'.($source_id_agent ? '' : ' class="invisible"').'>';
|
||||
echo '<legend><span>'.__('Targets').'</span></legend>';
|
||||
print_table ($table);
|
||||
echo '</fieldset>';
|
||||
|
||||
foreach ($result as $row) {
|
||||
if (give_acl ($config["id_user"], $row["id_grupo"], "AW"))
|
||||
$agents[$row["id_agente"]] = $row["nombre"];
|
||||
}
|
||||
/* Destiny selection */
|
||||
$table->id = 'destiny_table';
|
||||
$table->data = array ();
|
||||
$table->data[0][0] = __('Group');
|
||||
$table->data[0][1] = print_select ($groups, 'destiny_id_group', $destiny_id_group,
|
||||
false, '', '', true);
|
||||
$table->data[0][1] .= '<span id="destiny_agent_loading" class="invisible">';
|
||||
$table->data[0][1] .= '<img src="images/spinner.gif" />';
|
||||
$table->data[0][1] .= '</span>';
|
||||
|
||||
echo '<tr><td class="datost">';
|
||||
echo '<b>'.__('To Agent(s):').'</b><br /><br />';
|
||||
print_select ($agents, "destino[]", $destino, '', '', 0, false, true, false, '" style="width:250px');
|
||||
echo '</td>';
|
||||
$table->data[1][0] = __('Agent');
|
||||
$table->data[1][1] = print_select (get_group_agents ($destiny_id_group, false, "none"),
|
||||
'destiny_id_agent[]', 0, false, '', '', true, true);
|
||||
|
||||
// Form buttons
|
||||
echo '<td align="left" class="datosb">';
|
||||
echo "<br /><br />";
|
||||
print_submit_button (__('Copy Modules/Alerts'), "copy", false, 'class="sub copy" onClick="if (!confirm("'.__('Are you sure?').'")) return false;"');
|
||||
pandora_help ('manageconfig');
|
||||
echo "<br /><br />";
|
||||
print_submit_button (__('Delete Modules/Alerts'), "delete", false, 'class="sub delete" onClick="if (!confirm("'.__('Are you sure you want to delete these modules and alerts?').'")) return false;"');
|
||||
pandora_help ('manageconfig');
|
||||
echo "<br /><br />";
|
||||
print_submit_button (__('Delete Agents'), "delete_agent", false, 'class="sub delete" onClick="if (!confirm("'.__('Are you sure you want to delete these agents?').'")) return false;"');
|
||||
pandora_help ('manageconfig');
|
||||
echo '</td></tr>';
|
||||
echo '</table>';
|
||||
echo '<fieldset id="fieldset_destiny"'.($source_id_agent ? '' : ' class="invisible"').'>';
|
||||
echo '<legend><span>'.__('To agent(s)').'</span></legend>';
|
||||
print_table ($table);
|
||||
echo '</fieldset>';
|
||||
|
||||
echo '<div class="action-buttons" style="width: 90%">';
|
||||
print_input_hidden ('do_operation', 1);
|
||||
print_submit_button (__('Go'), 'go', false, 'class="sub next"');
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
|
||||
echo '<h3 class="error invisible" id="message"> </h3>';
|
||||
|
||||
$config['jquery'][] = 'form';
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready (function () {
|
||||
$("#source_id_group").change (function () {
|
||||
$("#source_agent_loading").show ();
|
||||
var select = $("#source_id_agent").disable ();
|
||||
/* Remove all but "Select" */
|
||||
$("option[value!=0]", select).remove ();
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/groups/group_list",
|
||||
"get_group_agents" : 1,
|
||||
"id_group" : this.value
|
||||
},
|
||||
function (data, status) {
|
||||
jQuery.each (data, function (id, value) {
|
||||
$(select).append ($("<option></option>").attr ("value", id).html (value));
|
||||
});
|
||||
$("#source_agent_loading").hide ();
|
||||
$("#source_id_agent").enable ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
|
||||
$("#source_id_agent").change (function () {
|
||||
var id_agent = this.value;
|
||||
if (id_agent == 0) {
|
||||
return;
|
||||
}
|
||||
$("#modules_loading").show ();
|
||||
$("#target_modules\\[\\] option, #target_alerts\\[\\] option").remove ();
|
||||
$("#target_modules\\[\\], #target_alerts\\[\\]").disable ();
|
||||
$("#destiny_id_agent\\[\\] option").show ();
|
||||
$("#destiny_id_agent\\[\\] option[value="+id_agent+"]").hide ();
|
||||
var no_modules;
|
||||
var no_alerts;
|
||||
/* Get modules */
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "operation/agentes/ver_agente",
|
||||
"get_agent_modules_json" : 1,
|
||||
"id_agent" : this.value,
|
||||
"filter" : "disabled = 0"
|
||||
},
|
||||
function (data, status) {
|
||||
if (data.length == 0) {
|
||||
no_modules = true;
|
||||
} else {
|
||||
jQuery.each (data, function (i, val) {
|
||||
option = $("<option></option>")
|
||||
.attr ("value", val["id_agente_modulo"])
|
||||
.append (val["nombre"]);
|
||||
$("#target_modules\\[\\]").append (option);
|
||||
});
|
||||
|
||||
no_modules = false;
|
||||
}
|
||||
|
||||
/* Get alerts */
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/agentes/alert_manager",
|
||||
"get_agent_alerts_simple" : 1,
|
||||
"id_agent" : id_agent
|
||||
},
|
||||
function (data, status) {
|
||||
if (! data) {
|
||||
no_alerts = true;
|
||||
} else {
|
||||
jQuery.each (data, function (i, val) {
|
||||
module_name = $("<em></em>").append (val["module_name"]);
|
||||
option = $("<option></option>")
|
||||
.attr ("value", val["id"])
|
||||
.append (val["template"]["name"])
|
||||
.append (" (")
|
||||
.append (module_name)
|
||||
.append (")");
|
||||
$("#target_alerts\\[\\]").append (option);
|
||||
});
|
||||
no_alerts = false;
|
||||
}
|
||||
$("#modules_loading").hide ();
|
||||
|
||||
if (no_modules && no_alerts) {
|
||||
/* Nothing to export from selected agent */
|
||||
$("#fieldset_destiny").hide ();
|
||||
|
||||
$("span.without_modules, span.without_alerts").show ();
|
||||
$("span.with_modules, span.with_alerts, #target_table-operations").hide ();
|
||||
} else {
|
||||
if (no_modules) {
|
||||
$("span.without_modules").show ();
|
||||
$("span.with_modules").hide ();
|
||||
$("#checkbox-copy_modules").uncheck ();
|
||||
} else {
|
||||
$("span.without_modules").hide ();
|
||||
$("span.with_modules").show ();
|
||||
$("#checkbox-copy_modules").check ();
|
||||
}
|
||||
|
||||
if (no_alerts) {
|
||||
$("span.without_alerts").show ();
|
||||
$("span.with_alerts").hide ();
|
||||
$("#checkbox-copy_alerts").uncheck ();
|
||||
} else {
|
||||
$("span.without_alerts").hide ();
|
||||
$("span.with_alerts").show ();
|
||||
$("#checkbox-copy_alerts").check ();
|
||||
}
|
||||
$("#fieldset_destiny, #target_table-operations").show ();
|
||||
}
|
||||
$("#fieldset_targets").show ();
|
||||
$("#target_modules\\[\\], #target_alerts\\[\\]").enable ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
|
||||
$("#destiny_id_group").change (function () {
|
||||
$("#destiny_agent_loading").show ();
|
||||
var select = $("#destiny_id_agent\\[\\]").disable ();
|
||||
$("#destiny_id_agent\\[\\] option").remove ();
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/groups/group_list",
|
||||
"get_group_agents" : 1,
|
||||
"id_group" : this.value
|
||||
},
|
||||
function (data, status) {
|
||||
jQuery.each (data, function (id, value) {
|
||||
option = $("<option></option>").attr ("value", id).html (value)
|
||||
if ($("#source_id_agent").fieldValue ().in_array (id)) {
|
||||
/* Hide source agent */
|
||||
$(option).hide ();
|
||||
}
|
||||
$(select).append (option);
|
||||
});
|
||||
$("#destiny_agent_loading").hide ();
|
||||
$("#destiny_id_agent\\[\\]").enable ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
|
||||
$("#manage_config_form").submit (function () {
|
||||
$("h3:not([id=message])").remove ();
|
||||
if ($("#source_id_agent").attr ("value") == 0) {
|
||||
$("#message").showMessage ("<?php echo __('No source agent to copy') ?>");
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_modules = $("#checkbox-copy_modules");
|
||||
copy_alerts = $("#checkbox-copy_alerts");
|
||||
|
||||
if (! $(copy_modules).attr ("checked") && ! $(copy_alerts).attr ("checked")) {
|
||||
$("#message").showMessage ("<?php echo __('No operation selected') ?>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($(copy_modules).attr ("checked") && $("#target_modules\\[\\]").fieldValue ().length == 0) {
|
||||
$("#message").showMessage ("<?php echo __('No modules have been selected') ?>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($("#destiny_id_agent\\[\\]").fieldValue ().length == 0) {
|
||||
$("#message").showMessage ("<?php echo __('No destiny agent(s) to copy') ?>");
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#message").hide ();
|
||||
return true;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -24,53 +24,6 @@ if (! give_acl ($config['id_user'], 0, "AW")) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (defined ('AJAX')) {
|
||||
$get_group_agents = (bool) get_parameter ('get_group_agents');
|
||||
$get_agent_alerts = (bool) get_parameter ('get_agent_alerts');
|
||||
|
||||
if ($get_group_agents) {
|
||||
$id_group = (int) get_parameter ('id_group');
|
||||
echo json_encode (get_group_agents ($id_group));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_agent_alerts) {
|
||||
$id_agent = (int) get_parameter ('id_agent');
|
||||
if ($id_agent <= 0) {
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
$id_group = get_agent_group ($id_agent);
|
||||
|
||||
if (! give_acl ($config['id_user'], $id_group, "AR")) {
|
||||
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
|
||||
"Trying to access Alert Management");
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
|
||||
require_once ('include/functions_agents.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
|
||||
$alerts = get_agent_alerts_simple ($id_agent);
|
||||
if (empty ($alerts)) {
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
|
||||
$retval = array ();
|
||||
foreach ($alerts as $alert) {
|
||||
$alert['template'] = get_alert_template ($alert['id_alert_template']);
|
||||
$alert['module_name'] = get_agentmodule_name ($alert['id_agent_module']);
|
||||
$alert['agent_name'] = get_agentmodule_agent_name ($alert['id_agent_module']);
|
||||
$retval[$alert['id']] = $alert;
|
||||
}
|
||||
|
||||
echo json_encode ($retval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$id = (int) get_parameter ('id');
|
||||
$id_agent = (int) get_parameter ('id_agent');
|
||||
|
||||
|
@ -637,15 +590,16 @@ if ($step == 1) {
|
|||
print_select (get_alert_compound_operations (), 'operations');
|
||||
echo '</div>';
|
||||
}
|
||||
$config['jquery'][] = 'form';
|
||||
$config['jquery'][] = 'tablesorter';
|
||||
$config['jquery'][] = 'tablesorter.pager';
|
||||
$config['jquery'][] = 'ui.core';
|
||||
$config['jquery'][] = 'timeentry';
|
||||
|
||||
$config['css'][] = 'timeentry';
|
||||
?>
|
||||
|
||||
<script type="text/javascript" src="include/javascript/jquery.form.js"></script>
|
||||
<script type="text/javascript" src="include/javascript/jquery.tablesorter.js"></script>
|
||||
<script type="text/javascript" src="include/javascript/jquery.tablesorter.pager.js"></script>
|
||||
<script type="text/javascript" src="include/javascript/pandora_alerts.js"></script>
|
||||
<link rel="stylesheet" href="include/styles/timeentry.css" type="text/css" media="screen">
|
||||
<script src="include/javascript/jquery.ui.core.js"></script>
|
||||
<script src="include/javascript/jquery.timeentry.js"></script>
|
||||
<script src="include/languages/time_<?php echo $config['language']; ?>.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -730,7 +684,7 @@ $(document).ready (function () {
|
|||
/* Remove all but "Select" */
|
||||
$("option[value!=0]", select).remove ();
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/alerts/configure_alert_compound",
|
||||
{"page" : "godmode/groups/group_list",
|
||||
"get_group_agents" : 1,
|
||||
"id_group" : this.value
|
||||
},
|
||||
|
@ -756,8 +710,8 @@ $(document).ready (function () {
|
|||
$("#alerts_loading").show ();
|
||||
$("#alert_list tbody").empty ();
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/alerts/configure_alert_compound",
|
||||
"get_agent_alerts" : 1,
|
||||
{"page" : "godmode/agentes/alert_manager",
|
||||
"get_agent_alerts_simple" : 1,
|
||||
"id_agent" : this.value
|
||||
},
|
||||
function (data, status) {
|
||||
|
|
|
@ -31,17 +31,39 @@ if (! give_acl($config['id_user'], 0, "PM")) {
|
|||
|
||||
if (defined ('AJAX')) {
|
||||
$get_group_json = (bool) get_parameter ('get_group_json');
|
||||
|
||||
$get_group_agents = (bool) get_parameter ('get_group_agents');
|
||||
|
||||
if ($get_group_json) {
|
||||
$id_group = (int) get_parameter ('id_group');
|
||||
|
||||
|
||||
if (! give_acl ($config['id_user'], $id_group, "AR")) {
|
||||
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
|
||||
"Trying to access Alert Management");
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
|
||||
$group = get_db_row ('tgrupo', 'id_grupo', $id_group);
|
||||
|
||||
|
||||
echo json_encode ($group);
|
||||
exit ();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_group_agents) {
|
||||
$id_group = (int) get_parameter ('id_group');
|
||||
|
||||
if (! give_acl ($config['id_user'], $id_group, "AR")) {
|
||||
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
|
||||
"Trying to access Alert Management");
|
||||
echo json_encode (false);
|
||||
return;
|
||||
}
|
||||
|
||||
echo json_encode (get_group_agents ($id_group, false, "none"));
|
||||
return;
|
||||
}
|
||||
|
||||
exit ();
|
||||
return;
|
||||
}
|
||||
|
||||
$create_group = (bool) get_parameter ('create_group');
|
||||
|
|
|
@ -609,16 +609,20 @@ function get_alert_agent_module ($id_alert_agent_module) {
|
|||
return get_db_row ('talert_template_modules', 'id', $id_alert_agent_module);
|
||||
}
|
||||
|
||||
function get_alerts_agent_module ($id_agent_module, $disabled = false) {
|
||||
function get_alerts_agent_module ($id_agent_module, $disabled = false, $filter = false) {
|
||||
$id_alert_agent_module = safe_int ($id_agent_module, 0);
|
||||
|
||||
$filter = '';
|
||||
$where = '';
|
||||
if (! $disabled)
|
||||
$filter .= 'AND disabled = 0';
|
||||
$where .= ' AND disabled = 0 ';
|
||||
|
||||
if ($filter) {
|
||||
$where .= ' AND '.format_array_to_where_clause_sql ($filter);
|
||||
}
|
||||
|
||||
$sql = sprintf ('SELECT * FROM talert_template_modules
|
||||
WHERE id_agent_module = %d %s',
|
||||
$id_agent_module, $filter);
|
||||
$id_agent_module, $where);
|
||||
|
||||
return get_db_all_rows_sql ($sql);
|
||||
}
|
||||
|
@ -764,6 +768,52 @@ function validate_alert_agent_module ($id_alert_agent_module) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy an alert defined in a module agent to other module agent.
|
||||
*
|
||||
* This function avoid duplicated insertion.
|
||||
*
|
||||
* @param int Source agent module id.
|
||||
* @param int Detiny agent module id.
|
||||
*
|
||||
* @return New alert id on success. Existing alert id if it already exists.
|
||||
* False on error.
|
||||
*/
|
||||
function copy_alert_agent_module_to_agent_module ($id_agent_alert, $id_destiny_module) {
|
||||
$alert = get_alert_agent_module ($id_agent_alert);
|
||||
if ($alert === false)
|
||||
return false;
|
||||
|
||||
$alerts = get_alerts_agent_module ($id_destiny_module, false,
|
||||
array ('id_alert_template' => $alert['id_alert_template']));
|
||||
if (! empty ($alerts)) {
|
||||
return $alerts[0]['id'];
|
||||
}
|
||||
|
||||
/* PHP copy arrays on assignment */
|
||||
$new_alert = array ();
|
||||
$new_alert['id_agent_module'] = $id_destiny_module;
|
||||
$new_alert['id_alert_template'] = $alert['id_alert_template'];
|
||||
|
||||
$id_new_alert = @process_sql_insert ('talert_template_modules', $new_alert);
|
||||
if ($id_new_alert === false) {
|
||||
return false;
|
||||
}
|
||||
$actions = get_alert_agent_module_actions ($id_agent_alert);
|
||||
if (empty ($actions))
|
||||
return $id_new_alert;
|
||||
|
||||
foreach ($actions as $action) {
|
||||
$result = add_alert_agent_module_action ($id_new_alert, $action['id'],
|
||||
array ('fires_min' => $action['fires_min'],
|
||||
'fires_max' => $action['fires_max']));
|
||||
if ($result === false)
|
||||
return false;
|
||||
}
|
||||
|
||||
return $id_new_alert;
|
||||
}
|
||||
|
||||
/* Compound alerts */
|
||||
|
||||
function get_alert_compound_threshold_values () {
|
||||
|
|
|
@ -331,7 +331,8 @@ function get_agent_module ($id_agent_module) {
|
|||
*
|
||||
* @param mixed Agent id to get modules. It can also be an array of agent id's.
|
||||
* @param mixed Array, comma delimited list or singular value of rows to
|
||||
* select. If nothing is specified, nombre will be selected.
|
||||
* select. If nothing is specified, nombre will be selected. A special
|
||||
* character "*" will select all the values.
|
||||
* @param mixed Aditional filters to the modules. It can be an indexed array
|
||||
* (keys would be the field name and value the expected value, and would be
|
||||
* joined with an AND operator) or a string, including any SQL clause (without
|
||||
|
@ -367,7 +368,7 @@ function get_agent_modules ($id_agent, $details = false, $filter = false) {
|
|||
if (is_array ($filter)) {
|
||||
$fields = array ();
|
||||
foreach ($filter as $field => $value) {
|
||||
array_push ($fields, $field.'='.$value);
|
||||
array_push ($fields, $field.'="'.$value.'"');
|
||||
}
|
||||
$where .= implode (' AND ', $fields);
|
||||
} else {
|
||||
|
@ -381,10 +382,11 @@ function get_agent_modules ($id_agent, $details = false, $filter = false) {
|
|||
$details = safe_input ($details);
|
||||
}
|
||||
|
||||
$sql = sprintf ('SELECT id_agente_modulo,%s
|
||||
$sql = sprintf ('SELECT %s%s
|
||||
FROM tagente_modulo
|
||||
%s
|
||||
ORDER BY nombre',
|
||||
$details != '*' ? 'id_agente_modulo,' : '',
|
||||
implode (",", (array) $details),
|
||||
$where);
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
|
@ -395,7 +397,7 @@ function get_agent_modules ($id_agent, $details = false, $filter = false) {
|
|||
|
||||
$modules = array ();
|
||||
foreach ($result as $row) {
|
||||
if (is_array ($details)) {
|
||||
if (is_array ($details) || $details == '*') {
|
||||
//Just stack the information in array by ID
|
||||
$modules[$row['id_agente_modulo']] = $row;
|
||||
} else {
|
||||
|
@ -1675,6 +1677,64 @@ function format_array_to_update_sql ($values) {
|
|||
return implode (", ", $fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an array of values into a SQL where clause string.
|
||||
*
|
||||
* This function is useful to generate a WHERE clause for a SQL sentence from
|
||||
* a list of values. Example code:
|
||||
*
|
||||
* <code>
|
||||
$values = array ();
|
||||
$values['name'] = "Name";
|
||||
$values['description'] = "Long description";
|
||||
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_sql ($values).' LIMIT 20';
|
||||
echo $sql;
|
||||
</code>
|
||||
* Will return:
|
||||
* <code>
|
||||
* SELECT * FROM table WHERE `name` = "Name" AND `description` = "Long description" LIMIT 20
|
||||
* </code>
|
||||
*
|
||||
* @param array Values to be formatted in an array indexed by the field name.
|
||||
* @param string Join operator. AND by default.
|
||||
*
|
||||
* @return string Values joined into an SQL string that can fits into the WHERE
|
||||
* clause of an SQL sentence.
|
||||
*/
|
||||
function format_array_to_where_clause_sql ($values, $join = 'AND') {
|
||||
$fields = array ();
|
||||
|
||||
if (! is_array ($values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$query = '';
|
||||
$i = 1;
|
||||
$max = count ($values);
|
||||
foreach ($values as $field => $value) {
|
||||
if ($field[0] != "`") {
|
||||
$field = "`".$field."`";
|
||||
}
|
||||
|
||||
if (is_null ($value)) {
|
||||
$query .= sprintf ("%s IS NULL", $field);
|
||||
} elseif (is_int ($value) || is_bool ($value)) {
|
||||
$query .= sprintf ("%s = %d", $field, $value);
|
||||
} else if (is_float ($value) || is_double ($value)) {
|
||||
$query .= sprintf ("%s = %f", $field, $value);
|
||||
} else {
|
||||
$query .= sprintf ("%s = '%s'", $field, $value);
|
||||
}
|
||||
|
||||
if ($i < $max) {
|
||||
$query .= $join;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of an alert assigned to an agent module.
|
||||
*
|
||||
|
@ -2523,28 +2583,7 @@ function process_sql_update ($table, $values, $where = false, $where_join = 'AND
|
|||
/* FIXME: Should we clean the string for sanity? */
|
||||
$query .= $where;
|
||||
} else if (is_array ($where)) {
|
||||
$i = 1;
|
||||
$max = count ($where);
|
||||
foreach ($where as $field => $value) {
|
||||
if ($field[0] != "`") {
|
||||
$field = "`".$field."`";
|
||||
}
|
||||
|
||||
if (is_null ($value)) {
|
||||
$query .= sprintf ("%s IS NULL", $field);
|
||||
} elseif (is_int ($value) || is_bool ($value)) {
|
||||
$query .= sprintf ("%s = %d", $field, $value);
|
||||
} else if (is_float ($value) || is_double ($value)) {
|
||||
$query .= sprintf ("%s = %f", $field, $value);
|
||||
} else {
|
||||
$query .= sprintf ("%s = '%s'", $field, $value);
|
||||
}
|
||||
|
||||
if ($i < $max) {
|
||||
$query .= $where_join;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$query .= format_array_to_where_clause_sql ($where);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
?>
|
|
@ -736,8 +736,11 @@ select#template, select#action {
|
|||
.invisible {
|
||||
display: none;
|
||||
}
|
||||
#label-checkbox-matches_value {
|
||||
#label-checkbox-matches_value,
|
||||
#label-checkbox-copy_modules,
|
||||
#label-checkbox-copy_alerts {
|
||||
display: inline;
|
||||
font-weight: normal;
|
||||
}
|
||||
input[type=image] {
|
||||
border:0px;
|
||||
|
@ -753,7 +756,10 @@ table#simple select#id_plugin {
|
|||
}
|
||||
table#simple input#text-plugin_parameter,
|
||||
table#simple input#text-snmp_oid,
|
||||
table#simple select#prediction_module {
|
||||
table#simple select#prediction_module,
|
||||
table#source_table select,
|
||||
table#destiny_table select,
|
||||
table#target_table select {
|
||||
width: 100%;
|
||||
}
|
||||
.clickable {
|
||||
|
@ -856,10 +862,19 @@ img.right {
|
|||
.text-right {
|
||||
text-align:right;
|
||||
}
|
||||
fieldset {
|
||||
border: 2px solid #E9F3D2;
|
||||
padding: 0 0 0 10px;
|
||||
width: 90%;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
fieldset legend span {
|
||||
font-style:italic;
|
||||
|
||||
}
|
||||
|
||||
/* timeEntry styles */
|
||||
.timeEntry_control {
|
||||
vertical-align: middle;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ if (defined ('AJAX')) {
|
|||
|
||||
if ($get_agent_json) {
|
||||
$id_agent = (int) get_parameter ('id_agent');
|
||||
|
||||
$agent = get_db_row ('tagente', 'id_agente', $id_agent);
|
||||
|
||||
echo json_encode ($agent);
|
||||
|
@ -38,7 +39,10 @@ if (defined ('AJAX')) {
|
|||
|
||||
if ($get_agent_modules_json) {
|
||||
$id_agent = (int) get_parameter ('id_agent');
|
||||
$agent_modules = get_db_all_rows_field_filter ('tagente_modulo', 'id_agente', $id_agent, "nombre");
|
||||
$filter = (string) get_parameter ('filter');
|
||||
|
||||
$agent_modules = get_agent_modules ($id_agent, "*",
|
||||
($filter != '' ? $filter : false));
|
||||
|
||||
echo json_encode ($agent_modules);
|
||||
exit ();
|
||||
|
|
Loading…
Reference in New Issue