2008-11-20 Evi Vanoost <vanooste@rcbi.rochester.edu>

* reporting/fgraph.php: Updated for some faster processing
	and new functions.

	* operation/events/events.php,
	operation/agentes/estado_alertas,
	include/functions_reporting.php, 
	godmode/reporting/reporting_bulder.php, 
	godmode/reporting/map_builder.php, godmode/db/db_info.php: 
	Function name updates
	
	* include/functions_html.php: Small style update
	
	* include/functions_db.php: get_agents_in_group is now
	get_group_agents. Accepts array and specified case. 
	get_modules_in_agent is now get_agentmodules and accepts arrays
	of agents as well as which details to select. Deprecated 
	dame_nombre_agente in favor of get_agent_name which accepts case.
	Fixed get_agent_addresses for use in select boxes. Added filter
	to get_agentmodule_count
	
	* godmode/db/db_purge.php: Fixed queries and style updates
	
	* godmode/agentes/configurar_agente.php: Fixed IP select box
	
	* godmode/agentes/agent_manager.php: Style update and fixed a bug

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1250 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2008-11-20 14:09:26 +00:00
parent 4ea1e37444
commit b184efd4d5
13 changed files with 292 additions and 255 deletions

View File

@ -1,3 +1,31 @@
2008-11-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* reporting/fgraph.php: Updated for some faster processing
and new functions.
* operation/events/events.php,
operation/agentes/estado_alertas,
include/functions_reporting.php,
godmode/reporting/reporting_bulder.php,
godmode/reporting/map_builder.php, godmode/db/db_info.php:
Function name updates
* include/functions_html.php: Small style update
* include/functions_db.php: get_agents_in_group is now
get_group_agents. Accepts array and specified case.
get_modules_in_agent is now get_agentmodules and accepts arrays
of agents as well as which details to select. Deprecated
dame_nombre_agente in favor of get_agent_name which accepts case.
Fixed get_agent_addresses for use in select boxes. Added filter
to get_agentmodule_count
* godmode/db/db_purge.php: Fixed queries and style updates
* godmode/agentes/configurar_agente.php: Fixed IP select box
* godmode/agentes/agent_manager.php: Style update and fixed a bug
2008-11-19 Jorge Gonzalez <jorgegonz@svn.gnome.org>
* pandoradb_data.sql: Added Arab and Turkish translations to the

View File

