Merge branch '2737-Optimización-de-tags-dev' into 'develop'

2737 optimización de tags dev

See merge request artica/pandorafms!1815
This commit is contained in:
vgilc 2018-10-11 12:14:10 +02:00
commit edadc60957
45 changed files with 669 additions and 3025 deletions

View File

@ -70,7 +70,7 @@ function mainAgentsModules() {
$hor_offset = (int)get_parameter('hor_offset', 0);
$block = $config['block_size'];
if(get_parameter('modulegroup') != null){
$agents_id = (array)get_parameter('id_agents2', -1);
$agents_id = (array)get_parameter('id_agents2', null);
}
$selection_a_m = (int)get_parameter('selection_agent_module');
$modules_selected = (array)get_parameter('module', 0);
@ -100,6 +100,9 @@ function mainAgentsModules() {
if($agents_id[0] != -1 ){
serialize_in_temp($agents_id, $config['id_user']."_agents", 1);
}
//if($agents_id != -1) $agents_id = null;
if ($config["pure"] == 0) {
if($modules_selected[0] && $agents_id[0]){
@ -132,8 +135,6 @@ function mainAgentsModules() {
}
}
$groups = users_get_groups ();
//groups
$filter_groups_label = '<b>'.__('Group').'</b>';
$filter_groups = html_print_select_groups(false, "AR", true, 'group_id', $group_id, '', '', '', true, false, true, '', false , 'width: auto;');
@ -144,18 +145,7 @@ function mainAgentsModules() {
$filter_module_groups_label = '<b>'.__('Module group').'</b>';
$filter_module_groups = html_print_select_from_sql ("SELECT * FROM tmodule_group ORDER BY name",
'modulegroup', $modulegroup, '',__('All'), 0, true, false, true, false, 'width: auto;');
$agents_select = array();
if (is_array($id_agents) || is_object($id_agents)){
foreach ($id_agents as $id) {
foreach ($agents as $key => $a) {
if ($key == (int)$id) {
$agents_select[$key] = $key;
}
}
}
}
//agent
$agents = agents_get_group_agents($group_id);
if ((empty($agents)) || $agents == -1) $agents = array();
@ -293,6 +283,7 @@ function mainAgentsModules() {
$count = 0;
foreach ($agents as $agent) {
// TODO TAGS agents_get_modules
$module = agents_get_modules($agent, false,
$filter_module_group, true, true);
if ($module == false) {
@ -301,7 +292,6 @@ function mainAgentsModules() {
$count++;
}
$total_pagination = count($agents);
if($agents_id[0] != -1){
$all_modules = array();
foreach ($modules_selected as $key => $value) {
@ -332,11 +322,11 @@ function mainAgentsModules() {
foreach ($result_sql as $key => $value) {
$all_modules[$value['id_agente_modulo']] = io_safe_output($name);
}
}
// $all_modules[$value] = modules_get_agentmodule_name($value);
}
}
} else {
// TODO TAGS agents_get_modules
$all_modules = agents_get_modules($agents, false,
$filter_module_group, true, true);
}
@ -346,7 +336,6 @@ function mainAgentsModules() {
$modules_by_name = array();
$name = '';
$cont = 0;
foreach ($all_modules as $key => $module) {
if ($module == $name) {
$modules_by_name[$cont-1]['id'][] = $key;
@ -358,7 +347,6 @@ function mainAgentsModules() {
$cont ++;
}
}
if ($config["pure"] == 1) {
$block = count($modules_by_name);
}
@ -381,7 +369,10 @@ function mainAgentsModules() {
$filter_groups['id_grupo'] = $group_id;
}
}
$agents = agents_get_agents ($filter_groups);
if (!empty($filter_groups['id_agente'])) {
$agents = agents_get_agents ($filter_groups);
}
$nagents = count($agents);
if ($all_modules == false || $agents == false) {
@ -499,10 +490,10 @@ function mainAgentsModules() {
<a class='$rowcolor' href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=".$agent['id_agente']."'>" .
$alias['alias'] .
"</a></td>";
// TODO TAGS agents_get_modules
$agent_modules = agents_get_modules($agent['id_agente'], false, $filter_module_group, true, true);
$nmodules = 0;
foreach ($modules_by_name as $module) {
$nmodules++;

View File

@ -32,26 +32,17 @@ if (is_ajax()) {
$limit = (int) get_parameter("limit", 5);
$tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND');
$filter = "estado<>1 $tags_condition";
$filter = "estado <> 1 $tags_condition";
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql = sprintf ("SELECT id_agente, evento, utimestamp
FROM tevento
WHERE %s
ORDER BY utimestamp DESC LIMIT %d",
$filter, $limit);
break;
case "oracle":
$sql = sprintf ("SELECT *
FROM tevento
WHERE %s
AND rownum <= %d
ORDER BY utimestamp DESC",
$filter, $limit);
break;
}
$sql = sprintf ("SELECT id_agente, evento, utimestamp
FROM tevento
LEFT JOIN tagent_secondary_group
ON tevento.id_agente = tagent_secondary_group.id_agent
WHERE %s
ORDER BY utimestamp DESC LIMIT %d",
$filter, $limit);
$result = db_get_all_rows_sql ($sql);
$events = array();

View File

@ -106,8 +106,6 @@ $form .= html_print_table($table, true);
$form .= '</form>';
ui_toggle($form, __("Filter"), "", false);
// ui_toggle(graphic_user_activity(400, 150), __("Chart"));
$filter = "1=1";
if (!empty($filter_type)) {

View File

@ -207,11 +207,6 @@ if ($create_agent) {
$agent_creation_error = __('No agent alias specified');
$agent_created_ok = 0;
}
/*elseif (agents_get_agent_id ($nombre_agente)) {
$agent_creation_error =
__('There is already an agent in the database with this name');
$agent_created_ok = 0;
}*/
else {
if($alias_as_name){
$sql = 'SELECT nombre FROM tagente WHERE nombre = "' . $alias . '"';

View File

@ -424,9 +424,11 @@ foreach ($order as $ord) {
$limit = (int) $config["block_size"];
$offset = (int) get_parameter ('offset');
$params = implode(',',
$params = ($checked)
? "tagente_modulo.*, tmodule_group.*"
: implode(',',
array(
'id_agente_modulo',
'tagente_modulo.id_agente_modulo',
'id_tipo_modulo',
'descripcion',
'nombre',
@ -453,80 +455,46 @@ $search_string_entities = io_safe_input($search_string);
$basic_where = sprintf("(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, $search_string_entities);
$where_tags = tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 'tagente_modulo');
// Tags acl
$agent_tags = tags_get_user_applied_agent_tags($id_agente);
if ($agent_tags !== true) {
$where_tags = " AND ttag_module.id_tag IN (" . implode(',', $agent_tags) . ")";
}
$paginate_module = false;
if (isset($config['paginate_module']))
$paginate_module = $config['paginate_module'];
switch ($config["dbtype"]) {
case "postgresql":
if ($paginate_module) {
$limit_sql = " LIMIT $limit OFFSET $offset ";
}
else {
$limit_sql = '';
}
case "mysql":
if ($paginate_module) {
if (!isset($limit_sql)) {
$limit_sql = " LIMIT $offset, $limit ";
}
}
else {
$limit_sql = '';
}
if ($checked) {
$sql = sprintf("SELECT *
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE %s %s %s %s %s",
$basic_where, $where, $where_tags, $order_sql, $limit_sql);
}
else {
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE %s %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql, $limit_sql);
}
$modules = db_get_all_rows_sql($sql);
break;
case "oracle":
$set = array();
if ($paginate_module) {
$set['limit'] = $limit;
$set['offset'] = $offset;
}
if ($checked) {
$sql = sprintf("SELECT *
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE %s %s %s %s",
$basic_where, $where, $where_tags, $order_sql);
}
else {
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql);
}
$modules = oracle_recode_query ($sql, $set, 'AND', false);
break;
if ($paginate_module) {
if (!isset($limit_sql)) {
$limit_sql = " LIMIT $offset, $limit ";
}
}
else {
$limit_sql = '';
}
$sql = sprintf("SELECT tagente_modulo.*, tmodule_group.*
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
LEFT JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo
WHERE %s %s %s
GROUP BY tagente_modulo.id_agente_modulo
%s %s",
$basic_where, $where, $where_tags,
$order_sql, $limit_sql
);
$sql_total_modules = sprintf("SELECT count(*)
$modules = db_get_all_rows_sql($sql);
$sql_total_modules = sprintf(
"SELECT count(DISTINCT(tagente_modulo.id_agente_modulo))
FROM tagente_modulo
WHERE %s %s %s", $basic_where, $where, $where_tags);
LEFT JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo
WHERE %s %s %s", $basic_where, $where, $where_tags
);
$total_modules = db_get_value_sql($sql_total_modules);

View File

@ -189,9 +189,23 @@ $table_simple->data[0][3] .= html_print_select_from_sql ('SELECT id_mg, name FRO
$in_policy = strstr($page, "policy_modules");
if (!$in_policy) {
// Cannot select the current module to be itself parent
$module_parent_filter = $id_agent_module
? array("tagente_modulo.id_agente_modulo" => "<>$id_agent_module")
: "";
$table_simple->data[1][0] = __('Module parent');
$table_simple->data[1][1] .= html_print_select_from_sql ('SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE id_agente = ' . $id_agente . ' ORDER BY nombre',
'parent_module_id', $parent_module_id, '', __('Not assigned'), '0', true, false, true);
$modules_can_be_parent = agents_get_modules($id_agente, false, $module_parent_filter);
// If the user cannot have access to parent module, only print the name
if ($parent_module_id != 0 && !in_array($parent_module_id, array_keys($modules_can_be_parent))) {
$table_simple->data[1][1] = db_get_value(
'nombre', 'tagente_modulo', 'id_agente_modulo', $parent_module_id
);
} else {
$table_simple->data[1][1] = html_print_select (
$modules_can_be_parent, 'parent_module_id', $parent_module_id, '',
__('Not assigned'), '0', true
);
}
}
$table_simple->data[2][0] = __('Type').' ' . ui_print_help_icon ('module_type', true);

View File

@ -70,6 +70,7 @@ if (! $id_agente) {
$table->data[0][0] = __('Module');
$modules = array ();
if ($id_agente)
$modules = agents_get_modules ($id_agente, false, array("delete_pending" => 0));

View File

@ -399,9 +399,8 @@ if (!is_metaconsole()) {
$text_module, false, true, '', array(), true, $id_agent_module);
}
$sources = events_get_all_source();
$table ->data[22][0] = '<b>' . __('Source') . '</b>';
$table ->data[22][1] = html_print_select ($sources, 'source', $source, '', '', '', true);
$table ->data[22][1] = html_print_input_text ('source', $source, '', 35, 255, true);
$table ->data[23][0] = '<b>' . __('Extra ID') . '</b>';
$table ->data[23][1] = html_print_input_text ('id_extra', $id_extra, '', 11, 255, true);

View File

@ -1,249 +0,0 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// 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.
// Load global vars
check_login ();
if (! check_acl ($config['id_user'], 0, "AW")) {
db_pandora_audit("ACL Violation",
"Trying to access massive tag addition");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_agents.php');
require_once ('include/functions_tags.php');
function process_manage_add ($id_agents, $modules, $id_tags) {
if (empty ($id_agents) || $id_agents[0] == 0) {
ui_print_error_message(__('No agents selected'));
return false;
}
if (empty ($modules)) {
ui_print_error_message(__('No modules selected'));
return false;
}
if (empty ($id_tags)) {
ui_print_error_message(__('No tags selected'));
return false;
}
$modules_id = array();
foreach ($modules as $module) {
foreach ($id_agents as $id_agent) {
$module_id = modules_get_agentmodule_id($module, $id_agent);
$modules_id[] = $module_id['id_agente_modulo'];
}
}
if (count($modules) == 1 && $modules[0] == '0') {
foreach ($id_agents as $id_agent) {
$modules_temp = agents_get_modules($id_agent);
foreach ($modules_temp as $id_module => $name_module) {
$modules_id[] = $id_module;
}
}
}
$conttotal = 0;
$contsuccess = 0;
foreach ($modules_id as $id_module) {
$err_count = tags_insert_module_tag($id_module, $id_tags);
if ($err_count == 0) {
$contsuccess ++;
}
$conttotal ++;
}
if ($contsuccess > 0) {
db_pandora_audit("Massive management", "Add tags", false, false,
"");
}
else {
db_pandora_audit("Massive management", "Fail try to add tags",
false, false, "");
}
ui_print_result_message ($contsuccess > 0,
__('Successfully added') . "(" . $contsuccess . "/" . $conttotal . ")",
__('Could not be added'));
}
$id_agents = get_parameter ('id_agents');
$id_tags = get_parameter ('id_tags');
$modules = get_parameter ('module');
$add = (bool) get_parameter_post ('add');
if ($add) {
process_manage_add ($id_agents, $modules, $id_tags);
}
$groups = users_get_groups ();
$own_info = get_user_info($config['id_user']);
if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "AW"))
$return_all_group = false;
else
$return_all_group = true;
$table->id = 'add_table';
$table->width = '98%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold; vertical-align:top';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '40%';
$table->size[2] = '15%';
$table->size[3] = '40%';
$table->data = array ();
$table->data[0][0] = __('Group');
$table->data[0][1] = html_print_select_groups(false, "AW",
$return_all_group, 'id_group', 0, '', 'Select', -1, true, false,
true, '', false, 'width:180px;');
$table->data[1][0] = __('Agents');
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
$table->data[1][0] .= html_print_image('images/spinner.png', true);
$table->data[1][0] .= '</span>';
$agents = agents_get_group_agents(
array_keys(users_get_groups ($config["id_user"], "AW", false)));
$table->data[1][1] = html_print_select ($agents,
'id_agents[]', '', '', '', '', true, true, true, '', false, 'width:180px;');
$table->data[1][2] = __('Modules');
$table->data[1][2] .= '<span id="module_loading" class="invisible">';
$table->data[1][2] .= html_print_image('images/spinner.png', true);
$table->data[1][2] .= '</span>';
$table->data[1][3] = '<input type="hidden" id="modules_selection_mode" value="all" />' .
html_print_select (array(), 'module[]', '', false, '', '', true, true, false, '', false, 'width:180px;');
$table->data[2][0] = __('Tags');
$tags = tags_get_all_tags();
$table->data[2][1] = html_print_select ($tags,
'id_tags[]', '', '', '', '', true, true, true, '', false, 'width:180px;');
echo '<form method="post"
id="form_tags"
action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=add_tags">';
html_print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'" onsubmit="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
html_print_input_hidden ('add', 1);
html_print_submit_button (__('Add'), 'go', false, 'class="sub add"');
echo '</div>';
echo '</form>';
// TODO: Change to iu_print_error system
echo '<h3 class="error invisible" id="message"> </h3>';
//Hack to translate text "none" in PHP to javascript
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
ui_require_jquery_file ('form');
ui_require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
$("#checkbox-recursion").click(function () {
$("#id_group").trigger("change");
});
$("#id_agents").change(agent_changed_by_multiple_agents);
$("#id_group").change (function () {
var $select = $("#id_agents").enable ();
$("#agent_loading").show ();
$("option", $select).remove ();
jQuery.post ("ajax.php",
{
"page" : "godmode/massive/massive_add_alerts",
"get_agents" : 1,
"id_group" : this.value,
"recursion" : $("#checkbox-recursion").is(":checked") ? 1 : 0,
// Add a key prefix to avoid auto sorting in js object conversion
"keys_prefix" : "_"
},
function (data, status) {
options = "";
jQuery.each (data, function (id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
options += "<option value=\""+id+"\">"+value+"</option>";
});
$("#id_agents").append (options);
$("#agent_loading").hide ();
$select.enable ();
},
"json"
);
});
$("#id_group").value = "0";
$("#id_group").click (
function () {
$(this).css ("width", "auto");
});
$("#id_group").blur (function () {
$(this).css ("width", "180px");
});
$("#id_agents").click (
function () {
$(this).css ("width", "auto");
});
$("#id_agents").blur (function () {
$(this).css ("width", "180px");
});
$("#module").click (
function () {
$(this).css ("width", "auto");
});
$("#module").blur (function () {
$(this).css ("width", "180px");
});
$("#modules_selection_mode").change (function() {
$("#id_agents").trigger('change');
});
});
/* ]]> */
</script>

View File

@ -78,146 +78,18 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all'
if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1))
$filter_for_module_deletion = false;
else
$filter_for_module_deletion = sprintf('nombre IN ("%s")', implode('","', $module_name));
$filter_for_module_deletion = sprintf('tagente_modulo.nombre IN ("%s")', implode('","', $module_name));
if ($config['dbtype'] == "oracle") {
$all_agent_modules = false;
if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1)) {
$all_agent_modules = true;
}
$names_to_long = array();
$i = 0;
foreach ($module_name as $name) {
if (strlen($name) > 30) {
$original_names[] = $module_name[$i];
unset($module_name[$i]);
$names_to_long[] = substr($name, 0, 28) . "%";
}
$i++;
}
$modules = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$modules .= sprintf(" id_agente IN (%s)", implode(",", $id_agents));
if (!empty($module_name) && (!$all_agent_modules)) {
$modules .= sprintf(" AND nombre IN ('%s')", implode("','", $module_name));
}
$modules = db_get_all_rows_sql($modules);
$modules2 = "";
if (!empty($names_to_long) && (!$all_agent_modules)) {
$modules2 = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$modules2 .= sprintf(" id_agente IN (%s) AND (", implode(",", $id_agents));
$j = 0;
foreach ($names_to_long as $name) {
if ($j == 0) {
$modules2 .= "nombre LIKE ('" . $name . "')";
}
else {
$modules2 .= " OR nombre LIKE ('" . $name . "')";
}
$j++;
}
$modules2 .= ")";
$modules2 = db_get_all_rows_sql($modules2);
$modules = array_merge($modules, $modules2);
}
$all_names = array();
foreach ($modules as $module) {
$all_modules[] = $module['id_agente_modulo'];
$all_names[] = $module['nombre'];
}
$modules = $all_modules;
$modules = array_unique($modules);
if (!empty($names_to_long) && (!$all_agent_modules)) {
$j = 0;
foreach ($all_names as $name) {
if (strlen($name) > 30) {
if (!in_array($name, $original_names)) {
unset($modules[$j]);
}
}
$j++;
}
}
}
else {
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
$filter_for_module_deletion, true);
}
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
$filter_for_module_deletion, true);
}
else {
if ($config['dbtype'] == "oracle") {
$all_agent_modules = false;
$names_to_long = array();
if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1)) {
$all_agent_modules = true;
}
$i = 0;
foreach ($module_name as $name) {
if (strlen($name) > 30) {
$original_names[] = $module_name[$i];
unset($module_name[$i]);
$names_to_long[] = substr($name, 0, 28) . "%";
}
$i++;
}
$modules = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$any_agent = false;
if ($id_agents == null) {
$any_agent = true;
}
if (!empty($id_agents)) {
$modules .= sprintf(" id_agente IN (%s)", implode(",", $id_agents));
$agents_selected = true;
}
if (!empty($module_name) && (!$all_agent_modules)) {
if ($any_agent) {
$modules .= sprintf(" nombre IN ('%s')", implode("','", $module_name));
}
else {
$modules .= sprintf(" AND nombre IN ('%s')", implode("','", $module_name));
}
}
$modules = db_get_all_rows_sql($modules);
if (!empty($names_to_long) && (!$all_agent_modules)) {
$modules2 = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$modules2 .= sprintf(" id_agente IN (%s) AND (", implode(",", $id_agents));
$j = 0;
foreach ($names_to_long as $name) {
if ($j == 0) {
$modules2 .= "nombre LIKE ('" . $name . "')";
}
else {
$modules2 .= " OR nombre LIKE ('" . $name . "')";
}
$j++;
}
$modules2 .= ")";
$modules2 = db_get_all_rows_sql($modules2);
$modules = array_merge($modules, $modules2);
}
$all_names = array();
foreach ($modules as $module) {
$all_modules[] = $module['id_agente_modulo'];
$all_names[] = $module['nombre'];
}
$modules = $all_modules;
$modules = array_unique($modules);
if (!empty($names_to_long) && (!$all_agent_modules)) {
$j = 0;
foreach ($all_names as $name) {
if (strlen($name) > 30) {
if (!in_array($name, $original_names)) {
unset($modules[$j]);
}
}
$j++;
}
}
}
else {
if ($status_module != -1) // If module status filter has been applied
$modules = agents_get_modules ($id_agents, 'id_agente_modulo', sprintf('nombre IN ("%s") AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where estado = %s OR utimestamp=0 )', implode('","',$module_name), $status_module), true);
else
$modules = agents_get_modules ($id_agents, 'id_agente_modulo', sprintf('nombre IN ("%s")', implode('","',$module_name)), true);
if ($status_module != -1) {
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
sprintf('tagente_modulo.nombre IN ("%s") AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where estado = %s OR utimestamp=0 )', implode('","',$module_name), $status_module), true);
} else {
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
'tagente_modulo.nombre IN ("' . implode('","',$module_name) . '")', true);
}
}
@ -236,12 +108,7 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all'
}
$count_deleted_modules = count($modules);
if ($config['dbtype'] == "oracle") {
$success = db_process_sql(sprintf("DELETE FROM tagente_modulo WHERE id_agente_modulo IN (%s)", implode(",", $modules)));
}
else {
$success = modules_delete_agent_module ($modules);
}
$success = modules_delete_agent_module ($modules);
if (! $success) {
ui_print_error_message(
@ -258,8 +125,6 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all'
}
$module_type = (int) get_parameter ('module_type');
$idGroupMassive = (int) get_parameter('id_group_massive');
$idAgentMassive = (int) get_parameter('id_agent_massive');
$group_select = get_parameter('groups_select');
$delete = (bool) get_parameter_post ('delete');
@ -281,9 +146,7 @@ if ($delete) {
$agents_ = array();
}
foreach ($agents_select as $agent_name) {
$agents_[] = agents_get_agent_id(io_safe_output($agent_name));
}
$agents_ = $agents_select;
$modules_ = $module_name;
break;
case 'agents':
@ -366,35 +229,18 @@ $groups = users_get_groups ();
$agents = agents_get_group_agents (array_keys (users_get_groups ()),
false, "none");
switch ($config["dbtype"]) {
case "mysql":
$module_types = db_get_all_rows_filter ('tagente_modulo,ttipo_modulo',
array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo',
'id_agente' => array_keys ($agents),
'disabled' => 0,
'order' => 'ttipo_modulo.nombre'),
array ('DISTINCT(id_tipo)',
'CONCAT(ttipo_modulo.descripcion," (",ttipo_modulo.nombre,")") AS description'));
break;
case "oracle":
$module_types = db_get_all_rows_filter ('tagente_modulo,ttipo_modulo',
array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo',
'id_agente' => array_keys ($agents),
'disabled' => 0,
'order' => 'ttipo_modulo.nombre'),
array ('ttipo_modulo.id_tipo',
'ttipo_modulo.descripcion || \' (\' || ttipo_modulo.nombre || \')\' AS description'));
break;
case "postgresql":
$module_types = db_get_all_rows_filter ('tagente_modulo,ttipo_modulo',
array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo',
'id_agente' => array_keys ($agents),
'disabled' => 0,
'order' => 'description'),
array ('DISTINCT(id_tipo)',
'ttipo_modulo.descripcion || \' (\' || ttipo_modulo.nombre || \')\' AS description'));
break;
}
$module_types = db_get_all_rows_filter (
'tagente_modulo,ttipo_modulo',
array (
'tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo',
'id_agente' => array_keys ($agents),
'disabled' => 0,
'order' => 'ttipo_modulo.nombre'
), array (
'DISTINCT(id_tipo)',
'CONCAT(ttipo_modulo.descripcion," (",ttipo_modulo.nombre,")") AS description'
)
);
if ($module_types === false)
$module_types = array ();
@ -410,16 +256,12 @@ $table->data = array ();
$table->style[0] = 'font-weight: bold';
$table->style[2] = 'font-weight: bold';
$table->data['selection_mode'][0] = __('Selection mode');
$table->data['selection_mode'][1] = '<span style="width:110px;display:inline-block;">'.__('Select modules first ') . '</span>' .
html_print_radio_button_extended ("selection_mode", 'modules', '', $selection_mode, false, '', 'style="margin-right: 40px;"', true).'<br>';
$table->data['selection_mode'][1] .= '<span style="width:110px;display:inline-block;">'.__('Select agents first ') . '</span>' .
html_print_radio_button_extended ("selection_mode", 'agents', '', $selection_mode, false, '', 'style="margin-right: 40px;"', true);
$table->rowclass['form_modules_1'] = 'select_modules_row';
$table->data['form_modules_1'][0] = __('Module type');
$table->data['form_modules_1'][0] .= '<span id="module_loading" class="invisible">';
@ -434,8 +276,6 @@ $table->data['form_modules_1'][3] = __('Select all modules of this type') . ' '
html_print_checkbox_extended("force_type", 'type', '', '', false,
'', 'style="margin-right: 40px;"', true);
$modules = array ();
if ($module_type != '') {
$filter = array ('id_tipo_modulo' => $module_type);
@ -443,9 +283,8 @@ if ($module_type != '') {
else {
$filter = false;
}
$names = agents_get_modules (array_keys ($agents),
'DISTINCT(nombre)', $filter, false);
'DISTINCT(tagente_modulo.nombre)', $filter, false);
foreach ($names as $name) {
$modules[$name['nombre']] = $name['nombre'];
}

View File

@ -1,305 +0,0 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// 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.
// Load global vars
check_login ();
if (! check_acl ($config['id_user'], 0, "AW")) {
db_pandora_audit("ACL Violation",
"Trying to access massive tag deletion");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_agents.php');
require_once ('include/functions_tags.php');
if (is_ajax ()) {
$get_agents = (bool)get_parameter('get_agents', false);
$get_modules = (bool)get_parameter('get_modules', false);
if ($get_agents) {
$id_tag = (int)get_parameter('id_tag', 0);
$agents = tags_get_agents($id_tag);
if (!empty($agents)) {
$temp = array();
foreach ($agents as $id_agent) {
$temp[$id_agent] = agents_get_name($id_agent);
}
$agents = $temp;
}
echo json_encode($agents);
return;
}
if ($get_modules) {
$id_tag = (int)get_parameter('id_tag', 0);
$id_agents = (array)get_parameter('id_agents', array());
if (!empty($id_agents)) {
foreach ($id_agents as $key => $id) {
$id_agents[$key] = (int)$id;
}
$data = db_get_all_rows_sql("
SELECT nombre
FROM tagente_modulo
WHERE id_agente IN (" . implode(',', $id_agents) . ")
AND id_agente_modulo IN (
SELECT t1.id_agente_modulo
FROM ttag_module t1
WHERE id_tag = " . $id_tag . "
AND id_policy_module = 0)
GROUP BY nombre;");
if (empty($data)) {
echo json_encode(array());
}
else {
$modules = array();
foreach ($data as $row) {
$modules[] = $row['nombre'];
}
echo json_encode($modules);
}
}
else {
echo json_encode(array());
}
return;
}
return;
}
function process_manage_delete ($id_agents, $modules, $id_tag) {
if (empty ($id_agents) || $id_agents[0] == 0) {
ui_print_error_message(__('No agents selected'));
return false;
}
if (empty ($modules) || $modules[0] == "0") {
ui_print_error_message(__('No modules selected'));
return false;
}
if (empty ($id_tag)) {
ui_print_error_message(__('No tag selected'));
return false;
}
$modules_id = array();
foreach ($modules as $module) {
$data = db_get_all_rows_sql("
SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre = '" . $module . "'
AND id_agente IN (" . implode(",", $id_agents) . ")
");
if (empty($data)) {
$data = array();
}
foreach ($data as $row) {
$modules_id[$row['id_agente_modulo']] = $row['id_agente_modulo'];
}
}
$conttotal = 0;
$contsuccess = 0;
foreach ($modules_id as $id_module) {
$success = tags_remove_tag($id_tag, $id_module);
if ($success) {
$contsuccess ++;
}
$conttotal ++;
}
if ($contsuccess > 0) {
db_pandora_audit("Massive management", "Delete tags", false, false,
"");
}
else {
db_pandora_audit("Massive management", "Fail try to delete tags",
false, false, "");
}
ui_print_result_message ($contsuccess > 0,
__('Successfully deleted') . "(" . $contsuccess . "/" . $conttotal . ")",
__('Could not be deleted'));
}
$id_agents = get_parameter ('id_agents');
$id_tag = (int)get_parameter ('id_tag');
$modules = get_parameter ('modules');
$delete = (bool) get_parameter_post ('delete');
if ($delete) {
process_manage_delete ($id_agents, $modules, $id_tag);
}
$groups = users_get_groups ();
$own_info = get_user_info($config['id_user']);
if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "AW"))
$return_all_group = false;
else
$return_all_group = true;
$table->id = 'add_table';
$table->width = '98%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold; vertical-align:top';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '40%';
$table->size[2] = '15%';
$table->size[3] = '40%';
$table->data = array ();
$table->data[0][0] = __('Tags');
$tags = tags_get_all_tags();
$table->data[0][1] = html_print_select ($tags,
'id_tag', '', '', '', '', true, false, true, '', false, 'min-width:180px;');
$table->data[1][0] = __('Agents');
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
$table->data[1][0] .= html_print_image('images/spinner.png', true);
$table->data[1][0] .= '</span>';
$table->data[1][1] = html_print_select (array(),
'id_agents[]', '', '', '', '', true, true, true, '', false, 'min-width:180px;');
$table->data[2][0] = __('Modules');
$table->data[2][0] .= '<span id="modules_loading" class="invisible">';
$table->data[2][0] .= html_print_image('images/spinner.png', true);
$table->data[2][0] .= '</span>';
$table->data[2][1] = '<input type="hidden" id="modules_selection_mode" value="all" />' .
html_print_select (array(), 'modules[]', '', false, '', '', true, true, false, '', false, 'min-width:180px;');
echo '<form method="post"
id="form_tags"
action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_tags">';
html_print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'" onsubmit="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
html_print_input_hidden ('delete', 1);
html_print_submit_button (__('Delete'), 'go', false, 'class="sub delete"');
echo '</div>';
echo '</form>';
// TODO: Change to iu_print_error system
echo '<h3 class="error invisible" id="message"> </h3>';
//Hack to translate text "none" in PHP to javascript
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
ui_require_jquery_file ('form');
ui_require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
$("#id_tag").change(function() {
$("#agent_loading").show();
jQuery.post ("ajax.php",
{
"page" : "godmode/massive/massive_delete_tags",
"get_agents" : 1,
"id_tag" : this.value,
},
function (data, status) {
$("#id_agents").empty();
options = "";
jQuery.each (data, function (id, value) {
options += "<option value=\""+id+"\">"+value+"</option>";
});
if (options == "") {
$("#id_agents").append(
"<option value=\"0\"><?php echo __('None');?></option>");
}
else {
$("#id_agents").append (options);
}
$("#agent_loading").hide ();
$("#id_agents").trigger('change');
},
"json"
);
});
//~ $("#id_agents").change(agent_changed_by_multiple_agents);
$("#id_agents").change(function() {
//Fill modules
$("#modules_loading").show();
jQuery.post ("ajax.php",
{
"page" : "godmode/massive/massive_delete_tags",
"get_modules" : 1,
"id_tag": $("#id_tag").val(),
"id_agents[]" : $("#id_agents").val(),
},
function (data, status) {
$("#modules").empty();
options = "";
jQuery.each (data, function (id, value) {
options += "<option value=\""+value+"\">"+value+"</option>";
});
if (options == "") {
$("#modules").append(
"<option value=\"0\"><?php echo __('None');?></option>");
}
else {
$("#modules").append (options);
}
$("#modules_loading").hide ();
},
"json"
);
});
$("#id_tag").trigger('change');
});
/* ]]> */
</script>

View File

@ -338,6 +338,7 @@ $agents = agents_get_group_agents (array_keys ($groups));
$modules = db_get_all_rows_sql("SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo
WHERE id_agente = " . $id_parent);
if ($modules === false) $modules = array();
$modules_values = array();
$modules_values[0] = __('Any');

View File

@ -282,7 +282,7 @@ else {
}
$names = agents_get_modules (array_keys ($agents),
'DISTINCT(nombre)', $filter, false);
'DISTINCT(tagente_modulo.nombre)', $filter, false);
foreach ($names as $name) {
$modules[$name['nombre']] = $name['nombre'];
}

View File

@ -66,7 +66,6 @@ if ($enterpriseEnable) {
}
$subsection = reporting_enterprise_add_graph_template_subsection('', $buttons);
reporting_enterprise_select_graph_template_tab();
$buttons['graph_container'] = array('active' => true,
'text' => '<a href="index.php?sec=reporting&sec2=godmode/reporting/graph_container">' .

View File

@ -420,9 +420,11 @@ foreach ($layoutDatas as $layoutData) {
}
else {
if ($layoutData['id_agent'] != 0) {
$modules = agents_meta_get_modules(
$layoutData['id_metaconsole'],
$layoutData['id_agent']);
$server = db_get_row('tmetaconsole_setup', 'id', $layoutData['id_metaconsole']);
if (metaconsole_connect($server) == NOERR) {
$modules = agents_get_modules($layoutData['id_agent']);
metaconsole_restore_db();
}
}
}

View File

@ -560,7 +560,6 @@ switch ($activeTab) {
foreach ($name_modules as $mod) {
foreach ($id_agents as $ag) {
$id_module = agents_get_modules($ag,
array('id_agente_modulo'),
array('nombre' => $mod));

View File

@ -555,7 +555,7 @@ if ($table_events) {
// Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!)
$groups = users_get_groups($config["id_user"]);
$tags_condition = tags_get_acl_tags($config['id_user'],
array_keys($groups), 'ER', 'event_condition', 'AND');
echo '<div id="div_all_events_24h">';

View File

@ -74,9 +74,9 @@ if ($search_modules) {
$id_agents = json_decode(io_safe_output(get_parameter('id_agents')));
$filter = '%' . get_parameter('q', '') . '%';
$other_filter = json_decode(io_safe_output(get_parameter('other_filter')), true);
// TODO TAGS agents_get_modules
$modules = agents_get_modules($id_agents, false,
(array('nombre' => $filter) + $other_filter));
(array('tagente_modulo.nombre' => $filter) + $other_filter));
if ($modules === false) $modules = array();
@ -550,10 +550,18 @@ if ($list_modules) {
// Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!)
$groups = users_get_groups($config["id_user"], $access);
if($cluster_list != 1){
$tags_sql = tags_get_acl_tags($config['id_user'],
array_keys($groups), $access, 'module_condition', 'AND',
'tagente_modulo', false, array(), true);
$tags_join = "";
$tags_sql = "";
if($cluster_list != 1) {
$tags = tags_get_user_applied_agent_tags ($id_agent, $access);
if ($tags === false) {
$tags_sql = " AND 1=0";
}
elseif (is_array($tags)) {
$tags_sql = " AND ttag_module.id_tag IN (" . implode(',', $tags) . ")";
$tags_join = "LEFT JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
}
}
$status_filter_monitor = (int)get_parameter('status_filter_monitor', -1);
@ -571,10 +579,10 @@ if ($list_modules) {
}
if ($status_module_group != -1) {
$status_module_group_filter = 'id_module_group = ' . $status_module_group;
$status_module_group_filter = 'tagente_modulo.id_module_group = ' . $status_module_group;
}
else {
$status_module_group_filter = 'id_module_group >= 0';
$status_module_group_filter = 'tagente_modulo.id_module_group >= 0';
}
$status_text_monitor_sql = '%';
@ -590,66 +598,22 @@ if ($list_modules) {
}
//Count monitors/modules
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf("
SELECT COUNT(*)
FROM tagente_estado,
(SELECT *
FROM tagente_modulo
WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0
AND disabled = 0 AND %s) tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND %s %s
AND tagente_estado.estado != %d
AND tagente_modulo.%s
ORDER BY tagente_modulo.id_module_group , %s %s",
$id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter,
$status_module_group_filter, $order['field'], $order['order']);
break;
case "postgresql":
$sql = sprintf("
SELECT COUNT(DISTINCT tagente_modulo.id_module_group)
FROM tagente_estado,
(SELECT *
FROM tagente_modulo
WHERE id_agente = %d AND nombre LIKE '%s'
AND delete_pending = 0
AND disabled = 0 AND %s) tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND %s %s
AND tagente_estado.estado != %d
AND tagente_modulo.%s
GROUP BY tagente_modulo.id_module_group,
tagente_modulo.nombre
ORDER BY tagente_modulo.id_module_group , %s %s",
$id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql,
$tags_sql, $monitor_filter,$status_module_group_filter,$order['field'],
$order['order']);
break;
case "oracle":
$sql = sprintf ("
SELECT COUNT(*)" .
" FROM tagente_estado, tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.id_agente = %d
AND tagente_modulo.nombre LIKE '%s'
AND %s %s
AND tagente_modulo.delete_pending = 0
AND tagente_modulo.disabled = 0
AND tagente_estado.estado != %d
AND tagente_modulo.%s
ORDER BY tagente_modulo.id_module_group , %s %s
", $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, $monitor_filter,
$status_module_group_filter,$order['field'], $order['order']);
break;
}
$order_sql = $order['field'] . " " . $order['order'];
$sql = "SELECT COUNT(*)
FROM tagente_modulo
$tags_join
INNER JOIN tagente_estado
ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE tagente_modulo.id_agente = $id_agente
AND nombre LIKE '$status_text_monitor_sql'
AND delete_pending = 0
AND $status_filter_sql
$tags_sql
AND tagente_estado.estado != $monitor_filter
GROUP BY tagente_modulo.id_agente_modulo
";
$count_modules = db_get_all_rows_sql($sql);
if (isset($count_modules[0]))
@ -659,68 +623,22 @@ if ($list_modules) {
//Get monitors/modules
// Get all module from agent
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf("
SELECT *
FROM tagente_estado,
(SELECT *
FROM tagente_modulo
WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0
AND disabled = 0 AND %s) tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND %s %s
AND tagente_estado.estado != %d
AND tagente_modulo.%s
ORDER BY tmodule_group.name , %s %s",
$id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter,
$status_module_group_filter, $order['field'], $order['order']);
break;
case "postgresql":
$sql = sprintf("
SELECT *
FROM tagente_estado,
(SELECT *
FROM tagente_modulo
WHERE id_agente = %d AND nombre LIKE '%s' AND delete_pending = 0
AND disabled = 0 AND %s) tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND %s %s
AND tagente_estado.estado != %d
AND tagente_modulo.%s
ORDER BY tmodule_group.name , %s %s",
$id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter,
$status_module_group_filter, $order['field'], $order['order']);
break;
// If Dbms is Oracle then field_list in sql statement has to be recoded. See oracle_list_all_field_table()
case "oracle":
$fields_tagente_estado = oracle_list_all_field_table('tagente_estado', 'string');
$fields_tagente_modulo = oracle_list_all_field_table('tagente_modulo', 'string');
$fields_tmodule_group = oracle_list_all_field_table('tmodule_group', 'string');
$sql = sprintf ("
SELECT " . $fields_tagente_estado . ', ' . $fields_tagente_modulo . ', ' . $fields_tmodule_group .
" FROM tagente_estado, tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.id_agente = %d
AND tagente_modulo.nombre LIKE '%s'
AND %s %s
AND tagente_modulo.delete_pending = 0
AND tagente_modulo.disabled = 0
AND tagente_estado.estado != %d
AND tagente_modulo.%s
ORDER BY tmodule_group.name , %s %s
", $id_agente, $status_text_monitor_sql, $tags_sql, $status_filter_sql, $monitor_filter,
$status_module_group_filter, $order['field'], $order['order']);
break;
}
$sql = "SELECT tagente_estado.*, tagente_modulo.*, tmodule_group.*
FROM tagente_modulo
$tags_join
INNER JOIN tagente_estado
ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE tagente_modulo.id_agente = $id_agente
AND nombre LIKE '$status_text_monitor_sql'
AND delete_pending = 0
AND $status_filter_sql
$tags_sql
AND tagente_estado.estado != $monitor_filter
GROUP BY tagente_modulo.id_agente_modulo
ORDER BY tmodule_group.name, $order_sql
";
if ($monitors_change_filter) {
$limit = " LIMIT " . $config['block_size'] . " OFFSET 0";

View File

@ -993,7 +993,6 @@ switch ($action) {
if (isset($elementFields["linked_layout_status_as_service_warning"])) {
$elementFields["linked_layout_status_as_service_warning"] = (float) $elementFields["linked_layout_status_as_service_warning"];
}
switch ($type) {
case 'auto_sla_graph':
$elementFields['event_max_time_row'] = $elementFields['period'];
@ -1059,7 +1058,7 @@ switch ($action) {
$elementFields['id_agent'], false,
array('disabled' => 0,
'id_agente' => $elementFields['id_agent'],
'tagente_modulo.id_tipo_modulo IN' => "(17,23,3,10,33)"));
'tagente_modulo.id_tipo_modulo IN' => "(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,17,23,3,10,33)"));
$elementFields['modules_html'] = '<option value="0">--</option>';
foreach ($modules as $id => $name) {

View File

@ -28,7 +28,6 @@ class Tree {
protected $userGroups;
protected $userGroupsArray;
protected $acltags = false;
protected $access = false;
protected $L1fieldName = '';
@ -69,8 +68,6 @@ class Tree {
enterprise_include_once("include/functions_agents.php");
if (is_metaconsole()) enterprise_include_once("meta/include/functions_ui_meta.php");
$this->acltags = tags_get_user_groups_and_tags($config['id_user'], $this->access);
}
public function setFilter($filter) {
@ -205,26 +202,19 @@ class Tree {
return "AND ta.$field_filter > 0" . $show_init_condition;
}
// FIXME: Separate and condition from inner join
protected function getTagJoin () {
// $parent is the agent id
$group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $this->id);
$tag_join = '';
if (empty($group_id)) {
// ACL error, this will restrict the module search
$tag_join = 'INNER JOIN ttag_module tta
ON 1=0';
}
else if (!empty($this->acltags) && isset($this->acltags[$group_id])) {
$tags_str = $this->acltags[$group_id];
return 'INNER JOIN ttag_module ttm
ON tam.id_agente_modulo = ttm.id_agente_modulo';
}
if (!empty($tags_str)) {
$tag_join = sprintf('INNER JOIN ttag_module ttm
ON tam.id_agente_modulo = ttm.id_agente_modulo
AND ttm.id_tag IN (%s)', $tags_str);
}
}
return $tag_join;
protected function getTagCondition () {
$tags = tags_get_user_applied_agent_tags($this->id, "AR");
// All tags permision, returns no condition
if ($tags === true) return "";
// No permision, do not show anything
if ($tags === false) return " AND 1=0";
$tags_sql = implode(',', $tags);
return "AND ttm.id_tag IN ($tags_sql)";;
}
protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) {
@ -900,7 +890,8 @@ class Tree {
$module_search_filter = $this->getModuleSearchFilter();
$module_status_filter = $this->getModuleStatusFilterFromTestado();
$agent_filter = "AND ta.id_agente = " . $this->id;
$tag_join = $this->getTagJoin();
$tag_condition = $this->getTagCondition();
$tag_join = empty($tag_condition) ? '' : $this->getTagJoin();
$condition = $this->L2condition;
$inner = $this->L2inner;
@ -909,9 +900,6 @@ class Tree {
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos,
tam.parent_module_id AS parent, tatm.id AS alerts';
// has any of this tags.
$tag_join = '';
$sql = "SELECT $columns
FROM tagente_modulo tam
$tag_join
@ -932,6 +920,7 @@ class Tree {
$agent_status_filter
$module_status_filter
$module_search_filter
$tag_condition
ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC";
return $sql;
}

View File

@ -48,6 +48,14 @@ class TreeTag extends Tree {
$this->getThirdLevel();
}
}
protected function getTagJoin () {
return '';
}
protected function getTagCondition () {
return '';
}
}
?>

View File

@ -599,7 +599,6 @@ function agents_process_manage_config ($source_id_agent, $destiny_id_agents, $co
$module = modules_get_agentmodule ($id_agent_module);
if ($module === false)
return false;
$modules = agents_get_modules ($id_destiny_agent, false,
array ('nombre' => $module['nombre'], 'disabled' => false));
@ -825,8 +824,9 @@ function agents_get_group_agents (
$filter = array();
if (!$noACL) {
$id_group = groups_safe_acl($config["id_user"], $id_group, "AR");
$id_group = $id_group == 0
? array_keys(users_get_groups(false, "AR", false))
: groups_safe_acl($config["id_user"], $id_group, "AR");
if (empty ($id_group)) {
//An empty array means the user doesn't have access
return array ();
@ -1077,7 +1077,8 @@ function agents_get_modules ($id_agent = null, $details = false,
if (empty($userGroups)) {
return array();
}
$id_userGroups = $id_groups = array_keys($userGroups);
$id_groups = array_keys($userGroups);
$id_groups_sql = implode(',', $id_groups);
// =================================================================
// When there is not a agent id. Get a agents of groups that the
@ -1107,49 +1108,25 @@ function agents_get_modules ($id_agent = null, $details = false,
if (!is_array($id_agent)) {
$id_agent = safe_int ($id_agent, 1);
}
$where = "(
1 = (
SELECT is_admin
FROM tusuario
WHERE id_user = '" . $config['id_user'] . "'
)
OR
tagente_modulo.id_agente IN (
SELECT id_agente
FROM tagente tas LEFT JOIN tagent_secondary_group tasgs
ON tas.id_agente = tasgs.id_agent
WHERE (tas.id_grupo IN (
" . implode(',', $id_userGroups) . "
) OR
tasgs.id_group IN (
" . implode(',', $id_userGroups) . "
)
)
)
OR 0 IN (
SELECT id_grupo
FROM tusuario_perfil
WHERE id_usuario = '" . $config['id_user'] . "'
AND id_perfil IN (
SELECT id_perfil
FROM tperfil WHERE agent_view = 1
)
)
$where = "1 = 1 ";
// Groups ACL only when user is not empty
if (!users_can_manage_group_all("AR")) {
$where = "(
tagente.id_grupo IN ($id_groups_sql) OR tasg.id_group IN ($id_groups_sql)
)";
if (! empty ($id_agent)) {
$where .= sprintf (' AND id_agente IN (%s)', implode (",", (array) $id_agent));
}
$where .= ' AND delete_pending = 0 ';
if (! empty ($id_agent)) {
$id_agent_sql = implode (",", (array)$id_agent);
$where .= " AND tagente.id_agente IN ($id_agent_sql) ";
}
if (! empty ($filter)) {
$where .= ' AND ';
if (is_array ($filter)) {
$fields = array ();
//----------------------------------------------------------
// Code for filters as array of arrays
// for example:
@ -1174,11 +1151,10 @@ function agents_get_modules ($id_agent = null, $details = false,
}
}
//----------------------------------------------------------
foreach ($list_filter as $item) {
$field = $item['field'];
$value = $item['value'];
//Check <> operator
$operatorDistin = false;
if (strlen($value) > 2) {
@ -1186,119 +1162,91 @@ function agents_get_modules ($id_agent = null, $details = false,
$operatorDistin = true;
}
}
if ($value[0] == '%') {
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
array_push ($fields,
$field . ' LIKE "' . $value . '"');
break;
case "oracle":
array_push ($fields,
$field . ' LIKE \'' . $value . '\'');
break;
}
array_push ($fields,
$field . ' LIKE "' . $value . '"');
}
else if ($operatorDistin) {
array_push($fields, $field.' <> ' . substr($value, 2));
}
else if (substr($value, -1) == '%') {
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
array_push ($fields, $field.' LIKE "'.$value.'"');
break;
case "oracle":
array_push ($fields, $field.' LIKE \''.$value.'\'');
break;
}
array_push ($fields, $field.' LIKE "'.$value.'"');
}
//else if (strstr($value, '666=666', true) == '') {
else if (strncmp($value, '666=666', 7) == 0) {
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
array_push ($fields, ' '.$value);
break;
case "oracle":
array_push ($fields, ' '.$value);
break;
}
array_push ($fields, ' '.$value);
}
else if (preg_match('/\bin\b/i',$field)) {
array_push ($fields, $field.' '.$value);
}
else {
switch ($config["dbtype"]) {
case "mysql":
array_push ($fields, $field.' = "'.$value.'"');
break;
case "postgresql":
array_push ($fields, $field.' = \''.$value.'\'');
break;
case "oracle":
if (is_int ($value) || is_float ($value) || is_double ($value))
array_push ($fields, $field.' = '.$value.'');
else
array_push ($fields, $field.' = \''.$value.'\'');
break;
}
array_push ($fields, 'tagente_modulo.' . $field.' = "'.$value.'"');
}
}
$where .= implode (' AND ', $fields);
$where .= implode (' AND ', $fields);
}
else {
$where .= $filter;
}
}
$stored_details = $details;
if (empty ($details)) {
$details = "nombre";
$details = "tagente_modulo.nombre";
$stored_details = "nombre";
}
else {
else {
$details = (array)$details;
$details = io_safe_input ($details);
$details = array_map(function ($a) {
return preg_match('/tagente_modulo./i', $a) ? $a : 'tagente_modulo.' . $a;
},$details
);
}
//$where .= " AND id_policy_module = 0 ";
$sql_tags_join = "";
if (tags_has_user_acl_tags($config['id_user'])){
$where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR',
'module_condition', 'AND', 'tagente_modulo', false, array(),
true);
true);
$where .= "\n\n" . $where_tags;
$sql_tags_join = "INNER JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
}
$sql = sprintf ('SELECT %s%s
FROM tagente_modulo
WHERE
%s
ORDER BY nombre',
($details != '*' && $indexed) ? 'id_agente_modulo,' : '',
%s
INNER JOIN tagente
ON tagente.id_agente = tagente_modulo.id_agente
LEFT JOIN tagent_secondary_group tasg
ON tagente.id_agente = tasg.id_agent
WHERE tagente_modulo.delete_pending = 0
AND %s
GROUP BY tagente_modulo.id_agente_modulo
ORDER BY tagente_modulo.nombre',
($details != 'tagente_modulo.*' && $indexed) ? 'tagente_modulo.id_agente_modulo,' : '',
io_safe_output(implode (",", (array) $details)),
$sql_tags_join,
$where);
$result = db_get_all_rows_sql ($sql);
if (empty ($result)) {
return array ();
}
if (! $indexed)
return $result;
$modules = array ();
foreach ($result as $module) {
if ($get_not_init_modules || modules_get_agentmodule_is_init($module['id_agente_modulo'])) {
if (is_array ($details) || $details == '*') {
if (is_array ($stored_details) || $stored_details == '*') {
//Just stack the information in array by ID
$modules[$module['id_agente_modulo']] = $module;
}
else {
$modules[$module['id_agente_modulo']] = $module[$details];
$modules[$module['id_agente_modulo']] = $module[$stored_details];
}
}
}
@ -1400,55 +1348,6 @@ function agents_get_alias_by_name ($name, $case = 'none') {
}
}
/**
* Get the number of pandora data packets in the database.
*
* In case an array is passed, it will have a value for every agent passed
* incl. a total otherwise it will just return the total
*
* @param mixed Agent id or array of agent id's, 0 for all
*
* @return mixed The number of data in the database
*/
function agents_get_modules_data_count ($id_agent = 0) {
$id_agent = safe_int ($id_agent, 1);
if (empty ($id_agent)) {
$id_agent = array ();
}
else {
$id_agent = (array) $id_agent;
}
$count = array ();
$count["total"] = 0;
$query[0] = "SELECT COUNT(*) FROM tagente_datos";
foreach ($id_agent as $agent_id) {
//Init value
$count[$agent_id] = 0;
$modules = array_keys (agents_get_modules ($agent_id));
foreach ($query as $sql) {
//Add up each table's data
//Avoid the count over empty array
if (!empty($modules))
$count[$agent_id] += (int) db_get_sql ($sql .
" WHERE id_agente_modulo IN (".implode (",", $modules).")", 0, true);
}
//Add total agent count to total count
$count["total"] += $count[$agent_id];
}
if ($count["total"] == 0) {
foreach ($query as $sql) {
$count["total"] += (int) db_get_sql ($sql, 0, true);
}
}
return $count; //Return the array
}
/**
* Check if an agent has alerts fired.
*
@ -2202,23 +2101,6 @@ function agents_monitor_total ($id_agent, $filter = '', $disabled = false) {
return db_get_sql ($sql);
}
//Get alert fired for this agent
function agents_get_alerts_fired ($id_agent, $filter="") {
$modules_agent = agents_get_modules($id_agent, "id_agente_modulo", $filter);
if (empty($modules_agent)) {
return 0;
}
$mod_clause = "(".implode(",", $modules_agent).")";
return db_get_sql ("SELECT COUNT(times_fired)
FROM talert_template_modules
WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause);
}
//Returns the alert image to display tree view
function agents_tree_view_alert_img ($alert_fired) {
@ -2453,8 +2335,7 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false)
else
$columns[] = 'descripcion';
$filter = " id_agente = $agent_id AND disabled = 0 AND id_tipo_modulo IN (".implode(",", $accepted_module_types).") AND (nombre LIKE '%_ifOperStatus' OR nombre LIKE 'ifOperStatus_%')";
$filter = " tagente_modulo.id_agente = $agent_id AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo IN (".implode(",", $accepted_module_types).") AND (tagente_modulo.nombre LIKE '%_ifOperStatus' OR tagente_modulo.nombre LIKE 'ifOperStatus_%')";
$modules = agents_get_modules($agent_id, $columns, $filter, true, false);
if (!empty($modules)) {
@ -2520,10 +2401,10 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false)
);
if($type_interface){
$interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE '". $interface_name . "_if%Octets'");
$interface_traffic_modules = agents_get_modules($agent_id, $columns, "tagente_modulo.nombre LIKE '". $interface_name . "_if%Octets'");
}
else{
$interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE 'if%Octets_$interface_name'");
$interface_traffic_modules = agents_get_modules($agent_id, $columns, "tagente_modulo.nombre LIKE 'if%Octets_$interface_name'");
}
if (!empty($interface_traffic_modules) && count($interface_traffic_modules) >= 2) {
@ -2611,85 +2492,173 @@ function agents_get_agent_custom_field ($agent_id, $custom_field_name) {
return db_get_value_sql($sql);
}
function select_modules_for_agent_group($id_group, $id_agents,
$selection, $return = true) {
$agents = implode(",", $id_agents);
function select_modules_for_agent_group(
$id_group, $id_agents, $selection, $return = true, $index_by_name = false
) {
global $config;
$agents = (empty($id_agents)) ? array() : implode(",", $id_agents);
$filter_agent_group = "";
$filter_group = "";
$filter_agent = "";
$selection_filter = "";
$sql_conditions_tags = "";
$sql_tags_inner = "";
$groups = array_keys(users_get_groups(false, "AR", false));
if ($id_group != 0) {
$filter_group = " AND id_module_group = ". $id_group;
$filter_group = " AND tagente_modulo.id_module_group = ". $id_group;
}
if ($agents != null) {
$filter_agent = " AND id_agente IN (" . $agents . ")";
$filter_agent = " AND tagente.id_agente IN (" . $agents . ")";
}
if (!users_can_manage_group_all("AR")) {
$group_string = implode(',', $groups);
$filter_agent_group = " AND (
tagente.id_grupo IN ($group_string)
OR tasg.id_group IN ($group_string)
)";
}
if (!$selection && $agents != null) {
$number_agents = count($id_agents);
$selection_filter = "HAVING COUNT(id_agente_modulo) = $number_agents";
}
if ($selection == 1 || (count($id_agents) == 1)) {
$modules = db_get_all_rows_sql("SELECT DISTINCT nombre, id_agente_modulo
FROM tagente_modulo
WHERE 1 = 1" . $filter_agent . $filter_group);
if (empty($modules)) $modules = array();
$found = array();
foreach ($modules as $i=>$row) {
$check = $row['nombre'];
if (@$found[$check]++) {
unset($modules[$i]);
}
}
if (tags_has_user_acl_tags(false)){
$sql_conditions_tags = tags_get_acl_tags(
$config['id_user'], $groups, 'AR',
'module_condition', 'AND', 'tagente_modulo', true, array(),
false);
$sql_tags_inner = "INNER JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
}
else {
$modules = db_get_all_rows_sql("SELECT nombre, id_agente_modulo
FROM tagente_modulo
WHERE 1 = 1" . $filter_agent . $filter_group);
if (empty($modules)) $modules = array();
$sql = "SELECT * FROM
(
SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.nombre
FROM tagente_modulo
$sql_tags_inner
INNER JOIN tagente
ON tagente.id_agente = tagente_modulo.id_agente
LEFT JOIN tagent_secondary_group tasg
ON tagente.id_agente = tasg.id_agent
WHERE tagente.disabled = 0
AND tagente_modulo.disabled = 0
$filter_agent_group
$filter_group
$filter_agent
$sql_conditions_tags
) x
GROUP BY nombre
$selection_filter";
foreach ($modules as $m) {
$is_in_all_agents = true;
$module_name = $m['nombre'];
foreach ($id_agents as $a) {
$module_in_agent = db_get_value_filter('id_agente_modulo',
'tagente_modulo', array('id_agente' => $a, 'nombre' => $module_name));
if (!$module_in_agent) {
$is_in_all_agents = false;
}
}
if ($is_in_all_agents) {
$modules_to_report[] = $m;
}
}
$modules = $modules_to_report;
$modules = db_get_all_rows_sql($sql);
if ($modules === false) $modules = array();
$found = array();
if (is_array($modules) || is_object($modules)){
foreach ($modules as $i=>$row) {
$check = $row['nombre'];
if (@$found[$check]++) {
unset($modules[$i]);
}
}
}
}
if (is_array($modules) || is_object($modules)){
foreach ($modules as $k => $v) {
$modules[$k] = io_safe_output($v);
}
}
if($return == false){
foreach ($modules as $value) {
$modules_array[$value['id_agente_modulo']] = $value['nombre'];
}
return $modules_array;
}
else{
if ($return) {
echo json_encode($modules);
return;
}
$modules_array = array();
foreach ($modules as $value) {
if($index_by_name) {
$modules_array[io_safe_output($value['nombre'])] =
ui_print_truncate_text(
io_safe_output($value['nombre']), 'module_medium', false, true
);
} else {
$modules_array[$value['id_agente_modulo']] = $value['nombre'];
}
}
return $modules_array;
}
function select_agents_for_module_group(
$module_names, $selection, $filter, $access = "AR"
) {
global $config;
$default_filter = array (
'status' => null
);
$filter = array_merge($default_filter, $filter);
$module_names_condition = "";
$filter_agent_group = "";
$selection_filter = "";
$sql_conditions_tags = "";
$sql_tags_inner = "";
$status_filter = "";
$module_type_filter = "";
$groups = array_keys(users_get_groups(false, $access, false));
// Name
if (!users_can_manage_group_all($access)) {
$group_string = implode(',', $groups);
$filter_agent_group = " AND (
tagente.id_grupo IN ($group_string)
OR tasg.id_group IN ($group_string)
)";
}
// Name filter
if ($module_names) {
$module_names_sql = implode("','", $module_names);
$module_names_condition = " AND tagente_modulo.nombre IN ('$module_names_sql') ";
}
// Common or all modules filter
if (!$selection) {
$number_modules = count($module_names);
$selection_filter = "HAVING COUNT(id_agente) = $number_modules";
}
// Status filter
if ($filter['status'] != null) {
$status_filter = " AND " . modules_get_state_condition(
$filter['status'], "tagente_estado"
);
}
// Tags input and ACL conditions
if (tags_has_user_acl_tags(false) || $filter['tags'] != null){
$sql_conditions_tags = tags_get_acl_tags(
$config['id_user'], $groups, $access,
'module_condition', 'AND', 'tagente_modulo', true, array(),
false);
$sql_tags_inner = "INNER JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
}
$sql = "SELECT * FROM
(
SELECT tagente.id_agente, tagente.alias
FROM tagente
LEFT JOIN tagent_secondary_group tasg
ON tagente.id_agente = tasg.id_agent
INNER JOIN tagente_modulo
ON tagente.id_agente = tagente_modulo.id_agente
$sql_tags_inner
LEFT JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
WHERE tagente.disabled = 0
AND tagente_modulo.disabled = 0
$module_names_condition
$filter_agent_group
$sql_conditions_tags
$status_filter
$module_type_filter
GROUP BY tagente_modulo.id_agente_modulo
) x
GROUP BY id_agente
$selection_filter";
$modules = db_get_all_rows_sql($sql);
if ($modules === false) return array();
return index_array(db_get_all_rows_sql($sql), 'id_agente', 'alias');
}
/**
@ -2723,6 +2692,7 @@ function agents_get_all_groups_agent ($id_agent, $group = false, $force_meta = f
// If cannot retrieve the group, it means that agent does not exist
if (!$group) return array();
enterprise_include_once('include/functions_agents.php');
$secondary_groups = enterprise_hook('agents_get_secondary_groups', array($id_agent, $force_meta));
// Return only an array with the group in open version

View File

@ -1824,23 +1824,6 @@ function get_group_alerts($id_group, $filter = '', $options = false,
FROM tagente_modulo WHERE delete_pending = 0';
}
if ($strict_user) {
$groups = users_get_groups($config["id_user"]);
if ($idGroup !== 0) {
$where_tags = tags_get_acl_tags($config['id_user'], $idGroup, 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true);
} else {
$where_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true);
}
// If there are any errors add imposible condition
if (in_array($where_tags, array(ERR_WRONG_PARAMETERS, ERR_ACL))) {
$subQuery .= ' AND 1 = 0';
}
else {
$subQuery .= $where_tags;
}
}
}
else {
if ($allModules)

View File

@ -1531,30 +1531,6 @@ function events_get_all_status ($report = false) {
return $fields;
}
/**
* Return all event source.
*
* @return array event source array.
*/
function events_get_all_source () {
$event_table = events_get_events_table(is_metaconsole(),false);
$fields = array ();
$fields[''] = __('All');
if (users_is_admin()) {
$sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table);
} else {
$groups_user = users_get_groups ($config['id_user'], "ER", true);
$sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table. " WHERE id_grupo IN (" .implode(",",array_keys($groups_user)) .")");
}
foreach ($sources as $key => $source) {
$fields[$source['source']] = $source['source'];
}
return $fields;
}
/**
* Decode a numeric status into status description.
*
@ -2240,12 +2216,7 @@ function events_page_details ($event, $server = "") {
$strict_user = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']);
if (!empty($agent['id_grupo'])) {
if ($strict_user) {
$acl_graph = tags_check_acl_by_module($module["id_agente_modulo"], $config['id_user'], 'RR') === true;
}
else {
$acl_graph = check_acl($config['id_user'], $agent['id_grupo'], "RR");
}
$acl_graph = check_acl($config['id_user'], $agent['id_grupo'], "RR");
}
if ($acl_graph) {
@ -3554,7 +3525,6 @@ function events_sql_events_grouped_agents($id_agent, $server_id = -1,
else {
$group_array = array_keys($groups);
}
$tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER',
'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
@ -3600,6 +3570,8 @@ function events_list_events_grouped_agents($sql) {
$table = events_get_events_table(is_metaconsole(), $history);
$sql = "select * from $table
LEFT JOIN tagent_secondary_group
ON tagent_secondary_group.id_agent = tevento.id_agente
WHERE $sql";
$result = db_get_all_rows_sql ($sql);

View File

@ -20,210 +20,6 @@ include_once($config['homedir'] . "/include/functions_agents.php");
include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_users.php");
function get_graph_statistics ($chart_array) {
global $config;
/// IMPORTANT!
///
/// The calculus for AVG, MIN and MAX values are in this function
/// because it must be done based on graph array data not using reporting
/// function to get coherent data between stats and graph visualization
$stats = array ();
$count = 0;
$size = sizeof($chart_array);
//Initialize stats array
$stats = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
foreach ($chart_array as $item) {
//Sum all values later divide by the number of elements
$stats['avg'] = $stats['avg'] + $item;
//Get minimum
if ($stats['min'] == null) {
$stats['min'] = $item;
}
else if ($item < $stats['min']) {
$stats['min'] = $item;
}
//Get maximum
if ($stats['max'] == null) {
$stats['max'] = $item;
}
else if ($item > $stats['max']) {
$stats['max'] = $item;
}
$count++;
//Get last data
if ($count == $size) {
$stats['last'] = $item;
}
}
//End the calculus for average
if ($count > 0) {
$stats['avg'] = $stats['avg'] / $count;
}
//Format stat data to display properly
$stats['last'] = remove_right_zeros(number_format($stats['last'], $config['graph_precision']));
$stats['avg'] = remove_right_zeros(number_format($stats['avg'], $config['graph_precision']));
$stats['min'] = remove_right_zeros(number_format($stats['min'], $config['graph_precision']));
$stats['max'] = remove_right_zeros(number_format($stats['max'], $config['graph_precision']));
return $stats;
}
function get_statwin_graph_statistics ($chart_array, $series_suffix = '') {
/// IMPORTANT!
///
/// The calculus for AVG, MIN and MAX values are in this function
/// because it must be done based on graph array data not using reporting
/// function to get coherent data between stats and graph visualization
$stats = array ();
$count = 0;
$size = sizeof($chart_array);
//Initialize stats array
$stats['sum'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
$stats['min'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
$stats['max'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
foreach ($chart_array as $item) {
if ($series_suffix != '') {
if (isset($item['sum' . $series_suffix]))
$item['sum'] = $item['sum' . $series_suffix];
if (isset($item['min' . $series_suffix]))
$item['min'] = $item['min' . $series_suffix];
if (isset($item['max' . $series_suffix]))
$item['max'] = $item['max' . $series_suffix];
}
//Get stats for normal graph
if (isset($item['sum']) && $item['sum']) {
//Sum all values later divide by the number of elements
$stats['sum']['avg'] = $stats['sum']['avg'] + $item['sum'];
//Get minimum
if ($stats['sum']['min'] == null) {
$stats['sum']['min'] = $item['sum'];
}
else if ($item['sum'] < $stats['sum']['min']) {
$stats['sum']['min'] = $item['sum'];
}
//Get maximum
if ($stats['sum']['max'] == null) {
$stats['sum']['max'] = $item['sum'];
}
else if ($item['sum'] > $stats['sum']['max']) {
$stats['sum']['max'] = $item['sum'];
}
}
//Get stats for min graph
if (isset($item['min']) && $item['min']) {
//Sum all values later divide by the number of elements
$stats['min']['avg'] = $stats['min']['avg'] + $item['min'];
//Get minimum
if ($stats['min']['min'] == null) {
$stats['min']['min'] = $item['min'];
}
else if ($item['min'] < $stats['min']['min']) {
$stats['min']['min'] = $item['min'];
}
//Get maximum
if ($stats['min']['max'] == null) {
$stats['min']['max'] = $item['min'];
}
else if ($item['min'] > $stats['min']['max']) {
$stats['min']['max'] = $item['min'];
}
}
//Get stats for max graph
if (isset($item['max']) && $item['max']) {
//Sum all values later divide by the number of elements
$stats['max']['avg'] = $stats['max']['avg'] + $item['max'];
//Get minimum
if ($stats['max']['min'] == null) {
$stats['max']['min'] = $item['max'];
}
else if ($item['max'] < $stats['max']['min']) {
$stats['max']['min'] = $item['max'];
}
//Get maximum
if ($stats['max']['max'] == null) {
$stats['max']['max'] = $item['max'];
}
else if ($item['max'] > $stats['max']['max']) {
$stats['max']['max'] = $item['max'];
}
}
//Count elements
$count++;
//Get last data
if ($count == $size) {
if (isset($item['sum']) && $item['sum']) {
$stats['sum']['last'] = $item['sum'];
}
if (isset($item['min']) && $item['min']) {
$stats['min']['last'] = $item['min'];
}
if (isset($item['max']) && $item['max']) {
$stats['max']['last'] = $item['max'];
}
}
}
//End the calculus for average
if ($count > 0) {
$stats['sum']['avg'] = $stats['sum']['avg'] / $count;
$stats['min']['avg'] = $stats['min']['avg'] / $count;
$stats['max']['avg'] = $stats['max']['avg'] / $count;
}
//Format stat data to display properly
$stats['sum']['last'] = round($stats['sum']['last'], 2);
$stats['sum']['avg'] = round($stats['sum']['avg'], 2);
$stats['sum']['min'] = round($stats['sum']['min'], 2);
$stats['sum']['max'] = round($stats['sum']['max'], 2);
$stats['min']['last'] = round($stats['min']['last'], 2);
$stats['min']['avg'] = round($stats['min']['avg'], 2);
$stats['min']['min'] = round($stats['min']['min'], 2);
$stats['min']['max'] = round($stats['min']['max'], 2);
$stats['max']['last'] = round($stats['max']['last'], 2);
$stats['max']['avg'] = round($stats['max']['avg'], 2);
$stats['max']['min'] = round($stats['max']['min'], 2);
$stats['max']['max'] = round($stats['max']['max'], 2);
return $stats;
}
function grafico_modulo_sparse_data_chart (
$agent_module_id,
$date_array,
@ -2471,6 +2267,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
// Fix: tag filters implemented! for tag functionality groups have to be all user_groups (propagate ACL funct!)
$groups = users_get_groups($config["id_user"]);
$tags_condition = tags_get_acl_tags($config['id_user'], array_keys($groups), 'ER', 'event_condition', 'AND');
$data = array ();
@ -2623,382 +2420,6 @@ function graph_sla_slicebar ($id, $period, $sla_min, $sla_max, $date, $daysWeek
$config['fontpath'], $round_corner, $home_url, $ttl);
}
/**
* Print a pie graph with purge data of agent
*
* @param integer id_agent ID of agent to show
* @param integer width pie graph width
* @param integer height pie graph height
*/
function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) {
global $config;
global $graphic_type;
$filter = array();
if ($id_agent < 1) {
$query = "";
}
else {
$modules = agents_get_modules($id_agent);
$module_ids = array_keys($modules);
if (!empty($module_ids))
$filter['id_agente_modulo'] = $module_ids;
}
// All data (now)
$time_now = time();
// 1 day ago
$time_1day = $time_now - SECONDS_1DAY;
// 1 week ago
$time_1week = $time_now - SECONDS_1WEEK;
// 1 month ago
$time_1month = $time_now - SECONDS_1MONTH;
// Three months ago
$time_3months = $time_now - SECONDS_3MONTHS;
$query_error = false;
// Data from 1 day ago
$num_1day = 0;
$num_1day += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_1day);
$num_1day += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_string
WHERE utimestamp > ' . $time_1day);
$num_1day += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_log4x
WHERE utimestamp > ' . $time_1day);
if ($num_1day >= 0) {
// Data from 1 week ago
$num_1week = 0;
$num_1week += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_1week . '
AND utimestamp < ' . $time_1day);
$num_1week += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_string
WHERE utimestamp > ' . $time_1week . '
AND utimestamp < ' . $time_1day);
$num_1week += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_log4x
WHERE utimestamp > ' . $time_1week . '
AND utimestamp < ' . $time_1day);
if ($num_1week >= 0) {
if ($num_1week > 0) {
$num_1week = 0;
$num_1week += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_1week);
$num_1week += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_string
WHERE utimestamp > ' . $time_1week);
$num_1week += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_log4x
WHERE utimestamp > ' . $time_1week);
}
// Data from 1 month ago
$num_1month = 0;
$num_1month += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_1month . '
AND utimestamp < ' . $time_1week);
$num_1month += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_string
WHERE utimestamp > ' . $time_1month . '
AND utimestamp < ' . $time_1week);
$num_1month += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_log4x
WHERE utimestamp > ' . $time_1month . '
AND utimestamp < ' . $time_1week);
if ($num_1month >= 0) {
if ($num_1month > 0) {
$num_1month = 0;
$num_1month += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_1month);
$num_1month += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_string
WHERE utimestamp > ' . $time_1month);
$num_1month += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos_log4x
WHERE utimestamp > ' . $time_1month);
}
// Data from 3 months ago
$num_3months = 0;
$num_3months += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_3months . '
AND utimestamp < ' . $time_1month);
$num_3months += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_3months . '
AND utimestamp < ' . $time_1month);
$num_3months += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_3months . '
AND utimestamp < ' . $time_1month);
if ($num_3months >= 0) {
if ($num_3months > 0) {
$num_3months = 0;
$num_3months += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_3months);
$num_3months += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_3months);
$num_3months += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp > ' . $time_3months);
}
// All data
$num_all = 0;
$num_all += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp < ' . $time_3months);
$num_all += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp < ' . $time_3months);
$num_all += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp < ' . $time_3months);
if ($num_all >= 0) {
$num_older = $num_all - $num_3months;
if ($config['history_db_enabled'] == 1) {
// All data in common and history database
$num_all_w_history = 0;
$num_all_w_history += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp < ' . $time_3months);
$num_all_w_history += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp < ' . $time_3months);
$num_all_w_history += (int) db_get_sql('SELECT COUNT(*)
FROM tagente_datos
WHERE utimestamp < ' . $time_3months);
if ($num_all_w_history >= 0) {
$num_history = $num_all_w_history - $num_all;
}
}
}
}
}
}
}
else if (($num_1day == 0) && ($num_1week == 0) && ($num_1month == 0) && ($num_3months == 0) && ($num_all == 0)) {
//If no data, returns empty
$query_error = true;
}
// Error
if ($query_error || $num_older < 0 || ($config['history_db_enabled'] == 1 && $num_history < 0)
|| (empty($num_1day) && empty($num_1week) && empty($num_1month)
&& empty($num_3months) && empty($num_all)
&& ($config['history_db_enabled'] == 1 && empty($num_all_w_history)))) {
return html_print_image('images/image_problem_area_small.png', true);
}
// Data indexes
$str_1day = __("Today");
$str_1week = "1 ".__("Week");
$str_1month = "1 ".__("Month");
$str_3months = "3 ".__("Months");
$str_older = "> 3 ".__("Months");
// Filling the data array
$data = array();
if (!empty($num_1day))
$data[$str_1day] = $num_1day;
if (!empty($num_1week))
$data[$str_1week] = $num_1week;
if (!empty($num_1month))
$data[$str_1month] = $num_1month;
if (!empty($num_3months))
$data[$str_3months] = $num_3months;
if (!empty($num_older))
$data[$str_older] = $num_older;
if ($config['history_db_enabled'] == 1 && !empty($num_history)) {
// In this pie chart only 5 elements are shown, so we need to remove
// an element. With a history db enabled the >3 months element are dispensable
if (count($data) >= 5 && isset($data[$str_3months]))
unset($data[$str_3months]);
$time_historic_db = time() - ((int)$config['history_db_days'] * SECONDS_1DAY);
$date_human = human_time_comparation($time_historic_db);
$str_history = "> $date_human (".__("History db").")";
$data[$str_history] = $num_history;
}
$water_mark = array(
'file' => $config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)
);
return pie3d_graph($config['flash_charts'], $data, $width, $height,
__('Other'), '', $water_mark, $config['fontpath'], $config['font_size']);
}
/**
* Print a horizontal bar graph with packets data of agents
*
* @param integer width pie graph width
* @param integer height pie graph height
*/
function grafico_db_agentes_paquetes($width = 380, $height = 300) {
global $config;
global $graphic_type;
$data = array ();
$legend = array ();
$agents = agents_get_group_agents (array_keys (users_get_groups (false, 'RR')), false, "none");
$count = agents_get_modules_data_count (array_keys ($agents));
unset ($count["total"]);
arsort ($count, SORT_NUMERIC);
$count = array_slice ($count, 0, 8, true);
foreach ($count as $agent_id => $value) {
$data[$agents[$agent_id]]['g'] = $value;
}
if($config["fixed_graph"] == false){
$water_mark = array('file' =>
$config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
}
return hbar_graph($config['flash_charts'], $data, $width, $height, array(),
$legend, "", "", true, "", $water_mark,
$config['fontpath'], $config['font_size'], false, 1, $config['homeurl'],
'white',
'black');
}
/**
* Print a horizontal bar graph with modules data of agents
*
* @param integer height graph height
* @param integer width graph width
*/
function graph_db_agentes_modulos($width, $height) {
global $config;
global $graphic_type;
$data = array ();
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
$modules = db_get_all_rows_sql ('
SELECT COUNT(id_agente_modulo), id_agente
FROM tagente_modulo
WHERE delete_pending = 0
GROUP BY id_agente
ORDER BY 1 DESC LIMIT 10');
break;
case "oracle":
$modules = db_get_all_rows_sql ('
SELECT COUNT(id_agente_modulo), id_agente
FROM tagente_modulo
WHERE rownum <= 10
AND delete_pending = 0
GROUP BY id_agente
ORDER BY 1 DESC');
break;
}
if ($modules === false)
$modules = array ();
$data = array();
foreach ($modules as $module) {
$agent_name = agents_get_name ($module['id_agente'], "none");
if (empty($agent_name)) {
continue;
}
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
$data[$agent_name]['g'] = $module['COUNT(id_agente_modulo)'];
break;
case "oracle":
$data[$agent_name]['g'] = $module['count(id_agente_modulo)'];
break;
}
}
if($config["fixed_graph"] == false){
$water_mark = array('file' =>
$config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
}
return hbar_graph($config['flash_charts'],
$data, $width, $height, array(),
array(), "", "", true, "",
$water_mark,
$config['fontpath'], $config['font_size'], false, 1, $config['homeurl'],
'white',
'black');
}
/**
* Print a pie graph with users activity in a period of time
*
* @param integer width pie graph width
* @param integer height pie graph height
* @param integer period time period
*/
function graphic_user_activity ($width = 350, $height = 230) {
global $config;
global $graphic_type;
$data = array ();
$max_items = 5;
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
$sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario
FROM tsesion
GROUP BY id_usuario
ORDER BY 1 DESC LIMIT %d', $max_items);
break;
case "oracle":
$sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario
FROM tsesion
WHERE rownum <= %d
GROUP BY id_usuario
ORDER BY 1 DESC', $max_items);
break;
}
$logins = db_get_all_rows_sql ($sql);
if ($logins == false) {
$logins = array();
}
foreach ($logins as $login) {
$data[$login['id_usuario']] = $login['n_incidents'];
}
if($config["fixed_graph"] == false){
$water_mark = array('file' =>
$config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
}
return pie3d_graph($config['flash_charts'], $data, $width, $height,
__('Other'), '', $water_mark,
$config['fontpath'], $config['font_size']);
}
/**
* Print a pie graph with priodity incident
*/
@ -3425,70 +2846,6 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
$config['fontpath'], $config['font_size'], 1, 'bottom');
}
function grafico_eventos_agente ($width = 300, $height = 200, $result = false, $meta = false, $history = false) {
global $config;
global $graphic_type;
//It was urlencoded, so we urldecode it
//$url = html_entity_decode (rawurldecode ($url), ENT_QUOTES);
$data = array ();
$loop = 0;
if ($result === false) {
$result = array();
}
$system_events = 0;
$other_events = 0;
$total = array();
$i = 0;
foreach ($result as $row) {
if ($meta) {
$count[] = $row["agent_name"];
}
else {
if ($row["id_agente"] == 0) {
$count[] = __('SYSTEM');
}
else
$count[] = agents_get_alias($row["id_agente"]) ;
}
}
$total = array_count_values($count);
foreach ($total as $key => $total) {
if ($meta) {
$name = $key." (".$total.")";
}
else {
$name = $key." (".$total.")";
}
$data[$name] = $total;
}
/*
if ($other_events > 0) {
$name = __('Other')." (".$other_events.")";
$data[$name] = $other_events;
}
*/
// Sort the data
arsort($data);
if($config["fixed_graph"] == false){
$water_mark = array('file' =>
$config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
}
return pie3d_graph($config['flash_charts'], $data, $width, $height,
__('Others'), '', $water_mark,
$config['fontpath'], $config['font_size'], 1, 'bottom');
}
/**
* Print a pie graph with events data in 320x200 size
*
@ -3514,8 +2871,11 @@ function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWat
}
$sql = sprintf("SELECT criticity, COUNT(id_evento) events
FROM tevento %s
GROUP BY criticity ORDER BY events DESC", $where);
FROM tevento
LEFT JOIN tagent_secondary_group tasg
ON tevento.id_agente = tasg.id_agent
%s %s
GROUP BY criticity ORDER BY events DESC", $where , $filter);
$criticities = db_get_all_rows_sql ($sql, false, false);
@ -4824,12 +4184,11 @@ function graph_monitor_wheel ($width = 550, $height = 600, $filter = false) {
if (!empty($agents)) {
$agents_id = array();
$agents_aux = array();
foreach ($agents as $key => $agent) {
foreach ($agents as $key => $agent) {
$agents_aux[$agent['id_agente']] = $agent;
}
$agents = $agents_aux;
$agents_aux = null;
$fields = array('id_agente_modulo', 'id_agente', 'id_module_group', 'nombre');
$module_groups = modules_get_modulegroups();
$module_groups[0] = __('Not assigned');

View File

@ -142,14 +142,12 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent
if ($forced_name !== false)
$module['nombre'] = $forced_name;
$modules = agents_get_modules ($id_destiny_agent, false,
array ('nombre' => $module['nombre'], 'disabled' => false));
// The module already exist in the target
if (! empty ($modules))
return array_pop (array_keys ($modules));
$modulesDisabled = agents_get_modules ($id_destiny_agent, false,
array ('nombre' => $module['nombre'], 'disabled' => true));
@ -2782,33 +2780,38 @@ function modules_get_counter_by_states($state) {
return false;
}
function modules_get_state_condition($state) {
function modules_get_state_condition($state, $prefix = "tae") {
switch ($state) {
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_BAD:
return "(
tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD."
$prefix.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT."
OR $prefix.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD."
)";
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_WARNING:
return "(
tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_WARNING."
$prefix.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
OR $prefix.estado = ".AGENT_MODULE_STATUS_WARNING."
)";
case AGENT_MODULE_STATUS_UNKNOWN:
return "tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
return "$prefix.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
case AGENT_MODULE_STATUS_NO_DATA:
case AGENT_MODULE_STATUS_NOT_INIT:
return "(
tae.estado = ".AGENT_MODULE_STATUS_NO_DATA."
OR tae.estado = ".AGENT_MODULE_STATUS_NOT_INIT."
$prefix.estado = ".AGENT_MODULE_STATUS_NO_DATA."
OR $prefix.estado = ".AGENT_MODULE_STATUS_NOT_INIT."
)";
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL:
return "(
tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL."
$prefix.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
OR $prefix.estado = ".AGENT_MODULE_STATUS_NORMAL."
)";
case AGENT_MODULE_STATUS_NOT_NORMAL:
return "(
$prefix.estado <> " . AGENT_MODULE_STATUS_NORMAL . "
AND $prefix.estado <> " . AGENT_MODULE_STATUS_NORMAL_ALERT . "
)";
}
// If the state is not an expected state, return no condition

View File

@ -256,7 +256,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$relative = false, $text_filter = '', $ip_mask = null,
$dont_show_subgroups = false, $strict_user = false, $size_canvas = null,
$old_mode = false, $map_filter = array()) {
global $config;
$nooverlap = 1;
@ -267,17 +267,8 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$filter['disabled'] = 0;
if (!empty($text_filter)) {
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
$filter[] =
'(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
break;
case "oracle":
$filter[] =
'(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
break;
}
$filter[] =
'(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
}
if ($group >= 1) {
@ -301,33 +292,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
//foreach loop are without parent (id_parent = 0)
// Get agents data
if ($strict_user) {
if ($dont_show_subgroups)
$filter['id_group'] = $group;
else {
if (!empty($childrens)) {
foreach ($childrens as $children) {
$filter_id_groups[$children] = $children;
}
}
$filter_id_groups[$group] = $group;
$filter['id_group'] = implode(',', $filter_id_groups);
}
$filter['group_by'] = 'tagente.id_agente';
$fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente,
tagente.normal_count, tagente.warning_count, tagente.critical_count,
tagente.unknown_count, tagente.total_count, tagente.notinit_count');
$acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
$agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
}
else {
$agents = agents_get_agents ($filter,
array ('id_grupo, nombre, id_os, id_parent, id_agente,
normal_count, warning_count, critical_count,
unknown_count, total_count, notinit_count'), 'AR',
array('field' => 'id_parent', 'order' => 'ASC'));
}
$agents = agents_get_agents ($filter,
array ('id_grupo, nombre, id_os, id_parent, id_agente,
normal_count, warning_count, critical_count,
unknown_count, total_count, notinit_count'), 'AR',
array('field' => 'id_parent', 'order' => 'ASC'));
}
else if ($group == -666) {
$agents = false;
@ -339,21 +308,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
unknown_count, total_count, notinit_count'), $strict_user);
}
else {
if ($strict_user) {
$filter['group_by'] = 'tagente.id_agente';
$fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente,
tagente.normal_count, tagente.warning_count, tagente.critical_count,
tagente.unknown_count, tagente.total_count, tagente.notinit_count');
$acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
$agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
}
else {
$agents = agents_get_agents ($filter,
array ('id_grupo, nombre, id_os, id_parent, id_agente,
normal_count, warning_count, critical_count,
unknown_count, total_count, notinit_count'), 'AR',
array('field' => 'id_parent', 'order' => 'ASC'));
}
$agents = agents_get_agents ($filter,
array ('id_grupo, nombre, id_os, id_parent, id_agente,
normal_count, warning_count, critical_count,
unknown_count, total_count, notinit_count'), 'AR',
array('field' => 'id_parent', 'order' => 'ASC'));
}
if ($agents === false)
@ -386,15 +345,10 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$filter = array();
$filter['disabled'] = 0;
// Get agent modules data
if ($strict_user) {
$modules = tags_get_agent_modules ($agent['id_agente'], false, $acltags, false, $filter, false);
}
else {
$modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true);
}
$modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true);
if ($modules === false)
$modules = array();
@ -615,264 +569,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
return $graph;
}
// Generate a dot graph definition for graphviz with groups
function networkmap_generate_dot_groups ($pandora_name, $group = 0,
$simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0,
$zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0,
$modwithalerts = 0, $module_group = 0, $hidepolicymodules = 0,
$depth = 'all', $id_networkmap = 0, $dont_show_subgroups = 0,
$text_filter = '', $strict_user = false, $size_canvas = null) {
global $config;
if ($strict_user) {
$acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
}
$parents = array();
$orphans = array();
$filter = array ();
$filter['disabled'] = 0;
if (!empty($text_filter)) {
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
$filter[] =
'(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")';
break;
case "oracle":
$filter[] =
'(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
break;
}
}
// Get groups data
if ($group > 0) {
$groups = array();
$id_groups = groups_get_id_recursive($group, true);
foreach($id_groups as $id_group) {
$add = false;
if (check_acl($config["id_user"], $id_group, 'AR')) {
$add = true;
}
if ($add) {
$groups[] = db_get_row ('tgrupo', 'id_grupo', $id_group);
}
}
$filter['id_grupo'] = $id_groups;
}
else {
if ($strict_user) {
$groups = users_get_groups ($config['id_user'],"AR", false, true);
}
else {
$groups = db_get_all_rows_in_table ('tgrupo');
}
if ($groups === false) {
$groups = array();
}
}
// Open Graph
$graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
$ranksep, $font_size, $size_canvas);
$node_count = 0;
// Parse groups
$nodes = array ();
$nodes_groups = array();
foreach ($groups as $group2) {
$node_count ++;
$group2['type'] = 'group';
$group2['id_node'] = $node_count;
// Add node
$nodes_groups[$group2['id_grupo']] = $group2;
}
$node_count = 0;
$groups_hiden = array();
foreach ($nodes_groups as $node_group) {
$node_count++;
// Save node parent information to define edges later
if ($node_group['parent'] != "0" && $node_group['id_grupo'] != $group) {
if ((!$dont_show_subgroups) || ($group == 0)) {
$parents[$node_count] = $nodes_groups[$node_group['parent']]['id_node'];
}
else {
$groups_hiden[$node_group['id_grupo']] = 1;
continue;
}
}
else {
$orphans[$node_count] = 1;
}
$nodes[$node_count] = $node_group;
}
if ($depth != 'group') {
if ($strict_user) {
$filter['group_by'] = 'tagente.nombre';
$filter['id_group'] = $filter['id_grupo'];
$fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_agente,
tagente.normal_count, tagente.warning_count, tagente.critical_count,
tagente.unknown_count, tagente.total_count, tagente.notinit_count');
$agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
unset($filter['id_group']);
}
else {
// Get agents data
$agents = agents_get_agents ($filter,
array ('id_grupo, nombre, id_os, id_agente,
normal_count, warning_count, critical_count,
unknown_count, total_count, notinit_count'));
}
if ($agents === false)
$agents = array();
// Parse agents
$nodes_agents = array();
foreach ($agents as $agent) {
if ($dont_show_subgroups) {
if (!empty($groups_hiden[$agent['id_grupo']])) {
continue;
}
}
// If only agents with alerts => agents without alerts discarded
$alert_agent = agents_get_alerts($agent['id_agente']);
if ($modwithalerts and empty($alert_agent['simple'])) {
continue;
}
$node_count ++;
// Save node parent information to define edges later
$parents[$node_count] = $agent['parent'] = $nodes_groups[$agent['id_grupo']]['id_node'];
$agent['id_node'] = $node_count;
$agent['type'] = 'agent';
// Add node
$nodes[$node_count] = $nodes_agents[$agent['id_agente']] = $agent;
if ($depth == 'agent') {
continue;
}
// Get agent modules data
if ($strict_user) {
$filter['disabled'] = 0;
$modules = tags_get_agent_modules ($agent['id_agente'], false, $acltags, false, $filter, false);
} else {
$modules = agents_get_modules ($agent['id_agente'], false, array('disabled' => 0), true, false);
}
// Parse modules
foreach ($modules as $key => $module) {
$node_count ++;
$agent_module = modules_get_agentmodule($key);
$alerts_module = db_get_sql('SELECT count(*) AS num
FROM talert_template_modules
WHERE id_agent_module = ' . $key);
if ($alerts_module == 0 && $modwithalerts) {
continue;
}
if ($agent_module['id_module_group'] != $module_group &&
$module_group != 0) {
continue;
}
if ($hidepolicymodules && $config['enterprise_installed']) {
enterprise_include_once('include/functions_policies.php');
if (policies_is_module_in_policy($key)) {
continue;
}
}
// Save node parent information to define edges later
$parents[$node_count] = $agent_module['parent'] = $agent['id_node'];
$agent_module['id_node'] = $node_count;
$agent_module['type'] = 'module';
// Add node
$nodes[$node_count] = $agent_module;
}
}
}
if (empty ($nodes)) {
return false;
}
// Create void statistics array
$stats = array();
// Create nodes
foreach ($nodes as $node_id => $node) {
if ($center > 0 && ! networkmap_is_descendant ($node_id, $center, $parents)) {
unset ($parents[$node_id]);
unset ($orphans[$node_id]);
unset ($nodes[$node_id]);
continue;
}
switch ($node['type']) {
case 'group':
$graph .= networkmap_create_group_node ($node , $simple, $font_size, $metaconsole = false, null, $strict_user) .
"\n\t\t";
$stats['groups'][] = $node['id_grupo'];
break;
case 'agent':
$graph .= networkmap_create_agent_node ($node , $simple, $font_size, true, true) .
"\n\t\t";
$stats['agents'][] = $node['id_agente'];
break;
case 'module':
$graph .= networkmap_create_module_node ($node , $simple, $font_size) .
"\n\t\t";
$stats['modules'][] = $node['id_agente_modulo'];
break;
}
}
// Define edges
foreach ($parents as $node => $parent_id) {
// Verify that the parent is in the graph
if (isset ($nodes[$parent_id])) {
$graph .= networkmap_create_edge ($node, $parent_id, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap);
}
else {
$orphans[$node] = 1;
}
}
// Create a central node if orphan nodes exist
if (count ($orphans)) {
$graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats);
}
// Define edges for orphan nodes
foreach (array_keys($orphans) as $node) {
$graph .= networkmap_create_edge ('0', $node, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap);
}
// Close graph
$graph .= networkmap_close_graph ();
return $graph;
}
// Returns an edge definition
function networkmap_create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, $sec2 = 'operation/agentes/networkmap', $tab = 'topology', $id_networkmap = 0) {
if (defined("METACONSOLE")) {

View File

@ -1800,7 +1800,6 @@ function reporting_agent_module($report, $content) {
$row = array();
$row['agent_status'][$agent] = agents_get_status($agent);
$row['agent_name'] = agents_get_alias($agent);
$agent_modules = agents_get_modules($agent);
$row['modules'] = array();
@ -3079,7 +3078,6 @@ function reporting_alert_report_agent($report, $content) {
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$module_list = agents_get_modules($content['id_agent']);
$data = array();
@ -3669,7 +3667,6 @@ function reporting_agent_configuration($report, $content) {
$agent_configuration['description'] = $agent_data['comentarios'];
$agent_configuration['enabled'] = (int)!$agent_data['disabled'];
$agent_configuration['group'] = $report["group"];
$modules = agents_get_modules ($content['id_agent']);
$agent_configuration['modules'] = array();
@ -8293,11 +8290,10 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0
* Get a detailed report of the modules of the agent
*
* @param int $id_agent Agent id to get the report for.
* @param string $filter filter for get partial modules.
*
* @return array An array
*/
function reporting_get_agent_module_info ($id_agent, $filter = false) {
function reporting_get_agent_module_info ($id_agent) {
global $config;
$return = array ();
@ -8313,12 +8309,7 @@ function reporting_get_agent_module_info ($id_agent, $filter = false) {
return $return;
}
if ($filter != '') {
$filter = 'AND ';
}
$filter = 'disabled = 0';
$filter = array('disabled' => 0);
$modules = agents_get_modules($id_agent, false, $filter, true, false);
if ($modules === false) {
@ -8416,33 +8407,6 @@ function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $
break;
}
if ($strict_user && $type == 'agent') {
$acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user);
$filter['disabled'] = 0;
$id_agent = $counts_info['id_agente'];
$counts_info = array();
$counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL));
$counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING));
$counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD));
$counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT));
$counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN));
$counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count'];
$all_agent_modules = tags_get_agent_modules ($id_agent, false, $acltags, false, $filter);
if (!empty($all_agent_modules)) {
$mod_clause = "(".implode(',', array_keys($all_agent_modules)).")";
$counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired)
FROM talert_template_modules
WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause);
}
else {
$counts_info['fired_count'] = 0;
}
}
// Store the counts in a data structure to print hidden divs with titles
$stats = array();

