0)
$filter = " WHERE id_grupo = ". $id_group;
else {
$groups_orig = get_user_groups();
$a = 0;
$groups = array_keys($groups_orig);
$filter = " WHERE id_grupo IN (". implode(',', $groups) .")";
}
$agents = get_db_all_rows_sql("SELECT id_agente, nombre FROM tagente". $filter);
echo json_encode($agents);
return;
}
if ($get_agent_json) {
$id_agent = (int) get_parameter ('id_agent');
$agent = get_db_row ('tagente', 'id_agente', $id_agent);
echo json_encode ($agent);
return;
}
if ($get_agent_modules_json_for_multiple_agents_id) {
$idAgents = get_parameter('id_agent');
$nameModules = get_db_all_rows_sql('SELECT nombre, id_agente_modulo FROM tagente_modulo WHERE id_agente IN (' . implode(',', $idAgents) . ')');
echo json_encode($nameModules);
return;
}
if ($get_agent_modules_json_for_multiple_agents) {
$idAgents = get_parameter('id_agent');
$nameModules = get_db_all_rows_sql('SELECT DISTINCT(nombre) FROM tagente_modulo t1 WHERE delete_pending = 0 AND id_agente IN (' . implode(',', $idAgents) . ') AND (SELECT count(nombre) FROM tagente_modulo t2 WHERE delete_pending = 0 AND t1.nombre = t2.nombre AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')');
$result = array();
foreach($nameModules as $nameModule) {
$result[] = $nameModule['nombre'];
}
echo json_encode($result);
return;
}
if ($get_agent_modules_json) {
$id_agent = (int) get_parameter ('id_agent');
$filter = (string) get_parameter ('filter');
$fields = (string) get_parameter ('fields');
$indexed = (bool) get_parameter ('indexed', true);
$agentName = (string) get_parameter ('agent_name', null);
if ($agentName != null) {
$search = array();
$search['name'] = $agentName;
}
else
$search = false;
/* Get all agents if no agent was given */
if ($id_agent == 0)
$id_agent = array_keys (get_group_agents (array_keys (get_user_groups ()), $search, "none"));
$agent_modules = get_agent_modules ($id_agent,
($fields != '' ? explode (',', $fields) : "*"),
($filter != '' ? $filter : false), $indexed);
//Hack to translate text "any" in PHP to javascript
//$agent_modules['any_text'] = __('Any');
echo json_encode ($agent_modules);
return;
}
if ($get_agent_status_tooltip) {
$id_agent = (int) get_parameter ('id_agent');
$agent = get_db_row ('tagente', 'id_agente', $id_agent);
echo '
'.$agent['nombre'].'
';
echo ''.__('Main IP').': '.$agent['direccion'].'
';
echo ''.__('Group').': ';
echo ' ';
echo get_group_name ($agent['id_grupo']).'
';
echo ''.__('Last contact').': '.human_time_comparation($agent['ultimo_contacto']).'
';
echo ''.__('Last remote contact').': '.human_time_comparation($agent['ultimo_contacto_remoto']).'
';
$sql = sprintf ('SELECT tagente_modulo.descripcion, tagente_modulo.nombre
FROM tagente_estado, tagente_modulo
WHERE tagente_modulo.id_agente = %d
AND tagente_modulo.id_tipo_modulo in (2, 6, 9, 18, 21, 100)
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0
AND tagente_estado.estado = 1', $id_agent);
$bad_modules = get_db_all_rows_sql ($sql);
$sql = sprintf ('SELECT COUNT(*)
FROM tagente_modulo
WHERE id_agente = %d
AND disabled = 0
AND id_tipo_modulo in (2, 6, 9, 18, 21, 100)', $id_agent);
$total_modules = get_db_sql ($sql);
if ($bad_modules === false)
$size_bad_modules = 0;
else
$size_bad_modules = sizeof ($bad_modules);
// Modules down
if ($size_bad_modules > 0) {
echo ''.__('Monitors down').': '.$size_bad_modules.' / '.$total_modules;
echo '';
foreach ($bad_modules as $module) {
echo '- ';
$name = $module['nombre'];
echo substr ($name, 0, 25);
if (strlen ($name) > 25)
echo '(...)';
echo '
';
}
echo '
';
}
// Alerts (if present)
$sql = sprintf ('SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente
WHERE tagente.id_agente = %d
AND tagente.disabled = 0
AND tagente.id_agente = tagente_modulo.id_agente
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module
AND talert_template_modules.times_fired > 0 ',
$id_agent);
$alert_modules = get_db_sql ($sql);
if ($alert_modules > 0){
$sql = sprintf ('SELECT tagente_modulo.nombre, talert_template_modules.last_fired
FROM talert_template_modules, tagente_modulo, tagente
WHERE tagente.id_agente = %d
AND tagente.disabled = 0
AND tagente.id_agente = tagente_modulo.id_agente
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module
AND talert_template_modules.times_fired > 0 ',
$id_agent);
$alerts = get_db_all_rows_sql ($sql);
echo ''.__('Alerts fired').':';
echo "";
foreach ($alerts as $alert_item) {
echo '- ';
$name = $alert_item[0];
echo substr ($name, 0, 25);
if (strlen ($name) > 25)
echo '(...)';
echo " ";
echo human_time_comparation($alert_item[1]);
echo '
';
}
echo '
';
}
return;
}
return;
}
$id_agente = (int) get_parameter ("id_agente", 0);
if (empty ($id_agente)) {
return;
}
$agent = get_db_row ('tagente', 'id_agente', $id_agente);
// get group for this id_agente
$id_grupo = $agent['id_grupo'];
if (! give_acl ($config['id_user'], $id_grupo, "AR")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation",
"Trying to access (read) to agent ".get_agent_name($id_agente));
include ("general/noaccess.php");
return;
}
// Check for Network FLAG change request
if (isset($_GET["flag"])) {
if ($_GET["flag"] == 1 && give_acl ($config['id_user'], $id_grupo, "AW")) {
$sql = "UPDATE tagente_modulo SET flag=1 WHERE id_agente_modulo = ".$_GET["id_agente_modulo"];
process_sql ($sql);
}
}
// Check for Network FLAG change request
if (isset($_GET["flag_agent"])){
if ($_GET["flag_agent"] == 1 && give_acl ($config['id_user'], $id_grupo, "AW")) {
$sql ="UPDATE tagente_modulo SET flag=1 WHERE id_agente = ". $id_agente;
process_sql ($sql);
}
}
echo "";
echo "
";
switch ($tab) {
case "gis":
require ("gis_view.php");
break;
case "sla":
require ("sla_view.php");
break;
case "manage":
require ("estado_generalagente.php");
break;
case "main":
require ("estado_generalagente.php");
require ("estado_monitores.php");
require ("alerts_status.php");
require ("status_events.php");
break;
case "data_view":
require ("datos_agente.php");
break;
case "data":
require ("estado_ultimopaquete.php");
break;
case "alert":
require ("alerts_status.php");
break;
case "inventory":
enterprise_include ('operation/agentes/agent_inventory.php');
break;
}
?>