wip reports alert actions
This commit is contained in:
parent
ec21d9d08a
commit
94bd55fd39
|
@ -175,6 +175,8 @@ $agent_max_value = true;
|
|||
$agent_min_value = true;
|
||||
$uncompressed_module = true;
|
||||
|
||||
$only_data = false;
|
||||
|
||||
// Users.
|
||||
$id_users = [];
|
||||
$users_groups = [];
|
||||
|
@ -763,7 +765,6 @@ switch ($action) {
|
|||
break;
|
||||
|
||||
case 'alert_report_actions':
|
||||
hd('1');
|
||||
$description = $item['description'];
|
||||
$es = json_decode($item['external_source'], true);
|
||||
|
||||
|
@ -791,6 +792,8 @@ switch ($action) {
|
|||
|
||||
$group_by = $es['group_by'];
|
||||
|
||||
$only_data = $es['only_data'];
|
||||
|
||||
$period = $item['period'];
|
||||
|
||||
$lapse = $item['lapse'];
|
||||
|
@ -2709,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>
|
||||
|
@ -5782,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();
|
||||
|
@ -6131,6 +6152,7 @@ function chooseType() {
|
|||
$("#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('');
|
||||
|
|
|
@ -1707,7 +1707,7 @@ switch ($action) {
|
|||
$alert_actions_to_report = get_parameter('alert_actions');
|
||||
$show_summary = get_parameter('show_summary', 0);
|
||||
$group_by = get_parameter('group_by');
|
||||
hd('3');
|
||||
$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', '');
|
||||
|
||||
|
@ -1734,6 +1734,7 @@ switch ($action) {
|
|||
$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);
|
||||
|
||||
|
@ -2503,11 +2504,11 @@ switch ($action) {
|
|||
break;
|
||||
|
||||
case 'alert_report_actions':
|
||||
hd('2');
|
||||
$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', '');
|
||||
|
@ -2535,6 +2536,7 @@ switch ($action) {
|
|||
$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);
|
||||
|
||||
|
|
|
@ -2881,12 +2881,18 @@ function alerts_get_actions_names($actions, $reduce=false)
|
|||
}
|
||||
|
||||
|
||||
function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
||||
/**
|
||||
* 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;
|
||||
|
||||
hd(5);
|
||||
|
||||
$table = 'tevento';
|
||||
if (is_metaconsole() === true) {
|
||||
$table = 'tmetaconsole_event';
|
||||
|
@ -3012,6 +3018,9 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
}
|
||||
}
|
||||
|
||||
$total = (bool) $filters['show_summary'];
|
||||
$only_data = (bool) $filters['only_data'];
|
||||
|
||||
$actions_names = alerts_get_actions_names($filters['actions'], true);
|
||||
|
||||
$group_array = [];
|
||||
|
@ -3071,57 +3080,45 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
case 'module':
|
||||
$fields[] = $table.'.id_agentmodule as module';
|
||||
$group_array[] = $table.'.id_agentmodule';
|
||||
if ($total === false) {
|
||||
$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';
|
||||
if ($total === false) {
|
||||
$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';
|
||||
if ($total === false) {
|
||||
$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';
|
||||
if ($total === false) {
|
||||
$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';
|
||||
if ($total === false) {
|
||||
$names_server = metaconsole_get_names();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'group':
|
||||
$fields[] = $table.'.id_grupo as `group`';
|
||||
$group_array[] = $table.'.id_grupo';
|
||||
if ($total === false) {
|
||||
$names_search = users_get_groups($config['user'], 'AR', false);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -3130,7 +3127,6 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
}
|
||||
}
|
||||
|
||||
if ($total === false) {
|
||||
if (isset($groupsBy['lapse']) === true
|
||||
&& empty($groupsBy['lapse']) === false
|
||||
) {
|
||||
|
@ -3140,7 +3136,6 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
);
|
||||
$group_array[] = 'period';
|
||||
}
|
||||
}
|
||||
|
||||
$group_by = '';
|
||||
if (is_array($group_array) === true && empty($group_array) === false) {
|
||||
|
@ -3183,18 +3178,15 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
$group_by
|
||||
);
|
||||
|
||||
hd($query);
|
||||
$data_query = db_get_all_rows_sql($query);
|
||||
|
||||
$data = db_get_all_rows_sql($query);
|
||||
|
||||
if ($data === false) {
|
||||
$data = [];
|
||||
if ($data_query === false) {
|
||||
$data_query = [];
|
||||
}
|
||||
|
||||
if ($total === false) {
|
||||
if (empty($data) === false) {
|
||||
if (empty($data_query) === false) {
|
||||
$data = array_reduce(
|
||||
$data,
|
||||
$data_query,
|
||||
function ($carry, $item) use ($groupsBy) {
|
||||
$period = (isset($item['Period']) === true) ? (int) $item['Period'] : 0;
|
||||
if (is_metaconsole() === true
|
||||
|
@ -3257,29 +3249,34 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
$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')
|
||||
|
@ -3297,6 +3294,28 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
$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].' » '.$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;
|
||||
|
@ -3338,17 +3357,27 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
$result['data'] = $result;
|
||||
|
||||
if ($total === true) {
|
||||
$total_values = [];
|
||||
$result = [];
|
||||
foreach ($data as $key => $array_data) {
|
||||
foreach ($data_query as $key => $array_data) {
|
||||
foreach ($array_data as $key_value => $v) {
|
||||
$total_values[$key_value] = ($total_values[$key_value] + $v);
|
||||
}
|
||||
}
|
||||
|
||||
$result['total'] = $total_values;
|
||||
$result['total'][$groupsBy['group_by']] = __('Total');
|
||||
if (is_metaconsole() === true
|
||||
&& ($groupsBy['group_by'] === 'agent'
|
||||
|| $groupsBy['group_by'] === 'module')
|
||||
) {
|
||||
unset($total_values['Period']);
|
||||
unset($total_values['server']);
|
||||
}
|
||||
|
||||
$result['summary']['total'] = $total_values;
|
||||
$result['summary']['total'][$groupsBy['group_by']] = __('Total');
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
|
@ -2665,13 +2665,18 @@ 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)
|
||||
{
|
||||
global $config;
|
||||
$return = [];
|
||||
|
||||
hd('4');
|
||||
|
||||
$return['type'] = 'alert_report_actions';
|
||||
if (empty($content['name']) === true) {
|
||||
$content['name'] = __('Alert actions');
|
||||
|
@ -2717,6 +2722,7 @@ function reporting_alert_report_actions($report, $content)
|
|||
$show_summary = $es['show_summary'];
|
||||
$group_by = $es['group_by'];
|
||||
$lapse = $content['lapse'];
|
||||
$only_data = $es['only_data'];
|
||||
|
||||
$filters = [
|
||||
'group' => $id_group,
|
||||
|
@ -2725,6 +2731,8 @@ function reporting_alert_report_actions($report, $content)
|
|||
'templates' => $templates,
|
||||
'actions' => $actions,
|
||||
'period' => $period,
|
||||
'show_summary' => (bool) $show_summary,
|
||||
'only_data' => (bool) $only_data,
|
||||
];
|
||||
|
||||
$groupsBy = [
|
||||
|
@ -2735,19 +2743,7 @@ function reporting_alert_report_actions($report, $content)
|
|||
$return['filters'] = $filters;
|
||||
$return['groupsBy'] = $groupsBy;
|
||||
|
||||
$return['data']['data'] = alerts_get_alert_fired(
|
||||
$filters,
|
||||
$groupsBy,
|
||||
false
|
||||
);
|
||||
|
||||
if ((bool) $show_summary === true) {
|
||||
$return['data']['summary'] = alerts_get_alert_fired(
|
||||
$filters,
|
||||
$groupsBy,
|
||||
true
|
||||
);
|
||||
}
|
||||
$return['data'] = alerts_get_alert_fired($filters, $groupsBy);
|
||||
|
||||
return reporting_check_structure_content($return);
|
||||
}
|
||||
|
|
|
@ -2733,12 +2733,18 @@ 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)
|
||||
{
|
||||
hd(6);
|
||||
|
||||
$data = $item['data'];
|
||||
$filters = $item['filters'];
|
||||
$groupsBy = $item['groupsBy'];
|
||||
|
||||
$output = '';
|
||||
|
@ -2795,14 +2801,19 @@ function get_alert_table($data)
|
|||
$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] = $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][$name] = $value;
|
||||
$table->data[$key][] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue