Merge branch 'ent-8075-Informe-de-acciones-de-alerta' into 'develop'

WIP new report alert fired actions

See merge request artica/pandorafms!4531
This commit is contained in:
Daniel Rodriguez 2021-12-09 17:31:42 +00:00
commit 92f789945a
13 changed files with 1910 additions and 285 deletions

View File

@ -89,14 +89,13 @@ function agents_modules_load_js()
var controls = document.getElementById('vc-controls');
autoHideElement(controls, 1000);
$('select#refresh').change(function (event) {
refr = Number.parseInt(event.target.value, 10);
startCountDown(refr, false);
});
}
else {
var agentes_id = $("#id_agents2").val();
var id_agentes = getQueryParam("full_agents_id");
if (agentes_id === null && id_agentes !== null) {
@ -104,15 +103,15 @@ function agents_modules_load_js()
id_agentes.forEach(function(element) {
$("#id_agents2 option[value="+ element +"]").attr("selected",true);
});
selection_agent_module();
}
$('#refresh').change(function () {
$('#hidden-vc_refr').val($('#refresh option:selected').val());
});
}
$("#group_id").change (function () {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
@ -128,7 +127,6 @@ function agents_modules_load_js()
jQuery.each (data, function (id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
option = $("<option></option>")
.attr ("value", value["id_agente"])
.html (value["alias"]);
@ -139,7 +137,7 @@ function agents_modules_load_js()
"json"
);
});
$("#checkbox-recursion").change (function () {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
@ -155,7 +153,6 @@ function agents_modules_load_js()
jQuery.each (data, function (id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
option = $("<option></option>")
.attr ("value", value["id_agente"])
.html (value["alias"]);
@ -166,7 +163,7 @@ function agents_modules_load_js()
"json"
);
});
$("#modulegroup").change (function () {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
@ -180,8 +177,8 @@ function agents_modules_load_js()
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
.attr ("value", id)
.html (value);
$("#module").append (option);
});
}
@ -207,8 +204,8 @@ function agents_modules_load_js()
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
.attr ("value", id)
.html (value);
$("#module").append (option);
});
}
@ -231,11 +228,11 @@ function agents_modules_load_js()
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
.attr ("value", id)
.html (value);
$("#module").append (option);
});
var id_modules = getQueryParam("full_modules_selected");
if(id_modules !== null) {
id_modules = id_modules.split(";");
@ -249,20 +246,19 @@ function agents_modules_load_js()
);
}
function getQueryParam (key) {
key = key.replace(/[[]/, '[');
key = key.replace(/[]]/, ']');
var pattern = "[?&]" + key + "=([^&#]*)";
function getQueryParam (key) {
key = key.replace(/[[]/, '[');
key = key.replace(/[]]/, ']');
var pattern = "[?&]" + key + "=([^&#]*)";
var regex = new RegExp(pattern);
var url = unescape(window.location.href);
var results = regex.exec(url);
if (results === null) {
return null;
} else {
return results[1];
}
if (results === null) {
return null;
} else {
return results[1];
}
}
</script>
<?php
}

View File