@ -19,8 +19,9 @@
// ========================
// AGENT GENERAL DATA FORM
// ========================
// Load global vars
require ('include/config.php');
require_once ('include/config.php');
enterprise_include ('godmode/agentes/agent_manager.php');
@ -30,7 +31,7 @@ if (! give_acl ($config['id_user'], 0, "AW")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access agent manager");
require ("general/noaccess.php");
return;
exit;
}
echo "<h2>".__('Agent configuration');
@ -41,10 +42,13 @@ if (isset($_GET["create_agent"])){
echo " &gt; ".__('Update agent');
}
echo "</h2>";
echo "<div style='height: 5px'> </div>";
echo '<div style="height: 5px">&nbsp;</div>';
// Agent remote configuration editor
$agent_md5 = md5 ($nombre_agente, FALSE);
$filename['md5'] = $config["remote_config"] . "/" . $agent_md5 . ".md5";
$filename['conf'] = $config["remote_config"] . "/" . $agent_md5 . ".conf";
if (isset ($_GET["disk_conf"])) {
require ("agent_disk_conf_editor.php");
exit;
@ -52,168 +56,111 @@ if (isset($_GET["disk_conf"])){
// Agent remote configuration DELETE
if (isset($_GET["disk_conf_delete"])) {
$agent_md5 = md5($nombre_agente, FALSE);
$file_name = $config["remote_config"] . "/" . $agent_md5 . ".conf";
unlink ($file_name);
$file_name = $config["remote_config"] . "/" . $agent_md5 . ".md5";
unlink ($file_name);
//TODO: Get this working on computers where the Pandora server(s) are not on the webserver
//TODO: Get a remote_config editor working in the open version
unlink ($filename['md5']);
unlink ($filename['conf']);
}
echo '<form name="conf_agent" method="post" action="index.php?sec=gagente&
sec2=godmode/agentes/configurar_agente">';
echo '<table width="650" id="table-agent-configuration" cellpadding="4" cellspacing="4" class="databox_color">';
echo "<tr>";
echo '<td class="datos"><b>'.__('Agent name').'</b><a href="#" class="tip">&nbsp;<span>'.__('The Agent\'s name must be the same as the one defined at the Console').'</span></a></td><td class="datos">';
print_input_text ('agente', $nombre_agente, '', 30, 100);
echo '<form name="conf_agent" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente">';
$table->width = 650;
$table->cellpadding = 4;
$table->cellspacing = 4;
$table->class = "databox_color";
$table->head = array ();
$table->data = array ();
$table->data[0][0] = '<b>'.__('Agent name').'</b>'.print_help_tip (__("The agent's name must be the same as the one defined at the console"), true);
$table->data[0][1] = print_input_text ('agente', $nombre_agente, '', 30, 100,true);
if (isset ($id_agente) && $id_agente != "") {
echo "
<a href='index.php?sec=estado&
sec2=operation/agentes/ver_agente&id_agente=".$id_agente."'>
<img src='images/lupa.png' border='0' align='middle' title='".__('Agent detail')."'></a>";
}
// Remote configuration available
if (file_exists ($config["remote_config"] . "/" . $agent_md5 . ".md5")) {
echo "
<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&id_agente=".$id_agente."&disk_conf=" . $agent_md5 . "'>
<img src='images/application_edit.png' border='0' align='middle' title='".__('This agent can be remotely configured')."'></a>";
echo '<a href="#" class="tip">&nbsp;<span>'.__('You can remotely edit this agent configuration').'</span></a>';
$table->data[0][1] .= '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'">
<img src="images/lupa.png" border="0" title="'.__('Agent detail').'"></a>';
}
echo '<tr><td class="datos2">';
echo '<b>'.__('IP Address').'</b>';
echo '<td class="datos2">';
print_input_text ('direccion', $direccion_agente, '', 16, 100);
// Remote configuration available
if (file_exists ($filename['md5'])) {
$table->data[0][1] .= '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&id_agente='.$id_agente.'&disk_conf='.$agent_md5.'">
<img src="images/application_edit.png" border="0" title="'.__('This agent can be remotely configured').'"></a>'.print_help_tip (__('You can remotely edit this agent configuration'), true);
}
$table->data[1][0] = '<b>'.__('IP Address').'</b>';
$table->data[1][1] = print_input_text ('direccion', $direccion_agente, '', 16, 100, true);
if ($create_agent != 1) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
$table->data[1][1] .= '&nbsp;&nbsp;&nbsp;&nbsp;';
echo '<select name="address_list">';
$sql1 = "SELECT * FROM taddress, taddress_agent
WHERE taddress.id_a = taddress_agent.id_a
AND taddress_agent.id_agent = $id_agente";
if ($result=mysql_query($sql1))
while ($row=mysql_fetch_array($result)){
echo "<option value='".salida_limpia($row["ip"])."'>".salida_limpia($row["ip"])."&nbsp;&nbsp;";
}
echo "</select>";
$ip_all = get_agent_addresses ($id_agente);
echo "<input name='delete_ip' type=checkbox value='1'> ".__('Delete selected');
echo "</td>";
$table->data[1][1] .= print_select ($ip_all, "address_list", $direccion_agente, '', '', 0, true);
$table->data[1][1] .= print_checkbox ("delete_ip", 1, false, true).__('Delete selected');
}
echo '<tr><td class="datos"><b>'.__('Parent').'</b>';
echo '<td class="datos">';
print_select_from_sql ('SELECT id_agente, nombre FROM tagente ORDER BY nombre',
'id_parent', $id_parent, '', 'None', '0');
$groups = get_user_groups ($config["id_user"]);
$agents = get_group_agents (array_keys ($groups));
echo '<tr><td class="datos"><b>'.__('Group').'</b>';
echo '<td class="datos">';
print_select_from_sql ('SELECT id_grupo, nombre FROM tgrupo ORDER BY nombre',
'grupo', $grupo, '', '', '');
$table->data[2][0] = '<b>'.__('Parent').'</b>';
$table->data[2][1] = print_select ($agents, 'id_parent', $id_parent, '', get_agent_name ($id_parent, "lower"), $id_parent, true, false, false); //I use get_agent_name because the user might not have rights to the current parent
echo "<tr><td class='datos2'>";
echo "<b>".__('Interval')."</b></td>";
echo '<td class="datos2">';
$table->data[3][0] = '<b>'.__('Group').'</b>';
$table->data[3][1] = print_select ($groups, 'grupo', $grupo, '', '', 0, true, false, false);
echo '<input type="text" name="intervalo" size="15" value="'.$intervalo.'"></td>';
echo '<tr><td class="datos"><b>'.__('OS').'</b></td>';
echo '<td class="datos">';
print_select_from_sql ('SELECT id_os, name FROM tconfig_os ORDER BY name',
'id_os', $id_os, '', '', '');
$table->data[4][0] = '<b>'.__('Interval').'</b>';
$table->data[4][1] = print_input_text ('intervalo', $intervalo, '', 16, 100, true);
$table->data[5][0] = '<b>'.__('OS').'</b>';
$table->data[5][1] = print_select_from_sql ('SELECT id_os, name FROM tconfig_os ORDER BY name', 'id_os', $id_os, '', '', '0', true);
// Network server
echo '<tr><td class="datos2"><b>'.__('Network Server').'</b>';
echo '<a href="#" class="tip">&nbsp;<span>'.__('You must select a Network Server for the Agent, so it can work properly with this kind of modules').'</span></a>';
echo '</td><td class="datos2">';
$none = '';
$none_value = '';
if ($id_network_server == 0) {
$none = __('None');
$none_value = 0;
}
print_select_from_sql ('SELECT id_server, name FROM tserver WHERE network_server = 1 ORDER BY name',
'network_server', $id_network_server, '', $none, $none_value);
$table->data[6][0] = '<b>'.__('Network Server').'</b>'.print_help_tip (__('You must select a Network Server for the Agent, so it can work properly with this kind of modules'), true);
$table->data[6][1] = print_select_from_sql ('SELECT id_server, name FROM tserver WHERE network_server = 1 ORDER BY name', 'network_server', $id_network_server, '', '', 0, true);
// Plugin Server
echo '<tr><td class="datos"><b>'.__('Plugin Server').'</b>';
echo '<a href="#" class="tip">&nbsp;<span>'.__('You must select a Plugin Server for the Agent, so it can work properly with this kind of modules').'</span></a>';
echo '</td><td class="datos">';
$none_str = __('None');
$none = '';
$none_value = '';
if ($id_plugin_server == 0) {
$none = $none_str;
$none_value = 0;
}
print_select_from_sql ('SELECT id_server, name FROM tserver WHERE plugin_server = 1 ORDER BY name',
'plugin_server', $id_plugin_server, '', $none, $none_value);
// Plugin server
$table->data[7][0] = '<b>'.__('Plugin Server').'</b>'.print_help_tip (__('You must select a Plugin Server for the Agent, so it can work properly with this kind of modules'), true);
$table->data[7][1] = print_select_from_sql ('SELECT id_server, name FROM tserver WHERE plugin_server = 1 ORDER BY name', 'plugin_server', $id_plugin_server, '', '', 0, true);
// WMI Server
echo '<tr><td class="datos2"><b>'.__('WMI Server').'</b>';
echo '<a href="#" class="tip">&nbsp;<span>'.__('You must select a WMI Server for the Agent, so it can work properly with this kind of modules').'</span></a>';
echo '</td><td class="datos2">';
$none = '';
$none_value = '';
if ($id_wmi_server == 0) {
$none = $none_str;
$none_value = 0;
}
print_select_from_sql ('SELECT id_server, name FROM tserver WHERE wmi_server = 1 ORDER BY name',
'wmi_server', $id_wmi_server, '', $none, $none_value);
$table->data[8][0] = '<b>'.__('WMI Server').'</b>'.print_help_tip (__('You must select a WMI Server for the Agent, so it can work properly with this kind of modules'), true);
$table->data[8][1] = print_select_from_sql ('SELECT id_server, name FROM tserver WHERE wmi_server = 1 ORDER BY name', 'wmi_server', $id_wmi_server, '', '', 0, true);
// Prediction Server
echo '<tr><td class="datos"><b>'.__('Prediction Server').'</b>';
echo '<a href="#" class="tip">&nbsp;<span>'.__('You must select a Prediction Server for the Agent, so it can work properly with this kind of modules').'</span></a>';
echo '</td><td class="datos">';
$none = '';
$none_value = '';
if ($id_prediction_server == 0) {
$none = $none_str;
$none_value = 0;
}
print_select_from_sql ('SELECT id_server, name FROM tserver WHERE prediction_server = 1 ORDER BY name',
'prediction_server', $id_prediction_server, '', $none, $none_value);
$table->data[9][0] = '<b>'.__('Prediction Server').'</b>'.print_help_tip (__('You must select a Prediction Server for the Agent, so it can work properly with this kind of modules'), true);
$table->data[9][1] = print_select_from_sql ('SELECT id_server, name FROM tserver WHERE prediction_server = 1 ORDER BY name', 'prediction_server', $id_prediction_server, '', '', 0, true);
enterprise_hook ('inventory_server');
// Description
echo '<tr><td class="datos2"><b>';
echo __('Description');
echo '</b><td class="datos2">';
print_input_text ('comentarios', $comentarios, '', 45, 255);
$table->data[10][0] = '<b>'.__('Description').'</b>';
$table->data[10][1] = print_input_text ('comentarios', $comentarios, '', 45, 255, true);
// Learn mode / Normal mode
echo '<tr><td class="datos"><b>';
echo __('Module definition');
pandora_help("module_definition");
echo '</b><td class="datos">';
echo __('Learning mode');
print_radio_button_extended ("modo", 1, '', $modo, false, '', 'style="margin-right: 40px;"');
echo __('Normal mode');
print_radio_button_extended ("modo", 0, '', $modo, false, '', 'style="margin-right: 40px;"');
$table->data[11][0] = '<b>'.__('Module definition').'</b>'.pandora_help("module_definition", true);
$table->data[11][1] = __('Learning mode').' '.print_radio_button_extended ("modo", 1, '', $modo, false, '', 'style="margin-right: 40px;"', true);
$table->data[11][1] .= __('Normal mode').' '.print_radio_button_extended ("modo", 0, '', $modo, false, '', 'style="margin-right: 40px;"', true);
// Status (Disabled / Enabled)
echo '<tr><td class="datos2"><b>'.__('Status').'</b>';
echo '<td class="datos2">';
echo __('Disabled');
print_radio_button_extended ("disabled", 1, '', $disabled, false, '', 'style="margin-right: 40px;"');
echo __('Active');
print_radio_button_extended ("disabled", 0, '', $disabled, false, '', 'style="margin-right: 40px;"');
$table->data[12][0] = '<b>'.__('Status').'</b>';
$table->data[12][1] = __('Disabled').' '.print_radio_button_extended ("disabled", 1, '', $disabled, false, '', 'style="margin-right: 40px;"', true);
$table->data[12][1] .= __('Active').' '.print_radio_button_extended ("disabled", 0, '', $disabled, false, '', 'style="margin-right: 40px;"', true);
// Remote configuration
echo '<tr><td class="datos"><b>'.__('Remote configuration').'</b>';
echo '<td class="datos">';
$filename = $config["remote_config"] . "/" . $agent_md5 . ".md5";
if (file_exists($filename)){
echo date("F d Y H:i:s.", fileatime($filename));
$table->data[13][0] = '<b>'.__('Remote configuration').'</b>';
if (file_exists ($filename['md5'])) {
$table->data[13][1] = date ("F d Y H:i:s.", fileatime ($filename['md5']));
// Delete remote configuration
echo "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&disk_conf_delete=1&id_agente=$id_agente'><img src='images/cross.png'></A>";
$table->data[13][1] .= '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&disk_conf_delete=1&id_agente=$id_agente"><img src="images/cross.png" /></a>';
} else {
echo '<i>'.__('Not available').'</i>';
$table->data[13][1] = '<i>'.__('Not available').'</i>';
}
echo '</table><table width="650"><tr><td align="right">';
print_table ($table);
unset ($table);
echo '<div style="width: 650px; text-align: right;">';
if ($create_agent == 1) {
print_submit_button (__('Create'), 'crtbutton', false, 'class="sub wand"');
print_input_hidden ('create_agent', 1);
@ -222,7 +169,5 @@ if ($create_agent == 1) {
print_input_hidden ('update_agent', 1);
print_input_hidden ('id_agente', $id_agente);
}
echo "</td></form></table>";
echo '</div>';
?>

View File

@ -490,6 +490,14 @@ if (isset($_POST["update_agent"])) { // if modified some agent paramenter
$id_agente = (int) get_parameter_post ("id_agente", 0);
$nombre_agente = (string) get_parameter_post ("agente");
$direccion_agente = (string) get_parameter_post ("direccion");
$address_list = (string) get_parameter_post ("address_list");
if ($address_list != $direccion_agente && $direccion_agente == get_agent_address ($id_agente) && $address_list != get_agent_address ($id_agente)) {
//If we selected another IP in the drop down list to be 'primary':
// a) field is not the same as selectbox
// b) field has not changed from current IP
// c) selectbox is not the current IP
$direccion_agente = $address_list;
}
$grupo = (int) get_parameter_post ("grupo", 0);
$intervalo = (int) get_parameter_post ("intervalo", 300);
$comentarios = (string) get_parameter_post ("comentarios");

View File

@ -82,7 +82,7 @@ foreach ($result as $row) {
$data[0] = '<strong><a href="index.php?sec=gagente&sec2=operation/agentes/ver_agente&id_agente='.
$row["id_agente"].'">'.dame_nombre_agente ($row["id_agente"]).'</a></strong>';
//Second row is a number of modules for the agent
$data[1] = count (get_modules_in_agent ($row["id_agente"]));
$data[1] = get_agentmodule_count ($row["id_agente"]);
//Then the number of data packets for the agent
$data[2] = $row["count"];

View File

@ -98,13 +98,13 @@ if (isset($_POST["purgedb"])) {
echo "<br />";
flush (); //Flush here in case there are errors and the script dies, at least we know where we ended
set_time_limit (); //Reset the time limit just in case
$sql = sprintf("DELETE FROM `tagente_datos` WHERE `id_agente_modulo` = '%d' AND `utimestamp` < '%d'",$row["id_agente_modulo"],$from_date);
$sql = sprintf ("DELETE FROM `tagente_datos` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
if (process_sql ($sql) === false)
$errors++;
$sql = sprintf("DELETE FROM `tagente_datos_inc` WHERE `id_agente_modulo` = '%d' AND `utimestamp` < '%d'",$row["id_agente_modulo"],$from_date);
$sql = sprintf ("DELETE FROM `tagente_datos_inc` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
if (process_sql ($sql) === false)
$errors++;
$sql = sprintf("DELETE FROM `tagente_datos_string` WHERE `id_agente_modulo` = '%d' AND `utimestamp` < '%d'",$row["id_agente_modulo"],$from_date);
$sql = sprintf ("DELETE FROM `tagente_datos_string` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
if (process_sql ($sql) === false)
$errors++;
}
@ -120,39 +120,29 @@ if (isset($_POST["purgedb"])) {
//All agents
echo __('Deleting records for all agents');
flush ();
//ob_flush();
$query = sprintf("DELETE FROM `tagente_datos` WHERE `utimestamp` < '%d'",$from_date);
$query = sprintf ("DELETE FROM `tagente_datos` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf("DELETE FROM `tagente_datos_inc` WHERE `utimestamp` < '%d'",$from_date);
$query = sprintf ("DELETE FROM `tagente_datos_inc` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf("DELETE FROM `tagente_datos_string` WHERE `utimestamp` < '%d'",$from_date);
$query = sprintf ("DELETE FROM `tagente_datos_string` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
}
echo "<br /><br />";
}
# Select Agent for further operations.
echo '<form action="index.php?sec=gdbman&sec2=godmode/db/db_purge" method="post">
<table class="databox">
<tr><td class="datos">';
$agents = get_group_agents (1, true);
$agents[-1] = __('Choose agent');
$agents[0] = __('All agents');
$result = get_agents_in_group (1);
if ($result === false)
$result = array();
foreach ($result as $row) {
$agents[$row["id_agente"]] = $row["nombre"];
}
print_select ($agents, "agent", $id_agent, "", "", "", false, false, false);
echo '<form action="index.php?sec=gdbman&sec2=godmode/db/db_purge" method="post">';
echo '<div style="width:100%;">';
print_select ($agents, "agent", $id_agent, "this.form.submit();", "", "", false, false, false);
print_help_tip (__("Select the agent you want information about"));
echo '</td><td><input class="sub upd" type="submit" name="purgedb_ag" value="'.__('Get data').'">';
echo '<noscript>';
print_submit_button (__('Get data'), 'purgedb_ag', false, 'class="sub upd"');
print_help_tip (__("Click here to get the data from the agent specified in the select box"));
echo '</td></tr></table><br />';
echo '</noscript><br />';
if ($id_agent > 0) {
$title = __('Information on agent').' '.dame_nombre_agente ($id_agent).' '.__('in the database');
@ -161,10 +151,12 @@ if ($id_agent > 0) {
}
echo "<h3>".$title."</h3>";
flush ();
$query = "";
flush (); //Flush before we do some SQL stuff
if ($id_agent > 0) { //If the agent is not All or Not selected
$query = sprintf (" AND id_agente_modulo = ANY(SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = '%d' ",$id_agent);
$modules = get_agentmodules ($id_agent);
sprintf ("AND id_agente_modulo IN(%s)", implode (",", array_keys ($modules)));
} else {
$query = "";
}
$data["1day"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query));

View File

@ -369,14 +369,7 @@ if (! $edit_layout && ! $id_layout) {
$intervals[1440] = __('Two Months');
$intervals[4320] = __('Six Months');
$all_agents = get_agents_in_group ($id_group);
$agents = array ();
if ($all_agents !== false) {
foreach ($all_agents as $agent) {
$agents[$agent['id_agente']] = strtolower($agent['nombre']);
}
asort($agents);
}
$agents = get_group_agents ($id_group);
echo '<div id="layout_editor_drop">';
echo '<h1>'.__('Map element editor').'</h1>';

View File

@ -202,14 +202,7 @@ if ($id_report) {
$report_id_group = $report['id_group'];
}
$all_agents = get_agents_in_group ($report_id_group);
$agents = array ();
if ($all_agents !== false) {
foreach ($all_agents as $agent) {
$agents[$agent['id_agente']] = strtolower($agent['nombre']);
}
asort ($agents);
}
$agents = get_group_agents ($report_id_group);
if ($edit_sla_report_content) {
/* Edit SLA report form */

View File

@ -190,44 +190,100 @@ function give_disabled_group ($id_group) {
}
/**
* Get all the agents in a group.
* Get all the agents within a group(s).
*
* @param id_group Group id or a comma delimited list of id_groups or an array
* of ID's
*
* @param disabled Add disabled agents to agents. Default: False.
*
* @return An array with all agents in the group.
* @param case Which case to return the agentname as (lower, upper, none)
*
* @return An array with all agents in the group or an empty array
*/
function get_agents_in_group ($id_group, $disabled = false) {
if (is_array ($id_group)) //If id_group is an array, then
function get_group_agents ($id_group, $disabled = false, $case = "lower") {
$id_group = safe_int ($id_group, 1);
if (is_array ($id_group)) {
//If id_group is an array, then
if (in_array (1, $id_group)) {
//If All is included in the group list, just select All
$id_group = 1;
} else {
//If All is not included, select what we need
$id_group = implode (",", $id_group);
}
}
/* 'All' group must return all agents */
if ($id_group == 1) {
if ($disabled) {
return get_db_all_rows_in_table ('tagente', 'nombre');
} else {
return get_db_all_rows_field_filter ('tagente', 'disabled', 0, 'nombre');
$search = '';
if (!empty ($id_group) && $id_group > 1) {
$search .= sprintf (' WHERE id_grupo IN (%s)', $id_group);
}
} elseif ($disabled && $id_group != 1) {
$sql = sprintf ("SELECT * FROM tagente WHERE id_grupo IN (%s) ORDER BY nombre",$id_group);
return get_db_all_rows_sql ($sql);
} else {
$sql = sprintf ("SELECT * FROM tagente WHERE id_grupo IN (%s) AND disabled = 0 ORDER BY nombre",$id_group);
return get_db_all_rows_sql ($sql);
if ($disabled !== false) {
$search .= (($search == '') ? ' WHERE' : ' AND' ).' disabled = 0';
}
$sql = sprintf ("SELECT id_agente, nombre FROM tagente%s ORDER BY nombre", $search);
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return array (); //Return an empty array
$agents = array ();
foreach ($result as $row) {
switch ($case) {
case "lower":
$agents[$row["id_agente"]] = mb_strtolower ($row["nombre"],"UTF-8");
break;
case "upper":
$agents[$row["id_agente"]] = mb_strtoupper ($row["nombre"],"UTF-8");
break;
default:
$agents[$row["id_agente"]] = $row["nombre"];
}
}
return ($agents);
}
/**
* Get all the modules in an agent.
*
* @param $id_agent Agent id
* @param $details Array, comma delimited list or singular value of rows to select. If nothing is specified, nombre will be selected
*
* @return An array with all modules in the agent.
* @return An array with all modules in the agent. If multiple rows are selected, they will be in an array
*/
function get_modules_in_agent ($id_agent) {
return get_db_all_rows_field_filter ('tagente_modulo', 'id_agente', (int) $id_agent);
function get_agentmodules ($id_agent, $details = false) {
$id_agent = safe_int ($id_agent, 1);
if (empty ($id_agent)) {
$filter = '';
} elseif (is_array ($id_agent)) {
$filter = sprintf (' WHERE id_agente IN (%s)', implode (",",$id_agent));
} else {
$filter = sprintf (' WHERE id_agente = %d', $id_agent);
}
if (empty ($details)) {
$details = "nombre";
}
$sql = "SELECT id_agente_modulo,".implode (",", (array) $details)." FROM tagente_modulo".$filter." ORDER BY nombre";
$result = get_db_all_rows_sql ($sql); //cast as array, that way a false will be converted into an array
if (empty ($result)) {
$result = array ();
}
$modules = array ();
foreach ($result as $row) {
if (is_array ($details)) {
$modules[$row["id_agente_modulo"]] = $row; //Just stack the information in array by ID
} else {
$modules[$row["id_agente_modulo"]] = $row[$details];
}
}
return $modules;
}
/**
@ -361,14 +417,36 @@ function return_event_description ($id_event) {
}
/**
* Get name of an agent.
* DEPRECATED: Use get_agent_name instead
*
* @param id_agent Agent id.
*
* @return Name of the given agent.
*/
function dame_nombre_agente ($id_agent) {
return (string) get_db_value ('nombre', 'tagente', 'id_agente', (int) $id_agent);
return get_agent_name ($id_agent, "none");
}
/**
* Get name of an agent.
*
* @param id_agent Agent id.
* @param case Case (upper, lower, none)
*
* @return Name of the given agent.
*/
function get_agent_name ($id_agent, $case = "upper") {
$agent = (string) get_db_value ('nombre', 'tagente', 'id_agente', (int) $id_agent);
switch ($case) {
case "upper":
return mb_strtoupper ($agent,"UTF-8");
break;
case "lower":
return mb_strtolower ($agent,"UTF-8");
break;
default:
return ($agent);
}
}
/**
@ -662,12 +740,10 @@ function get_alert_fires_in_period ($id_agent_module, $period, $date = 0) {
*/
function get_alerts_in_group ($id_group) {
$alerts = array ();
$agents = get_agents_in_group ($id_group);
if (empty ($agents))
return $alerts;
$agents = get_group_agents ($id_group, false, "none");
foreach ($agents as $agent) {
$agent_alerts = get_alerts_in_agent ($agent["id_agente"]);
foreach ($agents as $agent_id => $agent_name) {
$agent_alerts = get_alerts_in_agent ($agent_id);
$alerts = array_merge ($alerts, $agent_alerts);
}
@ -1287,7 +1363,7 @@ function agent_delete_address ($id_agent, $ip_address) {
if (get_agent_address ($id_agent) == $ip_address) {
$new_ips = get_agent_addresses ($id_agent);
// Change main address in agent to first one in the list
$query = sprintf ("UPDATE tagente SET `direccion` = '%s' WHERE id_agente = %d", $new_ips[0], $id_agent);
$query = sprintf ("UPDATE tagente SET `direccion` = '%s' WHERE id_agente = %d", current ($new_ips), $id_agent);
process_sql ($query);
}
}
@ -1324,7 +1400,7 @@ function get_agent_with_ip ($ip_address) {
*
* @param id_agent Agent id
*
* @return Array with the IP address of the given agent.
* @return Array with the IP address of the given agent or an empty array.
*/
function get_agent_addresses ($id_agent) {
$sql = sprintf ("SELECT ip FROM taddress_agent, taddress
@ -1339,7 +1415,7 @@ function get_agent_addresses ($id_agent) {
$ret_arr = array ();
foreach ($ips as $row) {
$ret_arr[] = $row["ip"];
$ret_arr[$row["ip"]] = $row["ip"];
}
return $ret_arr;
@ -2365,11 +2441,23 @@ function get_server_info ($id_server = -1) {
/**
* This function will return the number of all agent modules in the database
*
* @param integer or array of integers with agent(s). Leave empty to select everything
*
* @return integer with the number of agent modules
*
* TODO: Filter? Implement when necessary
**/
function get_agentmodule_count () {
return (int) get_db_sql ("SELECT COUNT(*) FROM tagente_modulo");
function get_agentmodule_count ($id_agent = 0) {
$id_agent = safe_int ($id_agent); //Make sure we're all int's and filter out bad stuff
if (empty ($id_agent) || $id_agent < 1) {
//If the array proved empty or the agent is less than 1 (eg. -1)
$filter = '';
} elseif (is_array ($id_agent)) {
//If it's an array of agents, flatten the aray
$filter = sprintf (" WHERE id_agente IN (%s)", implode (",",$id_agent));
} else {
$filter = sprintf (" WHERE id_agente = %d", $id_agent);
}
return (int) get_db_sql ("SELECT COUNT(*) FROM tagente_modulo".$filter);
}
?>

View File

@ -113,12 +113,7 @@ function print_select_from_sql ($sql, $name, $selected = '', $script = '', $noth
$fields[$row[0]] = $row[1];
}
$output = print_select ($fields, $name, $selected, $script, $nothing, $nothing_value, true, $multiple, $sort);
if ($return)
return $output;
echo $output;
return print_select ($fields, $name, $selected, $script, $nothing, $nothing_value, $return, $multiple, $sort);
}
/**

View File

@ -221,7 +221,7 @@ function get_group_stats ($id_group) {
} //End module check
} //End foreach module
$data["total_agents"] = count (get_agents_in_group ($groups));
$data["total_agents"] = count (get_group_agents ($groups, false, "none"));
$data["total_checks"] = $data["data_checks"] + $data["monitor_checks"];
$data["total_ok"] = $data["data_ok"] + $data["monitor_ok"];
$data["total_alerts"] = $data["data_alerts"] + $data["monitor_alerts"];
@ -496,7 +496,7 @@ function get_monitors_down_reporting_table ($monitors_down) {
$data = array ();
foreach ($monitors as $monitor) {
if (! isset ($data[0]))
$data[0] = dame_nombre_agente ($id_agent);
$data[0] = get_agent_name ($id_agent);
else
$data[0] = '';
if ($monitor['descripcion'] != '') {
@ -520,12 +520,12 @@ function get_monitors_down_reporting_table ($monitors_down) {
* @param $return Flag to return or echo the report (by default).
*/
function general_group_reporting ($id_group, $return = false) {
$output = '';
$agents = get_agents_in_group ($id_group);
$output .= '<strong>'.__('Agents in group').': '.sizeof ($agents).'</strong><br />';
$agents = get_group_agents ($id_group, false, "none");
$output = '<strong>'.__('Agents in group').': '.count ($agents).'</strong><br />';
if (!$return)
if ($return === false)
echo $output;
return $output;
}
@ -619,7 +619,7 @@ function get_agent_monitors_reporting_table ($id_agent, $period = 0, $date = 0)
function get_agent_modules_reporting_table ($id_agent, $period = 0, $date = 0) {
$table->data = array ();
$n_a_string = __('N/A').'(*)';
$modules = get_modules_in_agent ($id_agent);
$modules = get_agentmodules ($id_agent, array ("nombre", "descripcion"));
if ($modules === false)
$modules = array();
$data = array ();
@ -693,20 +693,16 @@ function get_agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $retur
* @param $return Flag to return or echo the report (by default).
*/
function get_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $return = false) {
$output = '';
$agents = get_agents_in_group ($id_group);
$agents = get_group_agents ($id_group, false, "none");
foreach ($agents as $agent) {
$output .= get_agent_detailed_reporting ($agent['id_agente'], $period, $date, true);
if (!$return) {
echo $output;
$output = '';
flush ();
}
foreach ($agents as $agent_id => $agent_name) {
$output .= get_agent_detailed_reporting ($agent_id, $period, $date, true);
}
if (!$return)
if ($return === false)
echo $output;
return $output;
}

View File

@ -144,10 +144,10 @@ if (isset($_GET["id_agente"])){
// Agent group selector
if ($ag_group > 1) {
$result = get_agents_in_group ($ag_group);
$result = get_group_agents ($ag_group, false, "upper");
} else {
//Fields is an array with all the groups the user has access to
$result = get_agents_in_group (array_keys ($fields));
$result = get_group_agents (array_keys ($fields), false, "upper");
}
$color = 1;
@ -174,9 +174,7 @@ if (isset($_GET["id_agente"])){
}
//This result is the array with agents
foreach ($result as $row) {
$id_agente = $row["id_agente"];
$nombre_agente = strtoupper ($row["nombre"]);
foreach ($result as $id_agente => $nombre_agente) {
$result_alerts = get_alerts_in_agent ($id_agente);
if ($result_alerts === false)

View File

@ -161,7 +161,7 @@ if (dame_admin ($config["id_user"])) {
foreach ($result as $id_row) {
$name_for_combo = "";
if ($id_row[0] > 0)
$name_for_combo = substr (strtolower (dame_nombre_agente ($id_row[0])),0,20);
$name_for_combo = substr (get_agent_name ($id_row[0], "lower"),0,20);
if ($name_for_combo != "")
$agents[$id_row[0]] = $name_for_combo;
}

View File

@ -1207,8 +1207,8 @@ function grafico_db_agentes_modulos($width, $height) {
$result = array();
foreach ($result as $row) {
$data[] = count (get_modules_in_agent ($row["id_agente"]));
$legend[] = dame_nombre_agente ($row["id_agente"]);
$data[] = get_agentmodule_count ($row["id_agente"]);
$legend[] = get_agent_name ($row["id_agente"], "lower");
}
generic_bar_graph ($width, $height, $data, $legend);
@ -1370,7 +1370,7 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "") {
$legend[] = "SYSTEM (".$row["count"].")";
} else {
//Other events
$legend[] = substr (dame_nombre_agente ($row["id_agente"]), 0, 15)." (".$row["count"].")";
$legend[] = substr (get_agent_name ($row["id_agente"], "lower"), 0, 15)." (".$row["count"].")";
}
}
}
@ -1434,7 +1434,7 @@ function grafico_db_agentes_paquetes ($width = 380, $height = 300) {
foreach ($result as $row) {
$data[] = $row["count"];
$legend[] = dame_nombre_agente ($row["id_agente"]);
$legend[] = get_agent_name ($row["id_agente"], "lower");
}
generic_bar_graph ($width, $height, $data, $legend);
@ -1447,7 +1447,8 @@ function grafico_db_agentes_purge ($id_agent, $width, $height) {
$id_agent = -1;
$query = "";
} else {
$query = sprintf (" AND id_agente_modulo = ANY(SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = '%d' ",$id_agent);
$modules = get_agentmodules ($id_agent);
$query = sprintf (" AND id_agente_modulo IN (%s)", implode (",", array_keys ($modules)));
}
// All data (now)