View File

@ -192,11 +192,13 @@ function tags_get_modules_count ($id) {
* @return int Local module tag's count.
*/
function tags_get_local_modules_count ($id) {
$field = 'COUNT(id_tag)';
$field = 'COUNT(DISTINCT(tagente_modulo.id_agente_modulo))';
$filter = array('id_tag' => $id);
$num_modules = (int) db_get_value_filter($field, 'ttag_module', $filter);
$num_modules = (int) db_get_value_filter(
$field,
'ttag_module INNER JOIN tagente_modulo ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo',
$filter
);
return $num_modules;
}
@ -457,7 +459,7 @@ function tags_get_module_tags ($id, $policy = false) {
$tags = db_get_all_rows_filter('ttag_module',
array('id_agente_modulo' => $id), false);
}
if ($tags === false)
return array();
@ -722,124 +724,37 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
$condition = '';
$group_conditions = array();
$without_tags = array();
$has_secondary = enterprise_hook('agents_is_using_secondary_groups');
// The acltags array contains the groups with the acl propagation applied
// after the changes done into the 'tags_get_user_groups_and_tags' function.
foreach ($acltags as $group_id => $group_tags) {
$tag_join = '';
if (!empty($group_tags)) {
$tag_join = sprintf('INNER JOIN ttag_module ttmc
ON tamc.id_agente_modulo = ttmc.id_agente_modulo
AND ttmc.id_tag IN (%s)',
is_array($group_tags) ? implode(',', $group_tags) : $group_tags);
$tag_join = sprintf('AND ttag_module.id_tag IN (%s)',is_array($group_tags) ? implode(',', $group_tags) : $group_tags);
if($has_secondary){
$agent_condition = sprintf('((tagente.id_grupo = %d OR tasg.id_group = %d) %s)',$group_id,$group_id,$tag_join);
} else {
$agent_condition = sprintf('((tagente.id_grupo = %d %s))',$group_id,$tag_join);
}
$group_conditions[] = $agent_condition;
} else {
$without_tags[] = $group_id;
}
// FIXME: Not properly way to increse performance
if(enterprise_hook('agents_is_using_secondary_groups')){
$agent_condition = sprintf('SELECT tamc.id_agente_modulo
FROM tagente_modulo tamc
%s
INNER JOIN tagente tac
ON tamc.id_agente = tac.id_agente
LEFT JOIN tagent_secondary_group tasg
ON tasg.id_agent = tac.id_agente
WHERE (tac.id_grupo = %d OR tasg.id_group = %d)',
$tag_join, $group_id, $group_id);
}
else{
$agent_condition = sprintf('SELECT tamc.id_agente_modulo
FROM tagente_modulo tamc
%s
INNER JOIN tagente tac
ON tamc.id_agente = tac.id_agente
AND tac.id_grupo = %d',
$tag_join, $group_id);
}
$sql_condition = sprintf('(%sid_agente_modulo IN (%s))', $modules_table, $agent_condition);
$group_conditions[] = $sql_condition;
$i++;
}
if (!empty($group_conditions))
if (!empty($group_conditions)) {
$condition = implode(' OR ', $group_conditions);
$condition = !empty($condition) ? "($condition)" : '';
return $condition;
}
// The old function will be keeped to serve as reference of the changes done
/**
* Transform the acl_groups data into a SQL condition
*
* @param mixed acl_groups data calculated in tags_get_acl_tags function
*
* @return string SQL condition for tagente_module
*/
function tags_get_acl_tags_module_condition_old($acltags, $modules_table = '') {
if (!empty($modules_table)) {
$modules_table .= '.';
}
$condition = '';
// Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression)
$i = 0;
foreach ($acltags as $group_id => $group_tags) {
if ($condition != '') {
if (!empty($without_tags)) {
if (!empty($condition)) {
$condition .= ' OR ';
}
// Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression)
if ($i == 0)
$condition .= ' ( ' . "\n";
// Group condition (The module belongs to an agent of the group X)
// Juanma (08/05/2014) Fix: Now group and tag is checked at the same time, before only tag was checked due to a bad condition
if (!array_key_exists(0, $acltags)) {
// Juanma (08/05/2014) Fix: get all groups recursively (Acl proc func!)
$group_condition = sprintf('%sid_agente IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s))', $modules_table, implode(',', array_values(groups_get_id_recursive($group_id))));
}
else {
//Avoid the user profiles with all group access.
$group_condition = " 1 = 1 ";
}
//When the acl is only group without tags
if (empty($group_tags)) {
$condition .= "($group_condition)\n";
}
else {
if (is_array($group_tags)) {
$group_tags_query = implode(',',$group_tags);
} else {
$group_tags_query = $group_tags;
}
// Tags condition (The module has at least one of the restricted tags)
$tags_condition = sprintf('%sid_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (%s))', $modules_table, $group_tags_query);
$condition .=
" ( \n" .
" $group_condition \n" .
" AND \n" .
" $tags_condition \n" .
" )\n";
}
$i++;
}
// Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression)
if (!empty($acltags))
$condition .= ' ) ';
//Avoid the user profiles with all group access.
//if (!empty($condition)) {
if (!empty($condition) &&
!array_key_exists(0, array_keys($acltags))) {
$condition = sprintf("\n((%s) OR %sid_agente NOT IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s)))", $condition, $modules_table, implode(',',array_keys($acltags)));
$in_group = implode(",",$without_tags);
$condition .= sprintf('(tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))',$in_group,$in_group);
}
$condition = !empty($condition) ? "($condition)" : '';
return $condition;
}
@ -859,102 +774,54 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group
// Get all tags of the system
$all_tags = tags_get_all_tags(false);
// Juanma (08/05/2014) Fix : Will have all groups retrieved (also propagated ones)
$_groups_not_in = '';
$without_tags = array();
foreach ($acltags as $group_id => $group_tags) {
// Group condition (The module belongs to an agent of the group X)
$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
//$_groups_not_in .= implode(',', array_values(groups_get_id_recursive($group_id))) . ',';
// Tags condition (The module has at least one of the restricted tags)
$tags_condition = '';
// NO check if there is not tag associated with groups
if (empty($group_tags)) {
// FIXME: Not properly way to increse performance
if(enterprise_hook('agents_is_using_secondary_groups')){
$tags_condition = "id_grupo = ".$group_id . " OR id_group = " . $group_id;
}
else{
$tags_condition = "id_grupo = ".$group_id;
}
}
else {
if (!is_array($group_tags)) {
$group_tags = explode(',', $group_tags);
}
foreach ($group_tags as $tag) {
// If the tag ID doesnt exist, ignore
if (!isset($all_tags[$tag])) {
continue;
}
if ($tags_condition != '') {
$tags_condition .= " OR \n";
}
//~ // Add as condition all the posibilities of the serialized tags
//~ $tags_condition .= sprintf('tags LIKE "%s,%%"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s,%%"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%s %%"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s %%"',io_safe_input($all_tags[$tag]));
if ($force_group_and_tag) {
if (!empty($all_tags[$tag])) {
if ($force_equal) {
$tags_condition .= sprintf('(tags = "%s"',io_safe_input($all_tags[$tag]));
} else {
$tags_condition .= "(tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
}
$childrens = groups_get_childrens($group_id, null, true);
if (empty($childrens)) {
$tags_condition .= sprintf(' AND id_grupo = %d )', $group_id);
} else {
$childrens_ids[] = $group_id;
foreach ($childrens as $child) {
$childrens_ids[] = (int)$child['id_grupo'];
}
$ids_str = implode(',', $childrens_ids);
$tags_condition .= sprintf(' AND id_grupo IN (%s) )', $ids_str);
}
} else {
$tags_condition .= "id_grupo = ".$group_id;
}
} else {
if ($force_equal) {
$tags_condition .= sprintf('tags = "%s"',io_safe_input($all_tags[$tag]));
} else {
$tags_condition .= "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
}
}
}
}
// If there is not tag condition ignore
if (empty($tags_condition)) {
$without_tags []= $group_id;
continue;
}
if ($condition != '') {
$condition .= ' OR ';
// Group condition (The module belongs to an agent of the group X)
//$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
$group_condition = "(id_grupo = $group_id OR id_group = $group_id)";
// Tags condition (The module has at least one of the restricted tags)
$tags_condition = '';
$tags_condition_array = array();
foreach ($group_tags as $tag) {
// If the tag ID doesnt exist, ignore
if (!isset($all_tags[$tag])) continue;
$tags_condition_array[] = $force_equal
? sprintf('tags = "%s"',io_safe_input($all_tags[$tag]))
: "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
}
$condition .= "($tags_condition)\n";
// If there is not tag currently in Pandora, block the group info
if (empty($tags_condition_array)) {
$tags_condition_array[] = "1=0";
}
$tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")";
$condition[] = "($tags_condition)\n";
}
//Commented because ACLs propagation don't work
/*
if (!empty($condition)) {
// Juanma (08/05/2014) Fix : Also add events of other groups (taking care of propagate ACLs func!)
if (!empty($_groups_not_in))
$condition = sprintf("\n((%s) OR id_grupo NOT IN (%s))", $condition, rtrim($_groups_not_in, ','));
$condition = implode(' OR ', $condition);
}
*/
if (!empty($without_tags)) {
if (!empty($condition)) {
$condition .= ' OR ';
}
$in_group = implode(",",$without_tags);
$condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group);
}
$condition = !empty($condition) ? "($condition)" : '';
return $condition;
}
@ -975,15 +842,14 @@ function tags_has_user_acl_tags($id_user = false) {
if(is_user_admin($id_user)) {
return false;
}
$query = sprintf("SELECT count(*)
FROM tusuario_perfil, tperfil
WHERE tperfil.id_perfil = tusuario_perfil.id_perfil AND
tusuario_perfil.id_usuario = '%s' AND tags != ''",
$id_user);
$query = "SELECT count(*)
FROM tusuario_perfil
WHERE tusuario_perfil.id_usuario = '$id_user'
AND tags != '' AND tags !='0'";
$user_tags = db_get_value_sql($query);
return (bool)$user_tags;
}
@ -1150,7 +1016,7 @@ function tags_get_tags_for_module_search($id_user = false, $access = 'AR') {
//--------------------------------------------------------------
return false;
}
// Get the tags of the required access flag for each group
// Get the tags of the required access flag for each group
$tags = tags_get_acl_tags($id_user, 0, $access, 'data');
// If there are wrong parameters or fail ACL check, return false
if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) {
@ -1186,252 +1052,27 @@ function tags_check_acl_by_module($id_module = 0, $id_user = false,
$access = 'AW') {
global $config;
$return = false;
if (!empty($id_module)) {
$tags = tags_get_module_tags($id_module);
$groups = modules_get_agent_groups($id_module);
if ($id_user === false) {
$id_user = $config["id_user"];
}
foreach ($groups as $group) {
if (tags_check_acl($id_user, $group, $access, $tags, true)) {
return true;
}
}
}
return $return;
}
/**
* Check the ACLs with tags
*
* @param string ID of the user (with false the user will be taked from config)
* @param string id of the group (0 means for at least one)
* @param string access flag (AR,AW...)
* @param mixed tags to be checked (array() means for at least one)
*
* @return bool true if the acl check has success, false otherwise
*/
function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_tag = false) {
global $config;
if (empty($id_module)) return false;
if ($id_user === false) {
$id_user = $config['id_user'];
$id_user = $config["id_user"];
}
// Get parents to check in propagate ACL cases
if (!is_array($id_group) && $id_group != 0) {
$id_group = array($id_group);
$group = db_get_row_filter('tgrupo',
array('id_grupo' => $id_group));
$parents = groups_get_parents($group['parent'], true);
foreach ($parents as $parent) {
$id_group[] = $parent['id_grupo'];
}
}
$acls = tags_get_acl_tags($id_user, $id_group, $access, 'data');
// If there are wrong parameters or fail ACL check, return false
if ($acls === ERR_WRONG_PARAMETERS || $acls === ERR_ACL) {
return false;
}
// If there are not tags restrictions or tags passed, check the group access
if (empty($acls) || empty($tags)) {
if (!is_array($id_group))
$group_id_array = array($id_group);
foreach ($id_group as $group) {
if (check_acl($id_user, $group, $access))
return true;
}
}
# Fix: If user profile has more than one group, due to ACL propagation then id_group can be an array
if (is_array($id_group)) {
foreach ($id_group as $group) {
if ($group > 0) {
if (array_key_exists(0, $acls)) {
//There is a All group
foreach ($tags as $tag) {
if (in_array($tag, $acls[0])) {
return true;
}
else {
return false;
}
}
}
else if (isset($acls[$group])) {
foreach ($tags as $tag) {
if (!$flag_id_tag)
$tag = tags_get_id($tag);
if (in_array($tag, $acls[$group])) {
return true;
} else if (empty($acls[$group])) {
return true;
}
}
}
else {
return false;
}
}
else {
foreach ($acls as $acl_tags) {
foreach ($tags as $tag) {
if (!$flag_id_tag)
$tag = tags_get_id($tag);
if (in_array($tag, $acl_tags)) {
return true;
}
}
}
}
}
}
else {
if ($id_group > 0) {
if (isset($acls[$id_group])) {
foreach ($tags as $tag) {
if (!$flag_id_tag)
$tag = tags_get_id($tag);
if (in_array($tag, $acls[$id_group])) {
return true;
}
}
}
else {
return false;
}
}
else {
foreach ($acls as $acl_tags) {
foreach ($tags as $tag) {
if (!$flag_id_tag)
$tag = tags_get_id($tag);
if (in_array($tag, $acl_tags)) {
return true;
}
}
}
}
}
return false;
}
function tags_check_acl_event($id_user, $id_group, $access, $tags = array(),$p = false) {
global $config;
if($id_user === false) {
$id_user = $config['id_user'];
}
$acls = tags_get_acl_tags($id_user, $id_group, $access, 'data');
// If there are wrong parameters or fail ACL check, return false
if($acls === ERR_WRONG_PARAMETERS || $acls === ERR_ACL) {
return false;
}
// If there are not tags restrictions or tags passed, check the group access
if (empty($acls) || empty($tags)) {
if (!is_array($id_group))
$group_id_array = array($id_group);
foreach ($id_group as $group) {
if (check_acl($id_user, $group, $access))
return true;
}
}
# Fix: If user profile has more than one group, due to ACL propagation then id_group can be an array
if (is_array($id_group)) {
foreach ($id_group as $group) {
if ($group > 0) {
if (isset($acls[$group])) {
foreach ($tags as $tag) {
$tag = tags_get_id($tag);
if (in_array($tag, $acls[$group])) {
return true;
}
}
}
else {
//return false;
$return = false;
}
}
else {
foreach ($acls as $acl_tags) {
foreach ($tags as $tag) {
$tag = tags_get_id($tag);
if (in_array($tag, $acl_tags)) {
return true;
}
}
}
}
}
}
else {
if ($id_group > 0) {
if (isset($acls[$id_group])) {
foreach ($tags as $tag) {
$tag = tags_get_id($tag);
if (in_array($tag, $acls[$id_group])) {
return true;
}
}
}
else {
//return false;
$return = false;
}
}
else {
foreach ($acls as $acl_tags) {
foreach ($tags as $tag) {
$tag = tags_get_id($tag);
if (in_array($tag, $acl_tags)) {
return true;
}
}
}
}
}
//return false;
$return = false;
if ($return == false) {
$parent = db_get_value('parent','tgrupo','id_grupo',$id_group);
if ($parent !== 0) {
$propagate = db_get_value('propagate','tgrupo','id_grupo',$parent);
if ($propagate == 1) {
$acl_parent = tags_check_acl_event($id_user, $parent, $access, $tags,$p);
return $acl_parent;
}
}
$tags = tags_get_module_tags($id_module);
$groups = modules_get_agent_groups($id_module);
$user_groups = users_get_groups($id_user, $acces, false, true);
$acl_column = get_acl_column($access);
foreach ($groups as $group) {
// If user has not permission for this group,go to next group
if (!isset($user_groups[$group])) continue;
// No tags means user can see all tags for this group
if (!isset($user_groups[$group]["tags"][$acl_column])) return true;
// Check acl
$intersection = array_intersect($tags, $user_groups[$group]["tags"][$acl_column]);
if(!empty($intersection)) return true;
}
return false;
}
/* This function checks event ACLs */
@ -2446,7 +2087,9 @@ function tags_get_user_groups_and_tags ($id_user = false, $access = 'AR', $stric
$return = array();
foreach ($acls as $acl) {
$return[$acl["id_grupo"]] = $acl["tags"];
$return[$acl["id_grupo"]] = isset($acl["tags"][get_acl_column($access)])
? implode(",",$acl["tags"][get_acl_column($access)])
: "";
}
return $return;
@ -2701,4 +2344,41 @@ function tags_get_module_policy_tags($id_tag, $id_module) {
return $id_module_policy;
}
/**
* Get all tags configured to user associated to the agent.
*
* @param int $id_agent Agent to extract tags
* @param string $access Access to check
*
* @return mixed
* false if user has not permission on agent groups
* true if there is not any tag restriction
* array with all tags if there are tags configured
*/
function tags_get_user_applied_agent_tags ($id_agent, $access = "AR") {
global $config;
$agent_groups = agents_get_all_groups_agent($id_agent);
$user_groups = users_get_groups(false, 'AR', false, true);
// Check global agent permissions
if (!check_acl_one_of_groups($config['id_user'], $agent_groups, $access)) {
return false;
}
$acl_column = get_acl_column($access);
$tags = array();
foreach ($agent_groups as $group) {
// If user has not permission to a single group, continue
if (!isset($user_groups[$group])) continue;
$group_tags = $user_groups[$group]["tags"][$acl_column];
if (!empty($group_tags)) {
$tags = array_merge($tags, $group_tags);
} else {
// If an agent
return true;
}
}
return empty($tags) ? true : $tags;
}
?>

View File

@ -745,16 +745,7 @@ function treeview_printTable($id_agente, $server_data = array(), $no_head = fals
foreach ($network_interfaces as $interface_name => $interface) {
if (!empty($interface['traffic'])) {
$permission = false;
if ($strict_user) {
if (tags_check_acl_by_module($interface['traffic']['in'], $config['id_user'], 'RR') === true
&& tags_check_acl_by_module($interface['traffic']['out'], $config['id_user'], 'RR') === true)
$permission = true;
}
else {
$permission = check_acl($config['id_user'], $agent["id_grupo"], "RR");
}
$permission = check_acl($config['id_user'], $agent["id_grupo"], "RR");
if ($permission) {
$params = array(

View File

@ -208,23 +208,13 @@ function groups_combine_acl($acl_group_a, $acl_group_b){
"tags" => 1,
);
foreach ($acl_group_a['tags'] as $key => $value) {
$acl_group_b['tags'][$key] = array_merge($value, $acl_group_b['tags'][$key]);
}
foreach ($acl_list as $acl => $aux) {
if($acl == "tags") {
// Mix tags
if (isset($acl_group_a[$acl]) && ($acl_group_a[$acl] != "")) {
if (isset($acl_group_b[$acl]) && ($acl_group_b[$acl] != "")) {
if ($acl_group_b[$acl] != ($acl_group_a[$acl])) {
$acl_group_b[$acl] = $acl_group_a[$acl] . "," . $acl_group_b[$acl];
}
}
else {
$acl_group_b[$acl] = $acl_group_a[$acl];
}
}
continue;
}
if($acl == "tags") continue;
// propagate ACL
$acl_group_b[$acl] = $acl_group_a[$acl] || $acl_group_b[$acl];
}
@ -286,6 +276,8 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
foreach ($raw_forest as $g) {
// XXX, following code must be remade (TAG)
users_get_explode_tags($g);
if (!isset($forest_acl[$g["id_grupo"]] )) {
$forest_acl[$g["id_grupo"]] = $g;
}
@ -314,6 +306,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
}
else {
// add group to user ACL forest
users_get_explode_tags($group);
$tmp = groups_combine_acl($forest_acl[$parent], $group);
}
if ($tmp !== null) {
@ -1069,4 +1062,27 @@ function users_get_strict_mode_groups($id_user, $return_group_all) {
return $return_user_groups;
}
function users_get_explode_tags(&$group) {
if (empty($group['tags'])) {
$group['tags'] = array();
$group['tags']['agent_view'] = array();
$group['tags']['agent_edit'] = array();
$group['tags']['agent_disable'] = array();
$group['tags']['event_view'] = array();
$group['tags']['event_edit'] = array();
$group['tags']['event_management'] = array();
} else {
$aux = explode(',', $group['tags']);
$group['tags'] = array();
$group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array();
$group['tags']['agent_edit'] = ($group['agent_edit']) ? $aux : array();
$group['tags']['agent_disable'] = ($group['agent_disable']) ? $aux : array();
$group['tags']['event_view'] = ($group['event_view']) ? $aux : array();
$group['tags']['event_edit'] = ($group['event_edit']) ? $aux : array();
$group['tags']['event_management'] = ($group['event_management']) ? $aux : array();
}
}
?>

View File

@ -3958,26 +3958,6 @@ function get_status_module() {
});
}
function check_changes_num_modules() {
var params = [];
params.push("check_changes_num_modules=1");
params.push("id=" + id_agent);
params.push("page=operation/agentes/pandora_networkmap.view");
jQuery.ajax({
data: params.join("&"),
dataType: 'json',
type: 'POST',
url: action = "../../../ajax.php",
success: function (data) {
if (data['correct']) {
if (module_count != data['count']) {
//location.reload(true);
}
}
}
});
}
function show_networkmap_node(id_agent_param, refresh_state) {
id_agent = id_agent_param;

View File

@ -65,58 +65,6 @@ Array.prototype.in_array = function () {
return false;
};
/**
* Fill up select box with id "module" with modules after agent has been selected
*
* @param event that has been triggered
* @param id_agent Agent ID that has been selected
* @param selected Which module(s) have to be selected
*/
function agent_changed (event, id_agent, selected) {
if (id_agent == undefined)
id_agent = this.value;
$('#module').attr ('disabled', 1);
$('#module').empty ();
$('#module').append ($('<option></option>').html ("Loading...").attr ("value", 0));
jQuery.post ('ajax.php',
{"page": "operation/agentes/ver_agente",
"get_agent_modules_json": 1,
"id_agent": id_agent
},
function (data) {
$('#module').empty ();
if (typeof($(document).data('text_for_module')) != 'undefined') {
$('#module').append ($('<option></option>').html ($(document).data('text_for_module')).attr("value", 0).prop('selected', true));
}
else {
if (typeof(data['any_text']) != 'undefined') {
$('#module').append ($('<option></option>').html (data['any_text']).attr ("value", 0).prop('selected', true));
}
else {
var anyText = $("#any_text").html(); //Trick for catch the translate text.
if (anyText == null) {
anyText = 'Any';
}
$('#module').append ($('<option></option>').html (anyText).attr ("value", 0).prop('selected', true));
}
}
jQuery.each (data, function (i, val) {
s = js_html_entity_decode (val['nombre']);
$('#module').append ($('<option></option>').html (s).attr ("value", val['id_agente_modulo']));
$('#module').fadeIn ('normal');
});
if (selected != undefined)
$('#module').attr ('value', selected);
$('#module').removeAttr('disabled');
},
"json"
);
}
/**
* Util for check is empty object
*

View File

@ -540,7 +540,6 @@ function show_events_group_agent (id_insert, id_agent, server_id) {
data: parameter,
dataType: 'html',
success: function (data) {
console.log(data);
$("#"+id_insert).html(data);
$("#"+id_insert).toggle();
}

View File

@ -281,8 +281,7 @@ class Modules {
$modules = array();
$modules_db = array();
$sql_conditions_base = " WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo";
$sql_conditions_base = " WHERE 1=1";
// Part SQL for the id_agent
@ -400,7 +399,14 @@ class Modules {
$sql_total = "SELECT count(*)";
$sql = " FROM tagente, tagente_modulo, tagente_estado" .
$sql = " FROM tagente INNER JOIN tagente_modulo
ON tagente_modulo.id_agente = tagente.id_agente
INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
LEFT JOIN tagent_secondary_group tasg
ON tagente.id_agente = tasg.id_agent
LEFT JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo" .
$sql_conditions_all;
$sql_limit = "ORDER BY tagente.nombre ASC ";

View File

@ -273,7 +273,6 @@ $table_data->head_colspan[0] = 3;
$data = array();
$data[0] = '<b>' . __('Group') . '</b>';
$data[1] = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/estado_agente&amp;refr=60&amp;group_id='.$agent["id_grupo"].'">'.groups_get_name ($agent["id_grupo"]).'</a>';
// ACCESS RATE GRAPH
$access_agent = db_get_value_sql("SELECT COUNT(id_agent)
FROM tagent_access
@ -550,6 +549,7 @@ if (!empty($network_interfaces)) {
else {
$group_array = $user_groups_ids;
}
$acl_tags = tags_get_acl_tags($config['id_user'], $group_array, 'ER',
'event_condition', 'AND', '', true, array(), true);

View File

@ -138,17 +138,14 @@ echo "</h4>";
ob_start();
print_form_filter_monitors($id_agente, $status_filter_monitor, $status_text_monitor, $status_hierachy_mode);
echo "<div id='module_list_loading'>" .
html_print_image('images/spinner.gif', true) .
'</div>';
echo "<div id='module_list'>" .
"</div>";
$html_toggle = ob_get_clean();
ui_toggle($html_toggle,
__('List of modules'),

View File

@ -37,21 +37,8 @@ ui_print_page_header (__("Export data"), "images/server_export_mc.png");
$group = get_parameter_post ('group', 0);
$agentName = get_parameter_post ('agent', 0);
switch ($config["dbtype"]) {
case "mysql":
$agents = agents_get_agents(
array('nombre LIKE "' . $agentName . '"'), array ('id_agente'));
break;
case "postgresql":
$agents = agents_get_agents(
array('nombre LIKE \'' . $agentName . '\''), array ('id_agente'));
break;
case "oracle":
$agents = agents_get_agents(
array('nombre LIKE \'%' . $agentName . '%\''), array ('id_agente'));
break;
}
$agents = agents_get_agents(
array('nombre LIKE "' . $agentName . '"'), array ('id_agente'));
$agent = $agents[0]['id_agente'];
$module = (array) get_parameter_post ('module_arr', array ());

View File

@ -47,7 +47,6 @@ $option_type = get_parameter('option_type', 0);
// - others
//----------------------------------------------------------------------
$list_modules = array();
$modules_networkmap_no_proc = agents_get_modules(
$id_agente, false, array(
'id_modulo' => 2, // networkmap type
@ -62,7 +61,6 @@ $modules_networkmap_no_proc = agents_get_modules(
));
if (empty($modules_networkmap_no_proc))
$modules_networkmap_no_proc = array();
$modules_others = agents_get_modules(
$id_agente, false, array(
'id_tipo_modulo' => array(
@ -77,7 +75,6 @@ $modules_others = agents_get_modules(
if (empty($modules_others))
$modules_others = array();
$modules_boolean = agents_get_modules(
$id_agente, false, array(
'id_tipo_modulo' => array(

View File

@ -563,8 +563,6 @@ if (is_ajax ()) {
$get_status_node = (bool)get_parameter('get_status_node', false);
$get_status_module = (bool)get_parameter('get_status_module',
false);
$check_changes_num_modules = (bool)get_parameter(
'check_changes_num_modules', false);
if ($get_status_node) {
$id = (int)get_parameter('id', 0);
@ -593,20 +591,6 @@ if (is_ajax ()) {
return;
}
if ($check_changes_num_modules) {
$id = (int)get_parameter('id', 0);
$modules = agents_get_modules($id);
$return = array();
$return['correct'] = true;
$return['count'] = count($modules);
echo json_encode($return);
return;
}
if ($update_node_alert) {
$map_id = (int)get_parameter('map_id', 0);

View File

@ -87,16 +87,25 @@ if ($id_module) {
enterprise_hook('open_meta_frame');
// Get Groups and profiles from user
$user_groups = implode (',', array_keys (users_get_groups ()));
$user_groups = implode (',', array_keys (users_get_groups (false,'AR',false)));
////////////////////////////////////
// Begin Build SQL sentences
$sql_from = ' FROM ttipo_modulo,tagente LEFT JOIN tagent_secondary_group tasg ON tagente.id_agente = tasg.id_agent, tagente_modulo, tagente_estado,tmodule ';
$sql_from = " FROM tagente_modulo
INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente
LEFT JOIN tagent_secondary_group tasg
ON tagente.id_agente = tasg.id_agent
INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
INNER JOIN tmodule
ON tmodule.id_module = tagente_modulo.id_modulo
INNER JOIN ttipo_modulo
ON tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo
LEFT JOIN ttag_module
ON tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo";
$sql_conditions_base = ' WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo AND tmodule.id_module = tagente_modulo.id_modulo';
$sql_conditions = ' AND tagente.disabled = 0';
$sql_conditions = ' WHERE tagente.disabled = 0';
if (is_numeric($ag_group)) {
$id_ag_group = 0;
@ -149,8 +158,7 @@ else if ($modulegroup > -1) {
// Module name selector
if ($ag_modulename != '') {
$sql_conditions .= sprintf (' AND tagente_modulo.nombre = \'%s\'',
$ag_modulename);
$sql_conditions .= " AND tagente_modulo.nombre LIKE '%" .$ag_modulename. "%'";
}
if ($module_option !== 0) {
@ -261,8 +269,7 @@ if (!users_is_admin()) {
}
// Two modes of filter. All the filters and only ACLs filter
$sql_conditions_all = $sql_conditions_base . $sql_conditions . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
$sql_conditions_acl = $sql_conditions_base . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
$sql_conditions_all = $sql_conditions . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
// Get count to paginate
if (!defined('METACONSOLE'))
@ -336,22 +343,16 @@ $table->data[0][5] = html_print_select($rows_select, 'modulegroup', $modulegroup
$table->rowspan[0][6] = 2;
$table->data[0][6] = html_print_submit_button (__('Show'), 'uptbutton',
false, 'class="sub search" style="margin-top:0px;"',true);
$modules = array();
$modules = modules_get_modules_name ($sql_from , $sql_conditions_acl, is_metaconsole());
$table->data[1][0] = __('Module name');
$table->data[1][1] = html_print_select (index_array ($modules, 'nombre', 'nombre'), 'ag_modulename',
$ag_modulename, '', __('All'), '', true, false, true, '', false, 'width: 150px;');
$table->data[1][1] = html_print_autocomplete_modules('ag_modulename',
$ag_modulename, false, true, '', array(), true);
$table->data[1][2] = __('Search');
$table->data[1][3] = html_print_input_text ('ag_freestring', $ag_freestring, '', 20, 30, true);
if (!is_metaconsole())
$table->data[1][4] = __('Tags') .
ui_print_help_tip(__('Only it is show tags in use.'), true);
else
$table->data[1][4] = __('Tags') .
ui_print_help_tip(__('Only it is show tags in use.'), true);
$table->data[1][4] = __('Tags') .
ui_print_help_tip(__('Only it is show tags in use.'), true);
$tags = array();
$tags = tags_get_user_tags();

View File

@ -177,15 +177,14 @@ echo '<td style="vertical-align: top; width: 75%; padding-top: 0px;" id="rightco
// Last events information
// ---------------------------------------------------------------------
$acltags = tags_get_user_groups_and_tags ($config['id_user'], 'ER', $user_strict);
if (!empty($acltags)) {
$tags_condition = tags_get_acl_tags_event_condition($acltags, false, $user_strict);
if (check_acl($config['id_user'],0,'ER')) {
$tags_condition = tags_get_acl_tags(false,0,'ER','event_condition');
$event_filter = "estado<>1";
if (!empty($tags_condition)) {
$events = events_print_event_table ("estado<>1 AND ($tags_condition)", 10, "100%",true,false,true);
ui_toggle($events, __('Latest events'),false,false);
$event_filter .= " AND ($tags_condition)";
}
$events = events_print_event_table ($event_filter, 10, "100%",true,false,true);
ui_toggle($events, __('Latest events'),false,false);
}
// ---------------------------------------------------------------------

View File

@ -29,13 +29,13 @@ ui_require_javascript_file('openlayers.pandora');
enterprise_include_once ('operation/agentes/ver_agente.php');
check_login ();
if (is_ajax ()) {
$get_agent_json = (bool) get_parameter ('get_agent_json');
$get_agent_modules_json = (bool) get_parameter ('get_agent_modules_json');
$get_agent_status_tooltip = (bool) get_parameter ("get_agent_status_tooltip");
$get_agents_group_json = (bool) get_parameter ("get_agents_group_json");
$get_modules_group_json = (bool) get_parameter ("get_modules_group_json");
$get_modules_group_value_name_json = (bool) get_parameter ("get_modules_group_value_name_json");
$get_agent_modules_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_json_for_multiple_agents");
$get_agent_modules_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_alerts_json_for_multiple_agents");
$get_agent_modules_multiple_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_multiple_alerts_json_for_multiple_agents");
@ -183,12 +183,23 @@ if (is_ajax ()) {
}
if ($get_modules_group_json) {
$id_group = (int) get_parameter('id_module_group');
$id_group = (int) get_parameter('id_module_group', 0);
$id_agents = get_parameter('id_agents');
$selection = get_parameter('selection');
select_modules_for_agent_group($id_group, $id_agents, $selection);
}
if ($get_modules_group_value_name_json) {
$id_agents = get_parameter('id_agents');
$selection = get_parameter('selection');
// No filter by module group
$modules = select_modules_for_agent_group(0, $id_agents, $selection, false, true);
echo json_encode($modules);
return;
}
if ($get_agent_json) {
$id_agent = (int) get_parameter ('id_agent');
@ -218,61 +229,17 @@ if (is_ajax ()) {
if ($get_agents_json_for_multiple_modules) {
$nameModules = get_parameter('module_name');
$selection_mode = get_parameter('selection_mode','common');
$selection_mode = get_parameter('selection_mode','common') == "all";
$status_modulo = (int) get_parameter ('status_module', -1);
$groups = users_get_groups ($config["id_user"], "AW", false);
$group_id_list = ($groups ? join(",",array_keys($groups)):"0");
$sql = 'SELECT DISTINCT(t1.nombre) as name, t1.alias
FROM tagente t1, tagente_modulo t2
WHERE t1.id_agente = t2.id_agente
AND t1.id_grupo IN (' . $group_id_list .')
AND t2.nombre IN (\'' . implode('\',\'', $nameModules) . '\')';
// Status selector
if ($status_modulo == AGENT_MODULE_STATUS_NORMAL) { //Normal
$sql_conditions .= ' estado = 0 AND utimestamp > 0)
OR (t2.id_tipo_modulo IN(21,22,23,100)) ';
}
elseif ($status_modulo == AGENT_MODULE_STATUS_CRITICAL_BAD) { //Critical
$sql_conditions .= ' estado = 1 AND utimestamp > 0 )';
}
elseif ($status_modulo == AGENT_MODULE_STATUS_WARNING) { //Warning
$sql_conditions .= ' estado = 2 AND utimestamp > 0 )';
}
elseif ($status_modulo == AGENT_MODULE_STATUS_NOT_NORMAL) { //Not normal
$sql_conditions .= ' estado <> 0';
}
elseif ($status_modulo == AGENT_MODULE_STATUS_UNKNOWN) { //Unknown
$sql_conditions .= ' estado = 3 AND utimestamp <> 0 )';
}
elseif ($status_modulo == AGENT_MODULE_STATUS_NOT_INIT) { //Not init
$sql_conditions .= ' utimestamp = 0 )
AND t2.id_tipo_modulo NOT IN (21,22,23,100)';
}
if ($status_modulo != -1) {
$sql .= ' AND t2.id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
}
if ($selection_mode == 'common') {
$sql .= 'AND (
SELECT count(t3.nombre)
FROM tagente t3, tagente_modulo t4
WHERE t3.id_agente = t4.id_agente AND t1.nombre = t3.nombre
AND t4.nombre IN (\'' . implode('\',\'', $nameModules) . '\')) = '.count($nameModules);
}
$sql .= ' ORDER BY t1.alias';
$nameAgents = db_get_all_rows_sql($sql);
if ($nameAgents == false)
$nameAgents = array();
foreach ($nameAgents as $nameAgent)
$names[$nameAgent['name']] = io_safe_output($nameAgent['alias']);
$names = select_agents_for_module_group(
$nameModules,
$selection_mode,
array (
'status' => $status_modulo
),
"AW"
);
echo json_encode($names);
return;
@ -390,17 +357,7 @@ if (is_ajax ()) {
$filter .= ' AND t1.id_tipo_modulo NOT IN (' . implode($module_types_excluded) . ')';
if (!empty($module_name)) {
switch ($config['dbtype']) {
case "mysql":
$filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%$module_name%'";
break;
case "postgresql":
$filter .= " AND t1.nombre LIKE '%$module_name%'";
break;
case "oracle":
$filter .= " AND UPPER(t1.nombre) LIKE UPPER('%$module_name%')";
break;
}
$filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%$module_name%'";
}
// Status selector
@ -690,7 +647,7 @@ if (is_ajax ()) {
}
if ($status_modulo != -1) {
$filter['id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
$filter['tagente_modulo.id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
}
@ -702,7 +659,7 @@ if (is_ajax ()) {
if ($get_id_and_name)
$fields = array('id_agente_modulo', 'nombre');
if ($get_distinct_name)
$fields = array('DISTINCT(nombre)');
$fields = array('DISTINCT(tagente_modulo.nombre)');
$indexed = (bool) get_parameter ('indexed', true);
$agentName = (string) get_parameter ('agent_name', null);
@ -734,7 +691,6 @@ if (is_ajax ()) {
$id_agent = array_keys(
agents_get_group_agents(
array_keys (users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
}
// Restore db connection
@ -747,7 +703,6 @@ if (is_ajax ()) {
$id_agent = array_keys(
agents_get_group_agents(
array_keys(users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
}

View File

@ -158,7 +158,7 @@ if ($user_comment != '') {
}
if ($source != '') {
$sql_post .= " AND source LIKE '$source'";
$sql_post .= " AND source LIKE '%$source%'";
}
// In metaconsole mode the agent search is performed by name
@ -310,6 +310,7 @@ if ($id_group > 0 && in_array ($id_group, array_keys ($groups))) {
else {
$group_array = array_keys($groups);
}
if (check_acl ($id_user, 0, "ER"))
$tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER',
'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"

View File

@ -666,9 +666,8 @@ $table->data[] = $data;
$table->rowclass[] = '';
$data = array();
$sources = events_get_all_source();
$data[0] = __('Source') . $jump;
$data[0] .= html_print_select ($sources, 'source', $source, '', '', '', true);
$data[0] .= html_print_input_text ('source', $source, '', 35, 255, true);
$data[1] = __('Extra ID') . $jump;
$data[1] .= html_print_input_text ('id_extra', $id_extra, '', 11, 255, true);
$data[2] = __("Comment") . $jump;
@ -975,7 +974,7 @@ $(document).ready( function() {
if (i == 'id_group_filter')
$("#id_group_filter").val(val);
if (i == 'source')
$("#source").val(val);
$("#text-source").val(val);
if (i == 'id_extra')
$("#text-id_extra").val(val);
if (i == 'user_comment')
@ -1018,7 +1017,7 @@ $(document).ready( function() {
$("#pagination").val(20);
$("#update_from_filter_table").val(1);
$("#text_id_agent").val("");
$("#source").val('');
$("#text-source").val('');
$("#text-id_extra").val('');
$("#text-user_comment").val('');
@ -1090,7 +1089,7 @@ $(document).ready( function() {
}
}
if (i == 'source')
$("#source").val(val);
$("#text-source").val(val);
if (i == 'id_extra')
$("#text-id_extra").val(val);
if (i == 'user_comment')
@ -1161,7 +1160,7 @@ $(document).ready( function() {
"id_group_filter": $("#id_group_filter").val(),
"date_from": $("#text-date_from").val(),
"date_to": $("#text-date_to").val(),
"source": $("#source").val(),
"source": $("#text-source").val(),
"id_extra": $("#text-id_extra").val(),
"user_comment": $("#text-user_comment").val()
},
@ -1261,7 +1260,7 @@ $(document).ready( function() {
"id_group_filter": $("#id_group_filter").val(),
"date_from": $("#text-date_from").val(),
"date_to": $("#text-date_to").val(),
"source": $("#source").val(),
"source": $("#text-source").val(),
"id_extra": $("#text-id_extra").val(),
"user_comment": $("#text-user_comment").val()
},