Fixed Event reports pie graphs in metaconsole

Former-commit-id: 6fe0eb4035200dc4e22736098b810f31194e1a45
This commit is contained in:
samucarc 2019-01-16 19:44:29 +01:00
parent 6ba8b9ab9a
commit 6e8e5d0dd6
2 changed files with 57 additions and 25 deletions

View File

@ -2710,7 +2710,7 @@ function events_clean_tags ($tags) {
*/ */
function events_get_count_events_by_agent ($id_group, $period, $date, function events_get_count_events_by_agent ($id_group, $period, $date,
$filter_event_severity = false, $filter_event_type = false, $filter_event_severity = false, $filter_event_type = false,
$filter_event_status = false, $filter_event_filter_search = false) { $filter_event_status = false, $filter_event_filter_search = false, $dbmeta = false) {
global $config; global $config;
@ -2802,16 +2802,22 @@ function events_get_count_events_by_agent ($id_group, $period, $date,
' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")'; ' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")';
} }
$tagente = 'tagente';
$tevento = 'tevento';
if($dbmeta){
$tagente = 'tmetaconsole_agent';
$tevento = 'tmetaconsole_event';
}
$sql = sprintf ('SELECT id_agente, $sql = sprintf ('SELECT id_agente,
(SELECT t2.alias (SELECT t2.alias
FROM tagente t2 FROM %s t2
WHERE t2.id_agente = t3.id_agente) AS agent_name, WHERE t2.id_agente = t3.id_agente) AS agent_name,
COUNT(*) AS count COUNT(*) AS count
FROM tevento t3 FROM %s t3
WHERE utimestamp > %d AND utimestamp <= %d WHERE utimestamp > %d AND utimestamp <= %d
AND id_grupo IN (%s) %s AND id_grupo IN (%s) %s
GROUP BY id_agente', GROUP BY id_agente',
$datelimit, $date, implode (",", $id_group), $sql_where); $tagente, $tevento, $datelimit, $date, implode (",", $id_group), $sql_where);
$rows = db_get_all_rows_sql ($sql); $rows = db_get_all_rows_sql ($sql);
@ -2843,7 +2849,7 @@ function events_get_count_events_by_agent ($id_group, $period, $date,
*/ */
function events_get_count_events_validated_by_user ($filter, $period, $date, function events_get_count_events_validated_by_user ($filter, $period, $date,
$filter_event_severity = false, $filter_event_type = false, $filter_event_severity = false, $filter_event_type = false,
$filter_event_status = false, $filter_event_filter_search = false) { $filter_event_status = false, $filter_event_filter_search = false, $dbmeta = false) {
global $config; global $config;
//group //group
$sql_filter = ' AND 1=1 '; $sql_filter = ' AND 1=1 ';
@ -2949,16 +2955,20 @@ function events_get_count_events_validated_by_user ($filter, $period, $date,
' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")'; ' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")';
} }
$tevento = 'tevento';
if($dbmeta)
$tevento = 'tmetaconsole_event';
$sql = sprintf ('SELECT id_usuario, $sql = sprintf ('SELECT id_usuario,
(SELECT t2.fullname (SELECT t2.fullname
FROM tusuario t2 FROM tusuario t2
WHERE t2.id_user = t3.id_usuario) AS user_name, WHERE t2.id_user = t3.id_usuario) AS user_name,
COUNT(*) AS count COUNT(*) AS count
FROM tevento t3 FROM %s t3
WHERE utimestamp > %d AND utimestamp <= %d WHERE utimestamp > %d AND utimestamp <= %d
%s %s %s %s
GROUP BY id_usuario', GROUP BY id_usuario',
$datelimit, $date, $sql_filter, $sql_where); $tevento, $datelimit, $date, $sql_filter, $sql_where);
$rows = db_get_all_rows_sql ($sql); $rows = db_get_all_rows_sql ($sql);
if ($rows == false) if ($rows == false)
@ -2988,7 +2998,7 @@ function events_get_count_events_validated_by_user ($filter, $period, $date,
*/ */
function events_get_count_events_by_criticity ($filter, $period, $date, function events_get_count_events_by_criticity ($filter, $period, $date,
$filter_event_severity = false, $filter_event_type = false, $filter_event_severity = false, $filter_event_type = false,
$filter_event_status = false, $filter_event_filter_search = false) { $filter_event_status = false, $filter_event_filter_search = false, $dbmeta = false) {
global $config; global $config;
@ -3094,13 +3104,16 @@ function events_get_count_events_by_criticity ($filter, $period, $date,
' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")'; ' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")';
} }
$tevento = 'tevento';
if ($dbmeta)
$tevento = 'tmetaconsole_event';
$sql = sprintf ('SELECT criticity, $sql = sprintf ('SELECT criticity,
COUNT(*) AS count COUNT(*) AS count
FROM tevento FROM %s
WHERE utimestamp > %d AND utimestamp <= %d WHERE utimestamp > %d AND utimestamp <= %d
%s %s %s %s
GROUP BY criticity', GROUP BY criticity',
$datelimit, $date, $sql_filter, $sql_where); $tevento, $datelimit, $date, $sql_filter, $sql_where);
$rows = db_get_all_rows_sql ($sql); $rows = db_get_all_rows_sql ($sql);
@ -3128,7 +3141,7 @@ function events_get_count_events_by_criticity ($filter, $period, $date,
*/ */
function events_get_count_events_validated ($filter, $period = null, $date = null, function events_get_count_events_validated ($filter, $period = null, $date = null,
$filter_event_severity = false, $filter_event_type = false, $filter_event_severity = false, $filter_event_type = false,
$filter_event_status = false, $filter_event_filter_search = false) { $filter_event_status = false, $filter_event_filter_search = false, $dbmeta = false) {
global $config; global $config;
@ -3252,7 +3265,10 @@ function events_get_count_events_validated ($filter, $period = null, $date = nul
' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")'; ' OR id_evento LIKE "%' . io_safe_input($filter_event_filter_search) . '%")';
} }
$sql = sprintf ("SELECT estado, COUNT(*) AS count FROM tevento WHERE %s %s GROUP BY estado", $sql_filter, $sql_where); $tevento = 'tevento';
if ($dbmeta)
$tevento = 'tmetaconsole_event';
$sql = sprintf ("SELECT estado, COUNT(*) AS count FROM %s WHERE %s %s GROUP BY estado", $tevento, $sql_filter, $sql_where);
$rows = db_get_all_rows_sql ($sql); $rows = db_get_all_rows_sql ($sql);

View File

@ -1532,12 +1532,17 @@ function reporting_event_report_group($report, $content,
$return['chart']['by_user_validator'] = null; $return['chart']['by_user_validator'] = null;
$return['chart']['by_criticity'] = null; $return['chart']['by_criticity'] = null;
$return['chart']['validated_vs_unvalidated'] = null; $return['chart']['validated_vs_unvalidated'] = null;
$server_name = $content['server_name'];
if (is_metaconsole() && $server_name != '')
$metaconsole_dbtable = true;
else
$metaconsole_dbtable = false;
if ($event_graph_by_agent) { if ($event_graph_by_agent) {
$data_graph = events_get_count_events_by_agent( $data_graph = events_get_count_events_by_agent(
$content['id_group'], $content['period'], $report["datetime"], $content['id_group'], $content['period'], $report["datetime"],
$filter_event_severity, $filter_event_type, $filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search); $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$return['chart']['by_agent']= pie_graph( $return['chart']['by_agent']= pie_graph(
$data_graph, $data_graph,
@ -1556,7 +1561,7 @@ function reporting_event_report_group($report, $content,
$data_graph = events_get_count_events_validated_by_user( $data_graph = events_get_count_events_validated_by_user(
array('id_group' => $content['id_group']), $content['period'], array('id_group' => $content['id_group']), $content['period'],
$report["datetime"],$filter_event_severity, $filter_event_type, $report["datetime"],$filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search); $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$return['chart']['by_user_validator'] = pie_graph( $return['chart']['by_user_validator'] = pie_graph(
$data_graph, $data_graph,
@ -1575,7 +1580,7 @@ function reporting_event_report_group($report, $content,
$data_graph = events_get_count_events_by_criticity( $data_graph = events_get_count_events_by_criticity(
array('id_group' => $content['id_group']), $content['period'], array('id_group' => $content['id_group']), $content['period'],
$report["datetime"],$filter_event_severity, $filter_event_type, $report["datetime"],$filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search); $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$colors = get_criticity_pie_colors($data_graph); $colors = get_criticity_pie_colors($data_graph);
@ -1598,7 +1603,7 @@ function reporting_event_report_group($report, $content,
$data_graph = events_get_count_events_validated( $data_graph = events_get_count_events_validated(
array('id_group' => $content['id_group']), $content['period'], array('id_group' => $content['id_group']), $content['period'],
$report["datetime"],$filter_event_severity, $filter_event_type, $report["datetime"],$filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search); $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$return['chart']['validated_vs_unvalidated'] = pie_graph( $return['chart']['validated_vs_unvalidated'] = pie_graph(
$data_graph, $data_graph,
@ -1679,13 +1684,19 @@ function reporting_event_report_module($report, $content,
$event_graph_by_criticity = $event_filter['event_graph_by_criticity']; $event_graph_by_criticity = $event_filter['event_graph_by_criticity'];
$event_graph_validated_vs_unvalidated = $event_filter['event_graph_validated_vs_unvalidated']; $event_graph_validated_vs_unvalidated = $event_filter['event_graph_validated_vs_unvalidated'];
$server_name = $content['server_name'];
if (is_metaconsole() && $server_name != '')
$metaconsole_dbtable = true;
else
$metaconsole_dbtable = false;
//data events //data events
$data = reporting_get_module_detailed_event ( $data = reporting_get_module_detailed_event (
$content['id_agent_module'], $content['period'], $report["datetime"], $content['id_agent_module'], $content['period'], $report["datetime"],
$show_summary_group, $filter_event_severity, $filter_event_type, $show_summary_group, $filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search, $force_width_chart, $filter_event_status, $filter_event_filter_search, $force_width_chart,
$event_graph_by_user_validator, $event_graph_by_criticity, $event_graph_by_user_validator, $event_graph_by_criticity,
$event_graph_validated_vs_unvalidated, $ttl, $id_server); $event_graph_validated_vs_unvalidated, $ttl, $id_server, $metaconsole_dbtable);
if (empty($data)) { if (empty($data)) {
$return['failed'] = __('No events'); $return['failed'] = __('No events');
@ -2449,11 +2460,16 @@ function reporting_event_report_agent($report, $content,
$return["chart"]["by_criticity"] = null; $return["chart"]["by_criticity"] = null;
$return["chart"]["validated_vs_unvalidated"] = null; $return["chart"]["validated_vs_unvalidated"] = null;
$server_name = $content['server_name'];
if (is_metaconsole() && $server_name != '')
$metaconsole_dbtable = true;
else
$metaconsole_dbtable = false;
if ($event_graph_by_user_validator) { if ($event_graph_by_user_validator) {
$data_graph = events_get_count_events_validated_by_user( $data_graph = events_get_count_events_validated_by_user(
array('id_agent' => $content['id_agent']), $content['period'], array('id_agent' => $content['id_agent']), $content['period'],
$report["datetime"],$filter_event_severity, $filter_event_type, $report["datetime"],$filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search); $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$return["chart"]["by_user_validator"] = pie_graph( $return["chart"]["by_user_validator"] = pie_graph(
$data_graph, $data_graph,
@ -2472,7 +2488,7 @@ function reporting_event_report_agent($report, $content,
$data_graph = events_get_count_events_by_criticity( $data_graph = events_get_count_events_by_criticity(
array('id_agent' => $content['id_agent']), $content['period'], array('id_agent' => $content['id_agent']), $content['period'],
$report["datetime"],$filter_event_severity, $filter_event_type, $report["datetime"],$filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search); $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$colors = get_criticity_pie_colors($data_graph); $colors = get_criticity_pie_colors($data_graph);
@ -2495,7 +2511,7 @@ function reporting_event_report_agent($report, $content,
$data_graph = events_get_count_events_validated( $data_graph = events_get_count_events_validated(
array('id_agent' => $content['id_agent']), $content['period'], array('id_agent' => $content['id_agent']), $content['period'],
$report["datetime"],$filter_event_severity, $filter_event_type, $report["datetime"],$filter_event_severity, $filter_event_type,
$filter_event_status, $filter_event_filter_search); $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$return["chart"]["validated_vs_unvalidated"] = pie_graph( $return["chart"]["validated_vs_unvalidated"] = pie_graph(
$data_graph, $data_graph,
@ -6681,7 +6697,7 @@ function reporting_get_module_detailed_event ($id_modules, $period = 0,
$filter_event_type = false, $filter_event_status = false, $filter_event_type = false, $filter_event_status = false,
$filter_event_filter_search = false, $force_width_chart = false, $filter_event_filter_search = false, $force_width_chart = false,
$event_graph_by_user_validator = false, $event_graph_by_criticity = false, $event_graph_by_user_validator = false, $event_graph_by_criticity = false,
$event_graph_validated_vs_unvalidated = false, $ttl = 1, $id_server = false) { $event_graph_validated_vs_unvalidated = false, $ttl = 1, $id_server = false, $metaconsole_dbtable = false) {
global $config; global $config;
@ -6726,7 +6742,7 @@ function reporting_get_module_detailed_event ($id_modules, $period = 0,
if ($event_graph_by_user_validator) { if ($event_graph_by_user_validator) {
$data_graph = events_get_count_events_validated_by_user( $data_graph = events_get_count_events_validated_by_user(
array('id_agentmodule' => $id_module), $period, $date, $filter_event_severity, array('id_agentmodule' => $id_module), $period, $date, $filter_event_severity,
$filter_event_type, $filter_event_status, $filter_event_filter_search); $filter_event_type, $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$event['chart']['by_user_validator'] = pie_graph( $event['chart']['by_user_validator'] = pie_graph(
$data_graph, $data_graph,
@ -6744,7 +6760,7 @@ function reporting_get_module_detailed_event ($id_modules, $period = 0,
if ($event_graph_by_criticity) { if ($event_graph_by_criticity) {
$data_graph = events_get_count_events_by_criticity( $data_graph = events_get_count_events_by_criticity(
array('id_agentmodule' => $id_module), $period, $date, $filter_event_severity, array('id_agentmodule' => $id_module), $period, $date, $filter_event_severity,
$filter_event_type, $filter_event_status, $filter_event_filter_search); $filter_event_type, $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$colors = get_criticity_pie_colors($data_graph); $colors = get_criticity_pie_colors($data_graph);
@ -6766,7 +6782,7 @@ function reporting_get_module_detailed_event ($id_modules, $period = 0,
if ($event_graph_validated_vs_unvalidated) { if ($event_graph_validated_vs_unvalidated) {
$data_graph = events_get_count_events_validated( $data_graph = events_get_count_events_validated(
array('id_agentmodule' => $id_module), $period, $date, $filter_event_severity, array('id_agentmodule' => $id_module), $period, $date, $filter_event_severity,
$filter_event_type, $filter_event_status, $filter_event_filter_search); $filter_event_type, $filter_event_status, $filter_event_filter_search, $metaconsole_dbtable);
$event['chart']['validated_vs_unvalidated'] = pie_graph( $event['chart']['validated_vs_unvalidated'] = pie_graph(
$data_graph, $data_graph,