@ -136,10 +136,10 @@ $percentil = false;
$time_compare_overlapped = false;
// Added for events items.
$show_summary_group = false;
$show_summary_group = false;
$filter_event_severity = false;
$filter_event_type = false;
$filter_event_status = false;
$filter_event_type = false;
$filter_event_status = false;
$event_graph_by_agent = false;
$event_graph_by_user_validator = false;
$event_graph_by_criticity = false;
@ -175,6 +175,8 @@ $agent_max_value = true;
$agent_min_value = true;
$uncompressed_module = true;
$only_data = false;
// Users.
$id_users = [];
$users_groups = [];
@ -185,6 +187,16 @@ $nothing_value = 0;
$graph_render = (empty($config['type_mode_graph']) === true) ? 0 : $config['type_mode_graph'];
$valuesGroupBy = [0 => __('None')];
$valuesGroupByDefaultAlertActions = [
'agent' => __('Agent'),
'module' => __('Module'),
'group' => __('Group'),
];
if (is_metaconsole() === false) {
$valuesGroupByDefaultAlertActions['template'] = __('Template');
}
switch ($action) {
case 'new':
$actionParameter = 'save';
@ -733,21 +745,73 @@ switch ($action) {
case 'agent_module':
$description = $item['description'];
$es = json_decode($item['external_source'], true);
$id_agents = $es['id_agents'];
// Decode agents and modules.
$id_agents = json_decode(
io_safe_output(base64_decode($es['id_agents'])),
true
);
$module = json_decode(
io_safe_output(base64_decode($es['module'])),
true
);
$selection_a_m = get_parameter('selection');
$recursion = $item['recursion'];
if ((count($es['module']) == 1) && ($es['module'][0] == 0)) {
$module = '';
} else {
$module = $es['module'];
}
$group = $item['id_group'];
$modulegroup = $item['id_module_group'];
$idAgentModule = $module;
break;
case 'alert_report_actions':
$description = $item['description'];
$es = json_decode($item['external_source'], true);
// Decode agents and modules.
$id_agents = json_decode(
io_safe_output(base64_decode($es['id_agents'])),
true
);
$module = json_decode(
io_safe_output(base64_decode($es['module'])),
true
);
$selection_a_m = get_parameter('selection');
$recursion = $item['recursion'];
$group = $item['id_group'];
$modulegroup = $item['id_module_group'];
$idAgentModule = $module;
$alert_templates_selected = $es['templates'];
$alert_actions_selected = $es['actions'];
$show_summary = $es['show_summary'];
$group_by = $es['group_by'];
$only_data = $es['only_data'];
$period = $item['period'];
$lapse = $item['lapse'];
// Set values.
$valuesGroupBy = [
'agent' => __('Agent'),
'module' => __('Module'),
'group' => __('Group'),
];
if (is_metaconsole() === false) {
$valuesGroupBy['template'] = __('Template');
}
$lapse_calc = 1;
break;
case 'agents_inventory':
$description = $item['description'];
$es = json_decode($item['external_source'], true);
@ -1648,30 +1712,12 @@ $class = 'databox filters';
<td class="bolder"><?php echo __('Agents'); ?></td>
<td>
<?php
$all_agent_log = agents_get_agents(false, ['id_agente', 'alias']);
foreach ($all_agent_log as $key => $value) {
$agents2[$value['id_agente']] = $value['alias'];
}
if ((empty($agents2)) || $agents2 == -1) {
$agents = [];
}
$agents_select = [];
if (is_array($id_agents) || is_object($id_agents)) {
foreach ($id_agents as $id) {
foreach ($agents2 as $key => $a) {
if ($key == (int) $id) {
$agents_select[$key] = $key;
}
}
}
}
$all_agents = agents_get_agents_selected($group);
html_print_select(
$agents2,
$all_agents,
'id_agents2[]',
$agents_select,
$id_agents,
$script = '',
'',
0,
@ -1680,7 +1726,23 @@ $class = 'databox filters';
true,
'',
false,
'min-width: 180px'
'min-width: 500px; max-height: 100px',
false,
false,
false,
'',
false,
false,
false,
false,
true,
true,
true
);
html_print_input_hidden(
'id_agents2-multiple-text',
json_encode($agents_select)
);
?>
</td>
@ -1717,48 +1779,146 @@ $class = 'databox filters';
<td class="bolder"><?php echo __('Modules'); ?></td>
<td>
<?php
if (empty($id_agents) || $id_agents == null || $id_agents === 0) {
$all_modules = '';
if (empty($id_agents) === true) {
$all_modules = [];
$idAgentModule = [];
} else {
$all_modules = db_get_all_rows_sql(
'SELECT DISTINCT nombre FROM
tagente_modulo WHERE id_agente IN ('.implode(',', array_values($id_agents)).')'
$all_modules = get_modules_agents(
$modulegroup,
$id_agents,
!$selection_a_m,
true
);
}
if ((empty($all_modules)) || $all_modules == -1) {
$all_modules = [];
}
$modules_select = [];
$all_modules_structured = [];
if (is_array($idAgentModule) || is_object($idAgentModule)) {
foreach ($idAgentModule as $id) {
foreach ($all_modules as $key => $a) {
if ($a['id_agente_modulo'] == (int) $id) {
$modules_select[$a['id_agente_modulo']] = $a['id_agente_modulo'];
}
}
}
}
foreach ($all_modules as $a) {
$all_modules_structured[$a['id_agente_modulo']] = $a['nombre'];
}
html_print_select(
$all_modules_structured,
$all_modules,
'module[]',
$modules_select,
$idAgentModule,
$script = '',
__('None'),
'',
0,
false,
true,
true,
'',
false,
'min-width: 180px'
'min-width: 500px; max-width: 500px; max-height: 100px',
false,
false,
false,
'',
false,
false,
false,
false,
true,
true,
true
);
html_print_input_hidden(
'module-multiple-text',
json_encode($agents_select)
);
?>
</td>
</tr>
<tr id="row_alert_templates" class="datos">
<td class="bolder"><?php echo __('Templates'); ?></td>
<td>
<?php
$alert_templates = [];
$own_info = get_user_info($config['id_user']);
if ($own_info['is_admin']) {
$alert_templates = alerts_get_alert_templates(
false,
[
'id',
'name',
]
);
} else {
$usr_groups = users_get_groups($config['id_user'], 'LW', true);
$filter_groups = '';
$filter_groups = implode(',', array_keys($usr_groups));
$alert_templates = alerts_get_alert_templates(
['id_group IN ('.$filter_groups.')'],
[
'id',
'name',
]
);
}
$alert_templates = array_reduce(
$alert_templates,
function ($carry, $item) {
$carry[$item['id']] = $item['name'];
return $carry;
},
[]
);
html_print_select(
$alert_templates,
'alert_templates[]',
$alert_templates_selected,
'',
'',
0,
false,
true,
true,
'',
false,
'min-width: 500px; max-height: 100px',
false,
false,
false,
'',
false,
false,
false,
false,
true,
true,
true
);
?>
</td>
</tr>
<tr id="row_alert_actions" class="datos">
<td class="bolder"><?php echo __('Actions'); ?></td>
<td>
<?php
$alert_actions = alerts_get_alert_actions(true);
html_print_select(
$alert_actions,
'alert_actions[]',
$alert_actions_selected,
'',
'',
0,
false,
true,
true,
'',
false,
'min-width: 500px; max-height: 100px',
false,
false,
false,
'',
false,
false,
false,
false,
true,
true,
true
);
?>
</td>
@ -2552,6 +2712,23 @@ $class = 'databox filters';
</td>
</tr>
<tr id="row_show_only_data" class="datos">
<td class="bolder">
<?php
echo __('Only data');
?>
</td>
<td>
<?php
html_print_checkbox_switch(
'only_data',
true,
$only_data
);
?>
</td>
</tr>
<tr id="row_event_severity" class="datos">
<td class="bolder"><?php echo __('Severity'); ?></td>
<td>
@ -2920,8 +3097,7 @@ $class = 'databox filters';
echo __('Time lapse intervals');
ui_print_help_tip(
__(
'Lapses of time in which the period is divided to make more precise calculations
'
'Lapses of time in which the period is divided to make more precise calculations'
)
);
?>
@ -2932,7 +3108,7 @@ $class = 'databox filters';
'lapse',
$lapse,
'',
'',
__('None'),
'0',
10,
'',
@ -3108,7 +3284,59 @@ $class = 'databox filters';
?>
</td>
</tr>
<tr id="row_show_summary" class="datos">
<td class="bolder">
<?php
echo __('Show Summary');
?>
</td>
<td>
<?php
html_print_checkbox_switch(
'show_summary',
true,
$show_summary
);
?>
</td>
</tr>
<tr id="row_group_by" class="datos">
<td class="bolder">
<?php
echo __('Group by');
?>
</td>
<td>
<?php
html_print_select(
$valuesGroupBy,
'group_by',
$group_by,
'',
'',
0,
false,
false,
false,
'',
false,
'',
false,
false,
false,
'',
false,
false,
false,
false,
true
);
?>
</td>
</tr>
<tr id="row_landscape" class="datos">
<td class="bolder">
<?php
@ -4252,12 +4480,12 @@ $(document).ready (function () {
// Load selected modules by default
$("#id_agents2").trigger('click');
$('#combo_server').change (function (){
$('#combo_server').change(function () {
$("#id_agents").html('');
$("#id_agents2").html('');
$("#module").html('');
$("#inventory_modules").html('');
})
$("#id_agents2").html('');
$("#module").html('');
$("#inventory_modules").html('');
});
$("#text-url").keyup (
function () {
@ -4273,7 +4501,6 @@ $(document).ready (function () {
$("#combo_group").change (
function () {
// Alert report group must show all matches when selecting All group
// ignoring 'recursion' option. #6497.
if ($("#combo_group").val() == 0) {
@ -4284,7 +4511,12 @@ $(document).ready (function () {
}
$("#id_agents2").html('');
// Check agent all.
$("#checkbox-id_agents2-check-all").prop('checked', false);
$("#module").html('');
// Check module all.
$("#checkbox-module-check-all").prop('checked', false);
$("#inventory_modules").html('');
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
@ -4310,7 +4542,6 @@ $(document).ready (function () {
);
}
);
$("#combo_group").change();
$("#checkbox-recursion").change (
function () {
@ -4324,6 +4555,11 @@ $(document).ready (function () {
},
function (data, status) {
$("#id_agents2").html('');
// Check agent all.
$("#checkbox-id_agents2-check-all").prop('checked', false);
$("#module").html('');
// Check module all.
$("#checkbox-module-check-all").prop('checked', false);
jQuery.each (data, function (id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
@ -4347,14 +4583,17 @@ $(document).ready (function () {
"get_modules_group_json" : 1,
"id_module_group" : this.value,
"id_agents" : $("#id_agents2").val(),
"selection" : $("#selection_agent_module").val()
"selection" : $("#selection_agent_module").val(),
"select_mode": 1
},
function (data, status) {
$("#module").html('');
// Check module all.
$("#checkbox-module-check-all").prop('checked', false);
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
.attr ("value", id)
.html (value);
$("#module").append (option);
});
},
@ -4368,17 +4607,20 @@ $(document).ready (function () {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_modules_group_json" : 1,
"selection" : $("#selection_agent_module").val(),
"id_module_group" : $("#combo_modulegroup").val(),
"id_agents" : $("#id_agents2").val(),
"selection" : $("#selection_agent_module").val()
"select_mode": 1
},
function (data, status) {
$("#module").html('');
// Check module all.
$("#checkbox-module-check-all").prop('checked', false);
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
.attr ("value", id)
.html (value);
$("#module").append (option);
});
}
@ -4395,15 +4637,18 @@ $(document).ready (function () {
"get_modules_group_json" : 1,
"id_module_group" : $("#combo_modulegroup").val(),
"id_agents" : $("#id_agents2").val(),
"selection" : $("#selection_agent_module").val()
"selection" : $("#selection_agent_module").val(),
"select_mode": 1
},
function (data, status) {
$("#module").html('');
// Check module all.
$("#checkbox-module-check-all").prop('checked', false);
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
.attr ("value", id)
.html (value);
$("#module").append (option);
});
}
@ -4494,6 +4739,15 @@ $(document).ready (function () {
}
switch (type){
case 'agent_module':
case 'alert_report_actions':
var agents_multiple = $('#id_agents2').val();
var modules_multiple = $('#module').val();
$('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple));
$('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple));
$('#id_agents2').val('');
$('#module').val('');
break;
case 'alert_report_module':
case 'alert_report_agent':
case 'event_report_agent':
@ -4518,12 +4772,6 @@ $(document).ready (function () {
return false;
}
break;
case 'agent_module':
if ($("select#id_agents2>option:selected").val() == undefined) {
dialog_message('#message_no_agent');
return false;
}
break;
case 'inventory':
case 'inventory_changes':
if ($("select#id_agents>option:selected").val() == undefined) {
@ -4568,18 +4816,11 @@ $(document).ready (function () {
case 'sumatory':
case 'historical_data':
case 'increment':
if ($("#id_agent_module").val() == 0) {
dialog_message('#message_no_module');
return false;
}
break;
case 'agent_module':
if ($("select#module>option:selected").val() == undefined) {
dialog_message('#message_no_module');
return false;
}
break;
case 'inventory':
case 'inventory_changes':
if ($("select#inventory_modules>option:selected").val() == 0) {
@ -4632,6 +4873,15 @@ $(document).ready (function () {
return false;
}
switch (type){
case 'agent_module':
case 'alert_report_actions':
var agents_multiple = $('#id_agents2').val();
var modules_multiple = $('#module').val();
$('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple));
$('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple));
$('#id_agents2').val('');
$('#module').val('');
break;
case 'alert_report_module':
case 'alert_report_agent':
case 'event_report_agent':
@ -4656,12 +4906,6 @@ $(document).ready (function () {
return false;
}
break;
case 'agent_module':
if ($("select#id_agents2>option:selected").val() == undefined) {
dialog_message('#message_no_agent');
return false;
}
break;
case 'inventory':
if ($("select#id_agents>option:selected").val() == undefined) {
dialog_message('#message_no_agent');
@ -4701,18 +4945,11 @@ $(document).ready (function () {
case 'sumatory':
case 'historical_data':
case 'increment':
if ($("#id_agent_module").val() == 0) {
dialog_message('#message_no_module');
return false;
}
break;
case 'agent_module':
if ($("select#module>option:selected").val() == undefined) {
dialog_message('#message_no_module');
return false;
}
break;
case 'inventory':
if ($("select#inventory_modules>option:selected").val() == 0) {
dialog_message('#message_no_module');
@ -5485,6 +5722,7 @@ function addGeneralRow() {
}
function chooseType() {
var meta = '<?php echo (is_metaconsole() === true) ? 1 : 0; ?>';
type = $("#type").val();
$("#row_description").hide();
$("#row_label").hide();
@ -5538,6 +5776,8 @@ function chooseType() {
$('#row_hide_notinit_agents').hide();
$('#row_priority_mode').hide();
$("#row_module_group").hide();
$("#row_alert_templates").hide();
$("#row_alert_actions").hide();
$("#row_servers").hide();
$("#row_sort").hide();
$("#row_date").hide();
@ -5562,6 +5802,7 @@ function chooseType() {
$("#select_agent_modules").hide();
$("#modules_row").hide();
$("#row_show_summary_group").hide();
$("#row_show_only_data").hide();
$("#row_event_severity").hide();
$("#row_event_type").hide();
$("#row_event_status").hide();
@ -5586,6 +5827,8 @@ function chooseType() {
$("#row_network_filter").hide();
$("#row_alive_ip").hide();
$("#row_agent_not_assigned_to_ip").hide();
$("#row_show_summary").hide();
$("#row_group_by").hide();
// SLA list default state.
$("#sla_list").hide();
@ -5896,6 +6139,37 @@ function chooseType() {
$("#row_historical_db_check").hide();
break;
case 'alert_report_actions':
$("#row_description").show();
$("#row_group").show();
$("#select_agent_modules").show();
$("#agents_modules_row").show();
$("#modules_row").show();
if(meta == 0){
$("#row_alert_templates").show();
}
$("#row_alert_actions").show();
$("#row_period").show();
$("#row_lapse").show();
$("#row_show_summary").show();
$("#row_show_only_data").show();
$("#row_group_by").show();
if('<?php echo $action; ?>' === 'new'){
$("#group_by").html('');
var dataDefault = '<?php echo json_encode($valuesGroupByDefaultAlertActions); ?>';
Object.entries(JSON.parse(dataDefault)).forEach(function (item) {
option = $("<option></option>")
.attr ("value", item[0])
.html (item[1]);
$("#group_by").append(option);
});
$("#lapse_select").attr('disabled', false);
$("#lapse_select").val('0').trigger('change');
$("#hidden-lapse").val('0');
}
break;
case 'event_report_group':
$("#row_description").show();
$("#row_period").show();

View File

@ -1676,22 +1676,77 @@ switch ($action) {
break;
case 'agent_module':
$agents_to_report = get_parameter('id_agents2');
$modules_to_report = get_parameter(
'module',
''
$agents_to_report_text = get_parameter('id_agents2-multiple-text', '');
$modules_to_report_text = get_parameter('module-multiple-text', '');
// Decode json check modules.
$agents_to_report = json_decode(
io_safe_output($agents_to_report_text),
true
);
$modules_to_report = json_decode(
io_safe_output($modules_to_report_text),
true
);
$es['module'] = get_same_modules(
$es['module'] = get_same_modules_all(
$agents_to_report,
$modules_to_report
);
$es['id_agents'] = $agents_to_report;
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
$values['external_source'] = json_encode($es);
$good_format = true;
break;
case 'alert_report_actions':
$alert_templates_to_report = get_parameter('alert_templates');
$alert_actions_to_report = get_parameter('alert_actions');
$show_summary = get_parameter('show_summary', 0);
$group_by = get_parameter('group_by');
$only_data = get_parameter('only_data', 0);
$agents_to_report_text = get_parameter('id_agents2-multiple-text');
$modules_to_report_text = get_parameter('module-multiple-text', '');
// Decode json check modules.
$agents_to_report = json_decode(
io_safe_output($agents_to_report_text),
true
);
$modules_to_report = json_decode(
io_safe_output($modules_to_report_text),
true
);
$es['module'] = get_same_modules_all(
$agents_to_report,
$modules_to_report
);
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
$es['templates'] = $alert_templates_to_report;
$es['actions'] = $alert_actions_to_report;
$es['show_summary'] = $show_summary;
$es['group_by'] = $group_by;
$es['only_data'] = $only_data;
$values['external_source'] = json_encode($es);
$values['period'] = get_parameter('period');
$values['lapse_calc'] = get_parameter(
'lapse_calc'
);
$values['lapse'] = get_parameter('lapse');
$good_format = true;
break;
case 'inventory':
$values['period'] = 0;
$es['date'] = get_parameter('date');
@ -2422,22 +2477,78 @@ switch ($action) {
break;
case 'agent_module':
$agents_to_report = get_parameter('id_agents2');
$modules_to_report = get_parameter(
'module',
''
$agents_to_report_text = get_parameter('id_agents2-multiple-text');
$modules_to_report_text = get_parameter('module-multiple-text', '');
// Decode json check modules.
$agents_to_report = json_decode(
io_safe_output($agents_to_report_text),
true
);
$modules_to_report = json_decode(
io_safe_output($modules_to_report_text),
true
);
$es['module'] = get_same_modules(
$es['module'] = get_same_modules_all(
$agents_to_report,
$modules_to_report
);
$es['id_agents'] = $agents_to_report;
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
$values['external_source'] = json_encode($es);
$good_format = true;
break;
case 'alert_report_actions':
$alert_templates_to_report = get_parameter('alert_templates');
$alert_actions_to_report = get_parameter('alert_actions');
$show_summary = get_parameter('show_summary', 0);
$group_by = get_parameter('group_by');
$only_data = get_parameter('only_data', 0);
$agents_to_report_text = get_parameter('id_agents2-multiple-text');
$modules_to_report_text = get_parameter('module-multiple-text', '');
// Decode json check modules.
$agents_to_report = json_decode(
io_safe_output($agents_to_report_text),
true
);
$modules_to_report = json_decode(
io_safe_output($modules_to_report_text),
true
);
$es['module'] = get_same_modules_all(
$agents_to_report,
$modules_to_report
);
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
$es['templates'] = $alert_templates_to_report;
$es['actions'] = $alert_actions_to_report;
$es['show_summary'] = $show_summary;
$es['group_by'] = $group_by;
$es['only_data'] = $only_data;
$values['external_source'] = json_encode($es);
$values['period'] = get_parameter('period');
$values['lapse_calc'] = get_parameter(
'lapse_calc'
);
$values['lapse'] = get_parameter('lapse');
$good_format = true;
break;
case 'inventory_changes':
$values['period'] = get_parameter('period');
$es['id_agents'] = get_parameter('id_agents');

View File

@ -733,6 +733,63 @@ function agents_get_agents(
}
function agents_get_agents_selected($group)
{
if (is_metaconsole() === true) {
$all = agents_get_agents(
['id_grupo' => $group],
[
'id_tagente',
'id_tmetaconsole_setup',
'id_agente',
'alias',
],
'AR',
[
'field' => 'alias',
'order' => 'ASC',
],
false,
0,
true
);
$all = array_reduce(
$all,
function ($carry, $item) {
$carry[$item['id_tmetaconsole_setup'].'|'.$item['id_tagente']] = $item['alias'];
return $carry;
},
[]
);
} else {
$all = agents_get_agents(
['id_grupo' => $group],
[
'id_agente',
'alias',
],
'AR',
[
'field' => 'alias',
'order' => 'ASC',
]
);
$all = array_reduce(
$all,
function ($carry, $item) {
$carry[$item['id_agente']] = $item['alias'];
return $carry;
},
[]
);
}
return $all;
}
/**
* Get all the alerts of an agent, simple and combined.
*
@ -1649,6 +1706,85 @@ function agents_get_name($id_agent, $case='none')
}
/**
* Get the agents names of an agent.
*
* @param array $array_ids Agents ids.
*
* @return array Id => name.
*/
function agents_get_alias_array($array_ids)
{
if (is_array($array_ids) === false || empty($array_ids) === true) {
return [];
}
if ((bool) is_metaconsole() === true) {
$agents = array_reduce(
$array_ids,
function ($carry, $item) {
$explode = explode('|', $item);
$carry[$explode[0]][] = $explode[1];
return $carry;
}
);
$result = [];
foreach ($agents as $tserver => $id_agents) {
$sql = sprintf(
'SELECT id_tagente as id, alias as `name`
FROM tmetaconsole_agent
WHERE id_tagente IN (%s) AND id_tmetaconsole_setup = %d',
implode(',', $id_agents),
$tserver
);
$data_server = db_get_all_rows_sql($sql);
if ($data_server === false) {
$data_server = [];
}
$data_server = array_reduce(
$data_server,
function ($carry, $item) {
$carry[$item['id']] = $item['name'];
return $carry;
},
[]
);
$result[$tserver] = $data_server;
}
} else {
$sql = sprintf(
'SELECT id_agente as id, alias as `name`
FROM tagente
WHERE id_agente IN (%s)',
implode(',', $array_ids)
);
$result = db_get_all_rows_sql($sql);
if ($result === false) {
$result = [];
}
$result = array_reduce(
$result,
function ($carry, $item) {
$carry[$item['id']] = $item['name'];
return $carry;
},
[]
);
}
return $result;
}
/**
* Get alias of an agent (cached function).
*

View File

@ -2837,3 +2837,588 @@ function alerts_get_agent_modules(
return $agent_modules;
}
function alerts_get_actions_names($actions, $reduce=false)
{
$where = '';
if (empty($actions) === false) {
if (is_array($actions) === true) {
$where = sprintf(
'WHERE id IN (%s)',
implode(',', $actions)
);
} else {
$where = sprintf('WHERE id = %d', $actions);
}
}
$sql = sprintf(
'SELECT id, `name`
FROM talert_actions
%s',
$where
);
$result = db_get_all_rows_sql($sql);
if ($result === false) {
$result = [];
}
if ($reduce === true) {
$result = array_reduce(
$result,
function ($carry, $item) {
$carry[$item['id']] = $item['name'];
return $carry;
},
[]
);
}
return $result;
}
/**
* Alert fired.
*
* @param array $filters Filters.
* @param array $groupsBy Groupby and lapse.
*
* @return array Result data.
*/
function alerts_get_alert_fired($filters=[], $groupsBy=[])
{
global $config;
$table = 'tevento';
if (is_metaconsole() === true) {
$table = 'tmetaconsole_event';
}
$filter_date = '';
if (isset($filters['period']) === true
&& empty($filters['period']) === false
) {
$filter_date = sprintf(
'AND %s.utimestamp > %d',
$table,
(time() - $filters['period'])
);
}
$filter_group = '';
if (isset($filters['group']) === true
&& empty($filters['group']) === false
) {
$filter_group = sprintf(
'AND %s.id_grupo = %d',
$table,
$filters['group']
);
}
$filter_agents = '';
if (isset($filters['agents']) === true
&& empty($filters['agents']) === false
) {
if (is_metaconsole() === true) {
$agents = array_reduce(
$filters['agents'],
function ($carry, $item) {
$explode = explode('|', $item);
$carry[$explode[0]][] = $explode[1];
return $carry;
}
);
$filter_agents .= ' AND ( ';
$i = 0;
foreach ($agents as $tserver => $agent) {
if ($i !== 0) {
$filter_agents .= ' OR ';
}
$filter_agents .= sprintf(
'( %s.id_agente IN (%s) AND %s.server_id = %d )',
$table,
implode(',', $agent),
$table,
(int) $tserver
);
$i++;
}
$filter_agents .= ' )';
} else {
$filter_agents = sprintf(
'AND %s.id_agente IN (%s)',
$table,
implode(',', $filters['agents'])
);
}
}
$filter_modules = '';
if (isset($filters['modules']) === true
&& empty($filters['modules']) === false
) {
if (is_metaconsole() === true) {
$modules = array_reduce(
$filters['modules'],
function ($carry, $item) {
$explode = explode('|', $item);
$carry[$explode[0]][] = $explode[1];
return $carry;
}
);
$filter_modules .= ' AND ( ';
$i = 0;
foreach ($modules as $tserver => $module) {
if ($i !== 0) {
$filter_modules .= ' OR ';
}
$filter_modules .= sprintf(
'( %s.id_agentmodule IN (%s) AND %s.server_id = %d )',
$table,
implode(',', $module),
$table,
(int) $tserver
);
$i++;
}
$filter_modules .= ' )';
} else {
$filter_modules = sprintf(
'AND %s.id_agentmodule IN (%s)',
$table,
implode(',', $filters['modules'])
);
}
}
$filter_templates = '';
if (isset($filters['templates']) === true
&& empty($filters['templates']) === false
) {
if (is_metaconsole() === false) {
$filter_templates = sprintf(
'AND talert_template_modules.id_alert_template IN (%s)',
implode(',', $filters['templates'])
);
}
}
$total = (bool) $filters['show_summary'];
$only_data = (bool) $filters['only_data'];
$actions_names = alerts_get_actions_names($filters['actions'], true);
$group_array = [];
$filter_actions = '';
$fields_actions = [];
if (isset($filters['actions']) === true
&& empty($filters['actions']) === false
) {
$filter_actions .= 'AND ( ';
$first = true;
foreach ($actions_names as $name_action) {
if ($first === false) {
$filter_actions .= ' OR ';
}
$filter_actions .= sprintf(
"JSON_CONTAINS(%s.custom_data, '\"%s\"', '\$.actions')",
$table,
io_safe_output($name_action)
);
$fields_actions[$name_action] = sprintf(
"SUM(JSON_CONTAINS(%s.custom_data, '\"%s\"', '\$.actions')) as '%s'",
$table,
io_safe_output($name_action),
io_safe_output($name_action)
);
$first = false;
}
$filter_actions .= ' ) ';
} else {
foreach ($actions_names as $name_action) {
$fields[] = sprintf(
"SUM(JSON_CONTAINS(%s.custom_data, '\"%s\"', '\$.actions')) as '%s'",
$table,
io_safe_output($name_action),
io_safe_output($name_action)
);
}
}
if (is_array($fields_actions) === true
&& empty($fields_actions) === false
) {
foreach ($fields_actions as $name => $field) {
$fields[] = $field;
}
}
$names_search = [];
$names_server = [];
if (isset($groupsBy['group_by']) === true) {
switch ($groupsBy['group_by']) {
case 'module':
$fields[] = $table.'.id_agentmodule as module';
$group_array[] = $table.'.id_agentmodule';
$names_search = modules_get_agentmodule_name_array(
array_values($filters['modules'])
);
if (is_metaconsole() === true) {
$fields[] = $table.'.server_id as server';
$group_array[] = $table.'.server_id';
$names_server = metaconsole_get_names();
}
break;
case 'template':
if (is_metaconsole() === false) {
$fields[] = 'talert_template_modules.id_alert_template as template';
$group_array[] = 'talert_template_modules.id_alert_template';
$names_search = alerts_get_templates_name_array(
array_values($filters['templates'])
);
}
break;
case 'agent':
$fields[] = $table.'.id_agente as agent';
$group_array[] = $table.'.id_agente';
$names_search = agents_get_alias_array(
array_values($filters['agents'])
);
if (is_metaconsole() === true) {
$fields[] = $table.'.server_id as server';
$group_array[] = $table.'.server_id';
$names_server = metaconsole_get_names();
}
break;
case 'group':
$fields[] = $table.'.id_grupo as `group`';
$group_array[] = $table.'.id_grupo';
$names_search = users_get_groups($config['user'], 'AR', false);
break;
default:
// Nothing.
break;
}
}
if (isset($groupsBy['lapse']) === true
&& empty($groupsBy['lapse']) === false
) {
$fields[] = sprintf(
'%s.utimestamp AS Period',
$table
);
$group_array[] = 'period';
}
$group_by = '';
if (is_array($group_array) === true && empty($group_array) === false) {
$group_by = sprintf(' GROUP BY %s', implode(", \n", $group_array));
}
$innerJoin = '';
if (is_metaconsole() === false) {
$innerJoin = sprintf(
'INNER JOIN talert_template_modules
ON talert_template_modules.id = %s.id_alert_am',
$table
);
}
$query = sprintf(
'SELECT
%s
FROM %s
%s
WHERE custom_data != ""
AND %s.event_type="alert_fired"
%s
%s
%s
%s
%s
%s
%s',
implode(", \n", $fields),
$table,
$innerJoin,
$table,
$filter_date,
$filter_group,
$filter_agents,
$filter_modules,
$filter_actions,
$filter_templates,
$group_by
);
$data_query = db_get_all_rows_sql($query);
if ($data_query === false) {
$data_query = [];
}
if (empty($data_query) === false) {
$data = array_reduce(
$data_query,
function ($carry, $item) use ($groupsBy) {
$period = (isset($item['Period']) === true) ? (int) $item['Period'] : 0;
if (is_metaconsole() === true
&& ($groupsBy['group_by'] === 'agent'
|| $groupsBy['group_by'] === 'module')
) {
$grby = $item[$groupsBy['group_by']];
$server = $item['server'];
unset($item['Period']);
unset($item[$groupsBy['group_by']]);
unset($item['server']);
$carry[$period][$server][$grby] = $item;
} else {
$grby = $item[$groupsBy['group_by']];
unset($item['Period']);
unset($item[$groupsBy['group_by']]);
$carry[$period][$grby] = $item;
}
return $carry;
},
[]
);
$intervals = [];
if (isset($groupsBy['lapse']) === true
&& empty($groupsBy['lapse']) === false
) {
$tend = time();
$tstart = ($tend - (int) $filters['period']);
for ($current_time = $tstart; $current_time < $tend; ($current_time += $groupsBy['lapse'])) {
$intervals[] = (int) $current_time;
}
}
$first_element = reset($data);
$first_element = reset($first_element);
if (is_metaconsole() === true
&& ($groupsBy['group_by'] === 'agent'
|| $groupsBy['group_by'] === 'module')
) {
$first_element = reset($first_element);
}
$clone = [];
foreach ($first_element as $key_clone => $value_clone) {
$clone[$key_clone] = 0;
}
$result = [];
if (empty($intervals) === true) {
foreach ($data as $period => $array_data) {
if (is_metaconsole() === true
&& ($groupsBy['group_by'] === 'agent'
|| $groupsBy['group_by'] === 'module')
) {
foreach ($names_search as $server => $names) {
foreach ($names as $id => $name) {
$name = $names_server[$server].' &raquo; '.$name;
if (isset($array_data[$server][$id]) === true) {
$result[$period][$server.'|'.$id] = $array_data[$server][$id];
$result[$period][$server.'|'.$id][$groupsBy['group_by']] = $name;
} else {
if ($only_data === false) {
$clone[$groupsBy['group_by']] = $name;
$result[$period][$server.'|'.$id] = $clone;
}
}
}
}
} else {
foreach ($names_search as $id => $name) {
if (isset($array_data[$id]) === true) {
$result[$period][$id] = $array_data[$id];
$result[$period][$id][$groupsBy['group_by']] = $name;
} else {
if ($only_data === false) {
$clone[$groupsBy['group_by']] = $name;
$result[$period][$id] = $clone;
}
}
}
}
}
} else {
$period_lapse = (int) $groupsBy['lapse'];
foreach ($intervals as $interval) {
$start_interval = $interval;
$end_interval = ($interval + $period_lapse);
if ($only_data === false) {
if (is_metaconsole() === true
&& ($groupsBy['group_by'] === 'agent'
|| $groupsBy['group_by'] === 'module')
) {
foreach ($names_search as $server => $names) {
foreach ($names as $id => $name) {
$result_name = $names_server[$server].' &raquo; '.$name;
$result[$start_interval][$server.'|'.$id] = $clone;
$result[$start_interval][$server.'|'.$id][$groupsBy['group_by']] = $result_name;
}
}
} else {
foreach ($names_search as $id => $name) {
$result[$start_interval][$id] = $clone;
$result[$start_interval][$id][$groupsBy['group_by']] = $name;
}
}
} else {
foreach ($data as $period => $array_data) {
if (is_metaconsole() === true
&& ($groupsBy['group_by'] === 'agent'
|| $groupsBy['group_by'] === 'module')
) {
foreach ($array_data as $server => $datas) {
foreach ($datas as $id_data => $value_data) {
$name = $names_server[$server].' &raquo; '.$names_search[$server][$id_data];
$result[$start_interval][$server.'|'.$id_data] = $clone;
$result[$start_interval][$server.'|'.$id_data][$groupsBy['group_by']] = $name;
}
}
} else {
foreach ($array_data as $id_data => $value_data) {
$name = $names_search[$id_data];
$result[$start_interval][$id_data] = $clone;
$result[$start_interval][$id_data][$groupsBy['group_by']] = $name;
}
}
}
}
foreach ($data as $period => $array_data) {
$period_time = (int) $period;
if ($start_interval < $period_time && $period_time <= $end_interval) {
if (is_metaconsole() === true
&& ($groupsBy['group_by'] === 'agent'
|| $groupsBy['group_by'] === 'module')
) {
foreach ($array_data as $server => $datas) {
foreach ($datas as $id_data => $value_data) {
foreach ($value_data as $key_data => $v) {
if ($key_data !== $groupsBy['group_by']) {
if (isset($result[$start_interval][$server.'|'.$id_data][$key_data])) {
$result[$start_interval][$server.'|'.$id_data][$key_data] += $v;
} else {
$result[$start_interval][$server.'|'.$id_data][$key_data] = $v;
}
}
}
}
}
} else {
foreach ($array_data as $id_data => $value_data) {
foreach ($value_data as $key_data => $v) {
if ($key_data !== $groupsBy['group_by']) {
if (isset($result[$start_interval][$id_data][$key_data])) {
$result[$start_interval][$id_data][$key_data] += $v;
} else {
$result[$start_interval][$id_data][$key_data] = $v;
}
}
}
}
}
unset($data[$period]);
}
}
}
}
}
$result['data'] = $result;
if ($total === true) {
$total_values = [];
foreach ($data_query as $key => $array_data) {
foreach ($array_data as $key_value => $v) {
$total_values[$key_value] = ($total_values[$key_value] + $v);
}
}
if (is_metaconsole() === true
&& ($groupsBy['group_by'] === 'agent'
|| $groupsBy['group_by'] === 'module')
) {
unset($total_values['server']);
}
unset($total_values['Period']);
$result['summary']['total'] = $total_values;
$result['summary']['total'][$groupsBy['group_by']] = __('Total');
}
return $result;
}
/**
* Get the templates names of an agent.
*
* @param array $array_ids Templates ids.
*
* @return array Id => name.
*/
function alerts_get_templates_name_array($array_ids)
{
if (is_array($array_ids) === false || empty($array_ids) === true) {
return [];
}
$sql = sprintf(
'SELECT id, `name`
FROM talert_templates
WHERE id IN (%s)',
implode(',', $array_ids)
);
$result = db_get_all_rows_sql($sql);
if ($result === false) {
$result = [];
}
$result = array_reduce(
$result,
function ($carry, $item) {
$carry[$item['id']] = $item['name'];
return $carry;
},
[]
);
return $result;
}

View File

@ -729,7 +729,8 @@ function html_print_select(
$required=false,
$truncate_size=false,
$select2_enable=true,
$multiple_select2=false
$select2_multiple_enable=false,
$select2_multiple_enable_all=false
) {
$output = "\n";
@ -791,6 +792,12 @@ function html_print_select(
$required = 'required';
}
if ($select2_multiple_enable === true
&& $select2_multiple_enable_all === true
) {
$output .= '<div class="flex-row-center">';
}
$output .= '<select '.$required.' onclick="'.$script.'" id="'.$id.'" name="'.$name.'"'.$attributes.' '.$styleText.'>';
if ($nothing !== false) {
@ -890,6 +897,24 @@ function html_print_select(
}
$output .= '</select>';
if ($select2_multiple_enable === true
&& $select2_multiple_enable_all === true
) {
$output .= '<div class="margin-left-2 flex-column">';
$output .= '<span>'.__('All').'</span>';
$output .= html_print_checkbox_switch(
$id.'-check-all',
1,
false,
true,
$disabled,
'checkMultipleAll('.$id.')'
);
$output .= '</div>';
$output .= '</div>';
}
if ($modal && !enterprise_installed()) {
$output .= "
<div id='".$message."' class='publienterprise publicenterprise_div' title='Community version'><img data-title='".__('Enterprise version not installed')."' class='img_help forced_title' data-use_title_for_force_title='1' src='images/alert_enterprise.png'></div>
@ -901,8 +926,7 @@ function html_print_select(
$select2 = 'select2_dark.min';
}
// Note that multiple_select2 is introduced as a workaround to overcome the pointless limitation of preventing "multiple" select inputs from using select2 library without affecting the existing calls to this function.
if ($multiple === false && $select2_enable === true || $multiple_select2 === true) {
if (($multiple === false || $select2_multiple_enable === true) && $select2_enable === true) {
if (is_ajax()) {
$output .= '<script src="';
$output .= ui_get_full_url(
@ -944,6 +968,32 @@ function html_print_select(
});';
}
if ($select2_multiple_enable === true
&& $select2_multiple_enable_all === true
) {
$output .= '$("#'.$id.'").on("change", function(e) {
var checked = false;
if(e.target.length !== $("#'.$id.' > option:selected").length) {
checked = false;
} else {
checked = true;
}
$("#checkbox-'.$id.'-check-all").prop("checked", checked);
});';
$output .= '$("#'.$id.'").trigger("change");';
$output .= 'function checkMultipleAll(id){
if ($("#checkbox-"+id.id+"-check-all").is(":checked")) {
$("#"+id.id+" > option").prop("selected", "selected");
$("#"+id.id).trigger("change");
} else {
$("#"+id.id).val(null).trigger("change");
}
}';
}
$output .= '</script>';
}

View File

@ -26,6 +26,8 @@
* ============================================================================
*/
use PandoraFMS\Enterprise\Metaconsole\Node;
// Begin.
require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_users.php';
@ -1435,6 +1437,90 @@ function modules_get_agentmodule_name($id_agente_modulo)
}
/**
* Get the module names of an agent module.
*
* @param array $array_ids Agents module ids.
*
* @return array Id => name.
*/
function modules_get_agentmodule_name_array($array_ids)
{
if (is_array($array_ids) === false || empty($array_ids) === true) {
return [];
}
if ((bool) is_metaconsole() === true) {
$modules = array_reduce(
$array_ids,
function ($carry, $item) {
$explode = explode('|', $item);
$carry[$explode[0]][] = $explode[1];
return $carry;
}
);
$result = [];
foreach ($modules as $tserver => $id_modules) {
if (metaconsole_connect(null, $tserver) == NOERR) {
$result_modules = modules_get_agentmodule_name_array_data(
$id_modules
);
$result[$tserver] = $result_modules;
metaconsole_restore_db();
}
}
} else {
$result = modules_get_agentmodule_name_array_data(
$array_ids
);
}
return $result;
}
/**
* Data names.
*
* @param array $array_ids Ids.
*
* @return array
*/
function modules_get_agentmodule_name_array_data($array_ids)
{
if (is_array($array_ids) === false || empty($array_ids) === true) {
return [];
}
$sql = sprintf(
'SELECT id_agente_modulo as id, nombre as `name`
FROM tagente_modulo
WHERE id_agente_modulo IN (%s)',
implode(',', $array_ids)
);
$result = db_get_all_rows_sql($sql);
if ($result === false) {
$result = [];
}
$result = array_reduce(
$result,
function ($carry, $item) {
$carry[$item['id']] = $item['name'];
return $carry;
},
[]
);
return $result;
}
/**
* Get the module descripcion of an agent module.
*
@ -3469,32 +3555,271 @@ function modules_get_agentmodule_mininterval_no_async($id_agent)
}
function get_same_modules($agents, $modules)
function get_modules_agents($id_module_group, $id_agents, $selection, $select_mode=true)
{
$modules_to_report = [];
if ($modules != '') {
foreach ($modules as $m) {
$module_name = modules_get_agentmodule_name($m);
foreach ($agents as $a) {
$module_in_agent = db_get_value_filter(
'id_agente_modulo',
'tagente_modulo',
[
'id_agente' => $a,
'nombre' => $module_name,
]
);
if ($module_in_agent) {
$modules_to_report[] = $module_in_agent;
if ((bool) is_metaconsole() === true) {
if ($select_mode === true) {
$agents = array_reduce(
$id_agents,
function ($carry, $item) {
$explode = explode('|', $item);
$carry[$explode[0]][] = $explode[1];
return $carry;
}
);
} else {
if (count($id_agents) > 0) {
$rows = db_get_all_rows_sql(
sprintf(
'SELECT `id_agente`, `id_tagente`, `id_tmetaconsole_setup`
FROM `tmetaconsole_agent`
WHERE `id_agente` IN (%s)',
implode(',', $id_agents)
)
);
} else {
$rows = [];
}
$agents = array_reduce(
$rows,
function ($carry, $item) {
if ($carry[$item['id_tmetaconsole_setup']] === null) {
$carry[$item['id_tmetaconsole_setup']] = [];
}
$carry[$item['id_tmetaconsole_setup']][] = $item['id_tagente'];
return $carry;
},
[]
);
}
$modules = [];
foreach ($agents as $tserver => $id_agents) {
if (metaconsole_connect(null, $tserver) == NOERR) {
$modules[$tserver] = select_modules_for_agent_group(
$id_module_group,
$id_agents,
$selection,
false,
false,
true
);
metaconsole_restore_db();
}
}
if (!$selection) {
// Common modules.
$final_modules = [];
$nodes_consulted = count($modules);
foreach ($modules as $tserver => $mods) {
foreach ($mods as $module) {
if ($final_modules[$module['nombre']] === null) {
$final_modules[$module['nombre']] = 0;
}
$final_modules[$module['nombre']]++;
}
}
$modules = [];
foreach ($final_modules as $module_name => $occurrences) {
if ($occurrences === $nodes_consulted) {
// Module already present in ALL nodes.
$modules[] = [
'id_agente_modulo' => $module_name,
'nombre' => $module_name,
];
}
}
} else {
// All modules.
$return = [];
$nodes = [];
foreach ($agents as $tserver => $id_agents) {
try {
$nodes[$tserver] = new Node($tserver);
} catch (Exception $e) {
hd($e);
}
$return = array_reduce(
$modules[$tserver],
function ($carry, $item) use ($tserver, $nodes) {
$t = [];
foreach ($item as $k => $v) {
$t[$k] = $v;
}
$t['id_node'] = $tserver;
if ($nodes[$tserver] !== null) {
$t['nombre'] = io_safe_output(
$nodes[$tserver]->server_name().' &raquo; '.$t['nombre']
);
}
$carry[] = $t;
return $carry;
},
$return
);
}
$modules = $return;
}
$modules = array_reduce(
$modules,
function ($carry, $item) {
$carry[$item['id_node'].'|'.$item['id_agente_modulo']] = $item['nombre'];
return $carry;
},
[]
);
} else {
$modules = select_modules_for_agent_group(
$id_module_group,
$id_agents,
$selection,
false
);
}
$modules_to_report = array_merge($modules_to_report, $modules);
return $modules;
}
/**
* List all modules in agents selection.
*
* @param array $agents Agents ids array.
* @param array $modules Modules ids array.
*
* @return array
*/
function get_same_modules($agents, $modules)
{
if (is_array($agents) === false || empty($agents) === true) {
return [];
}
$name_modules = modules_get_agentmodule_name_array_data(
array_values($modules)
);
$sql = sprintf(
'SELECT id_agente_modulo as id,
nombre as `name`
FROM tagente_modulo
WHERE id_agente IN (%s)',
implode(',', array_values($agents))
);
$all = db_get_all_rows_sql($sql);
if ($all === false) {
$all = [];
}
$all = array_reduce(
$all,
function ($carry, $item) use ($name_modules) {
if (array_search($item['name'], $name_modules)) {
$carry[$item['id']] = $item['id'];
}
return $carry;
},
[]
);
$modules_to_report = array_merge($all, $modules);
$modules_to_report = array_unique($modules_to_report);
return $modules_to_report;
return $all;
}
/**
* List all modules in agents selection to metaconsole or node.
*
* @param array $agents Agents ids array.
* @param array $modules Modules ids array.
*
* @return array List modules [server|id_module, ...].
*/
function get_same_modules_all($agents, $modules, $select_mode=true)
{
if (is_array($agents) === false || empty($agents) === true) {
return [];
}
if (is_metaconsole() === true) {
$modules = array_reduce(
$modules,
function ($carry, $item) {
$explode = explode('|', $item);
$carry[$explode[0]][] = $explode[1];
return $carry;
}
);
if ($select_mode === true) {
$agents = array_reduce(
$agents,
function ($carry, $item) {
$explode = explode('|', $item);
$carry[$explode[0]][] = $explode[1];
return $carry;
}
);
} else {
$rows = db_get_all_rows_sql(
sprintf(
'SELECT `id_agente`, `id_tagente`, `id_tmetaconsole_setup`
FROM `tmetaconsole_agent`
WHERE `id_agente` IN (%s)',
implode(',', $agents)
)
);
$agents = array_reduce(
$rows,
function ($carry, $item) {
if ($carry[$item['id_tmetaconsole_setup']] === null) {
$carry[$item['id_tmetaconsole_setup']] = [];
}
$carry[$item['id_tmetaconsole_setup']][] = $item['id_tagente'];
return $carry;
},
[]
);
}
$result = [];
foreach ($agents as $tserver => $id_agents) {
if (metaconsole_connect(null, $tserver) == NOERR) {
$same_modules = get_same_modules($id_agents, $modules[$tserver]);
foreach ($same_modules as $id_module) {
$result[] = $tserver.'|'.$id_module;
}
metaconsole_restore_db();
}
}
} else {
$result = get_same_modules($agents, $modules);
}
return $result;
}

View File

@ -734,6 +734,13 @@ function reporting_make_reporting_data(
);
break;
case 'alert_report_actions':
$report['contents'][] = reporting_alert_report_actions(
$report,
$content
);
break;
case 'agents_inventory':
$report['contents'][] = reporting_agents_inventory(
$report,
@ -2658,15 +2665,119 @@ function reporting_inventory($report, $content, $type)
}
/**
* Build data for report alert actions.
*
* @param array $report Report info.
* @param array $content Content.
*
* @return array Result data.
*/
function reporting_alert_report_actions($report, $content)
{
$return = [];
$return['type'] = 'alert_report_actions';
if (empty($content['name']) === true) {
$content['name'] = __('Alert actions');
}
$return['title'] = io_safe_output($content['name']);
$return['landscape'] = $content['landscape'];
$return['pagebreak'] = $content['pagebreak'];
$return['subtitle'] = __('Actions');
$return['description'] = io_safe_output($content['description']);
$return['date'] = reporting_get_date_text($report, $content);
$return['data'] = [];
$es = json_decode($content['external_source'], true);
if (isset($report['id_template']) === true
&& empty($report['id_template']) === false
) {
if (is_metaconsole() === true) {
$server_id = metaconsole_get_id_server($content['server_name']);
$modules = [$server_id.'|'.$content['id_agent_module']];
$agents = [$server_id.'|'.$content['id_agent']];
} else {
$modules = [$content['id_agent_module']];
$agents = [$content['id_agent']];
}
} else {
$modules = json_decode(
io_safe_output(base64_decode($es['module'])),
true
);
$agents = json_decode(
io_safe_output(base64_decode($es['id_agents'])),
true
);
}
$period = $content['period'];
$id_group = $content['id_group'];
$templates = $es['templates'];
$actions = $es['actions'];
$show_summary = $es['show_summary'];
$group_by = $es['group_by'];
$lapse = $content['lapse'];
$only_data = $es['only_data'];
$filters = [
'group' => $id_group,
'agents' => $agents,
'modules' => $modules,
'templates' => $templates,
'actions' => $actions,
'period' => $period,
'show_summary' => (bool) $show_summary,
'only_data' => (bool) $only_data,
];
$groupsBy = [
'group_by' => $group_by,
'lapse' => $lapse,
];
$return['filters'] = $filters;
$return['groupsBy'] = $groupsBy;
$return['data'] = alerts_get_alert_fired($filters, $groupsBy);
return reporting_check_structure_content($return);
}
/**
* Data report agent/module.
*
* @param array $report Report info.
* @param array $content Content info.
*
* @return array Structure Content.
*/
function reporting_agent_module($report, $content)
{
global $config;
$agents_and_modules = json_decode($content['external_source'], true);
$agents = [];
$agents = $agents_and_modules['id_agents'];
$modules = $agents_and_modules['module'];
$id_group = $content['id_group'];
$id_module_group = $content['id_module_group'];
$external_source = json_decode(
$content['external_source'],
true
);
$agents = json_decode(
io_safe_output(
base64_decode($external_source['id_agents'])
),
true
);
$modules = json_decode(
io_safe_output(
base64_decode($external_source['module'])
),
true
);
$return['type'] = 'agent_module';
@ -2700,7 +2811,9 @@ function reporting_agent_module($report, $content)
$cont = 0;
foreach ($modules as $modul_id) {
$modules_by_name[$cont]['name'] = io_safe_output(modules_get_agentmodule_name($modul_id));
$modules_by_name[$cont]['name'] = io_safe_output(
modules_get_agentmodule_name($modul_id)
);
$modules_by_name[$cont]['id'] = $modul_id;
$cont++;
}

View File

@ -377,6 +377,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
reporting_html_agent_module($table, $item);
break;
case 'alert_report_actions':
reporting_html_alert_report_actions($table, $item);
break;
case 'agents_inventory':
reporting_html_agents_inventory($table, $item);
break;
@ -2729,6 +2733,94 @@ function reporting_html_group_configuration($table, $item, $pdf=0)
}
/**
* Html output report alert actions
*
* @param object $table Table.
* @param array $item Data for draw report.
* @param integer $pdf PDF output.
*
* @return string Html output.
*/
function reporting_html_alert_report_actions($table, $item, $pdf=0)
{
$data = $item['data'];
$groupsBy = $item['groupsBy'];
$output = '';
if (isset($data['data']) === true
&& empty($data['data']) === false
) {
foreach ($data['data'] as $period => $data_array) {
if (empty($period) === false) {
$output .= '<h1 class="h1-report-alert-actions">';
$output .= __('From').' ';
$output .= date(
'd-m-Y H:i:s',
$period
);
$output .= ' '.__('to').' ';
$output .= date('d-m-Y H:i:s', ($period + (int) $groupsBy['lapse']));
$output .= '</h1>';
}
$output .= get_alert_table($data_array);
}
if (isset($data['summary']) === true
&& empty($data['summary']) === false
) {
$output .= '<h1 class="h1-report-alert-actions">';
$output .= __('Total summary');
$output .= '</h1>';
$output .= get_alert_table($data['summary']);
}
} else {
$output .= ui_print_empty_data(
__('No alerts fired'),
'',
true
);
}
if ($pdf === 0) {
$table->colspan['alert_report_action']['cell'] = 3;
$table->cellstyle['alert_report_action']['cell'] = 'text-align: center;';
$table->data['alert_report_action']['cell'] = $output;
} else {
return $output;
}
}
function get_alert_table($data)
{
$table = new StdCLass();
$table->width = '100%';
$table->data = [];
$table->head = [];
$table->headstyle = [];
$table->cellstyle = [];
$table->headstyle[0] = 'text-align:left;';
$head = reset($data);
foreach (array_reverse(array_keys($head)) as $name) {
$table->head[] = $name;
}
foreach ($data as $key => $params) {
$table->cellstyle[$key][0] = 'text-align:left;';
foreach (array_reverse($params) as $name => $value) {
$table->data[$key][] = $value;
}
}
return html_print_table($table, true);
}
/**
* This type of report element will generate the interface graphs
* of all those devices that belong to the selected group.

View File

@ -834,6 +834,7 @@ function reports_get_report_types($template=false, $not_editor=false)
'optgroup' => __('Alerts'),
'name' => __('Agent alert report '),
];
if (!$template) {
$types['alert_report_group'] = [
'optgroup' => __('Alerts'),
@ -841,6 +842,11 @@ function reports_get_report_types($template=false, $not_editor=false)
];
}
$types['alert_report_actions'] = [
'optgroup' => __('Alerts'),
'name' => __('Actions alert report '),
];
$types['event_report_module'] = [
'optgroup' => __('Events'),
'name' => __('Module event report'),

View File

@ -329,7 +329,7 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t
if (!$no_close_bool) {
// Use the no_meta parameter because this image is only in
// the base console.
$output .= '<a href="javascript: close_info_box(\''.$id.'\')">'.html_print_image('images/blade.png', true, false, false, true).'</a>';
$output .= '<a href="javascript: close_info_box(\''.$id.'\')">'.html_print_image('images/blade.png', true, false, false, false).'</a>';
}
$output .= '</td>

View File

@ -8347,3 +8347,41 @@ div.stat-win-spinner img {
#license_error_msg_dialog {
min-height: 350px !important;
}
.select2-container--default
.select2-selection--multiple
.select2-selection__rendered {
padding: 5px 10px 10px !important;
max-height: 120px;
overflow: auto !important;
}
.select2-container--default
.select2-selection--multiple
.select2-selection__choice {
background-color: #82b92e !important;
border: 1px solid #82b92e !important;
padding: 0.3em 0.6em !important;
color: #fff;
font-size: 1em;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
align-content: center;
}
.select2-container--default
.select2-selection--multiple
.select2-selection__choice__remove {
color: #fff !important;
font-size: 1.2em;
margin-right: 5px !important;
}
.h1-report-alert-actions {
text-transform: none;
text-align: left;
margin: 5px;
font-size: 12px;
}

View File

@ -192,126 +192,25 @@ if (is_ajax()) {
return;
}
if ($get_modules_group_json) {
if ($get_modules_group_json === true) {
$id_group = (int) get_parameter('id_module_group', 0);
$id_agents = get_parameter('id_agents', null);
$selection = get_parameter('selection');
$select_mode = (bool) get_parameter('select_mode', 0);
if ($id_agents === null) {
echo '[]';
return;
}
if ((bool) is_metaconsole() === true) {
if (count($id_agents) > 0) {
$rows = db_get_all_rows_sql(
sprintf(
'SELECT `id_agente`, `id_tagente`, `id_tmetaconsole_setup`
FROM `tmetaconsole_agent`
WHERE `id_agente` IN (%s)',
implode(',', $id_agents)
)
);
} else {
$rows = [];
}
$agents = array_reduce(
$rows,
function ($carry, $item) {
if ($carry[$item['id_tmetaconsole_setup']] === null) {
$carry[$item['id_tmetaconsole_setup']] = [];
}
$carry[$item['id_tmetaconsole_setup']][] = $item['id_tagente'];
return $carry;
},
[]
);
$modules = [];
foreach ($agents as $tserver => $id_agents) {
if (metaconsole_connect(null, $tserver) == NOERR) {
$modules[$tserver] = select_modules_for_agent_group(
$id_group,
$id_agents,
$selection,
false,
false,
true
);
metaconsole_restore_db();
}
}
if (!$selection) {
// Common modules.
$final_modules = [];
$nodes_consulted = count($modules);
foreach ($modules as $tserver => $mods) {
foreach ($mods as $module) {
if ($final_modules[$module['nombre']] === null) {
$final_modules[$module['nombre']] = 0;
}
$final_modules[$module['nombre']]++;
}
}
$modules = [];
foreach ($final_modules as $module_name => $occurrences) {
if ($occurrences === $nodes_consulted) {
// Module already present in ALL nodes.
$modules[] = [
'id_agente_modulo' => $module_name,
'nombre' => $module_name,
];
}
}
} else {
// All modules.
$return = [];
$nodes = [];
foreach ($agents as $tserver => $id_agents) {
try {
$nodes[$tserver] = new Node($tserver);
} catch (Exception $e) {
hd($e);
}
$return = array_reduce(
$modules[$tserver],
function ($carry, $item) use ($tserver, $nodes) {
$t = [];
foreach ($item as $k => $v) {
$t[$k] = $v;
}
$t['id_node'] = $tserver;
if ($nodes[$tserver] !== null) {
$t['nombre'] = io_safe_output(
$nodes[$tserver]->server_name().' &raquo; '.$t['nombre']
);
}
$carry[] = $t;
return $carry;
},
$return
);
}
$modules = $return;
}
echo json_encode($modules);
} else {
select_modules_for_agent_group($id_group, $id_agents, $selection);
}
$modules = get_modules_agents(
$id_group,
$id_agents,
$selection,
$select_mode
);
echo json_encode($modules);
return;
}
if ($filter_modules_group_json) {