new item report agent/modules status pandora_enterprise#7653

This commit is contained in:
Daniel Barbero Martin 2022-02-10 16:33:58 +01:00
parent af400e0043
commit 2a37503f2e
7 changed files with 354 additions and 6 deletions

View File

@ -743,6 +743,7 @@ switch ($action) {
break;
case 'agent_module':
case 'agent_module_status':
$description = $item['description'];
$es = json_decode($item['external_source'], true);
@ -4744,6 +4745,7 @@ $(document).ready (function () {
switch (type){
case 'agent_module':
case 'agent_module_status':
case 'alert_report_actions':
var agents_multiple = $('#id_agents2').val();
var modules_multiple = $('#module').val();
@ -4878,6 +4880,7 @@ $(document).ready (function () {
}
switch (type){
case 'agent_module':
case 'agent_module_status':
case 'alert_report_actions':
var agents_multiple = $('#id_agents2').val();
var modules_multiple = $('#module').val();
@ -6345,6 +6348,7 @@ function chooseType() {
break;
case 'agent_module':
case 'agent_module_status':
$("#row_description").show();
$("#row_group").show();
$("#row_module_group").show();

View File

@ -1653,6 +1653,7 @@ switch ($action) {
break;
case 'agent_module':
case 'agent_module_status':
$agents_to_report_text = get_parameter('id_agents2-multiple-text', '');
$modules_to_report_text = get_parameter('module-multiple-text', '');
@ -2454,6 +2455,7 @@ switch ($action) {
break;
case 'agent_module':
case 'agent_module_status':
$agents_to_report_text = get_parameter('id_agents2-multiple-text');
$modules_to_report_text = get_parameter('module-multiple-text', '');

View File

@ -4167,3 +4167,78 @@ function get_planned_downtime_agents_list($id_downtime, $filter_cond, $id_groups
return $agents;
}
/**
* Agent Module status and data
*
* @param integer $id_group Group
* @param array $agents Agents filter.
* @param array $modules Modules filter.
*
* @return array Result.
*/
function get_status_data_agent_modules($id_group, $agents=[], $modules=[])
{
$slq_filter_group = '';
if (empty($id_group) === false) {
$slq_filter_group = sprintf(
' AND tagente.id_group = %d',
$id_group
);
}
$slq_filter_agent = '';
if (empty($agents) === false) {
$slq_filter_agent = sprintf(
' AND tagente_modulo.id_agente IN (%s)',
implode(',', $agents)
);
}
$slq_filter_module = '';
if (empty($modules) === false) {
$slq_filter_module = sprintf(
' AND tagente_modulo.id_agente_modulo IN (%s)',
implode(',', $modules)
);
}
$sql = sprintf(
'SELECT tagente_modulo.id_agente_modulo as id_agent_module,
tagente_modulo.nombre as name_module,
tagente_modulo.unit as unit_module,
tagente_modulo.id_agente as id_agent,
tagente_estado.datos as data_module,
tagente_estado.timestamp as data_time_module,
tagente_estado.estado as status_module,
tagente.alias as name_agent,
tagente.id_grupo as id_group,
tgrupo.nombre as name_group
FROM tagente_modulo
INNER JOIN tagente_estado
ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente
LEFT JOIN tagent_secondary_group
ON tagente.id_agente = tagent_secondary_group.id_agent
INNER JOIN tgrupo
ON tagente.id_grupo = tgrupo.id_grupo
WHERE 1=1
%s
%s
%s
',
$slq_filter_group,
$slq_filter_agent,
$slq_filter_module
);
$res = db_get_all_rows_sql($sql);
if ($res === false) {
$res = [];
}
return $res;
}

View File

@ -739,6 +739,13 @@ function reporting_make_reporting_data(
);
break;
case 'agent_module_status':
$report['contents'][] = reporting_agent_module_status(
$report,
$content
);
break;
case 'alert_report_actions':
$report['contents'][] = reporting_alert_report_actions(
$report,
@ -2863,6 +2870,136 @@ function reporting_agent_module($report, $content)
}
/**
* Agents module status
*
* @param array $report Info Report.
* @param array $content Info content.
*
* @return array
*/
function reporting_agent_module_status($report, $content)
{
global $config;
$return['type'] = 'agent_module_status';
if (empty($content['name'])) {
$content['name'] = __('Agent/Modules Status');
}
$return['title'] = io_safe_output($content['name']);
$return['landscape'] = $content['landscape'];
$return['pagebreak'] = $content['pagebreak'];
$group_name = groups_get_name($content['id_group'], true);
if ($content['id_module_group'] == 0) {
$module_group_name = __('All');
} else {
$module_group_name = db_get_value(
'name',
'tmodule_group',
'id_mg',
$content['id_module_group']
);
}
$return['subtitle'] = $group_name.' - '.$module_group_name;
$return['description'] = io_safe_output($content['description']);
$return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$return['data'] = [];
$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
);
if (is_metaconsole() === true) {
$agents_per_node = [];
$modules_per_node = [];
if (empty($agents) === false) {
foreach ($agents as $value) {
$agent_array = explode('|', $value);
$agents_per_node[$agent_array[0]][] = $agent_array[1];
}
}
if (empty($modules) === false) {
foreach ($modules as $value) {
$module_array = explode('|', $value);
$modules_per_node[$module_array[0]][] = $module_array[1];
}
}
if (empty($agents_per_node) === false) {
foreach ($agents_per_node as $server => $agents) {
$connection = metaconsole_get_connection_by_id($server);
if (metaconsole_connect($connection) != NOERR) {
continue;
}
$res[$connection['server_name']] = get_status_data_agent_modules(
$content['id_group'],
$agents,
$modules_per_node[$server]
);
metaconsole_restore_db();
}
} else {
$metaconsole_connections = metaconsole_get_connection_names();
// For all nodes.
if (isset($metaconsole_connections) === true
&& is_array($metaconsole_connections) === true
) {
foreach ($metaconsole_connections as $metaconsole) {
// Get server connection data.
$server_data = metaconsole_get_connection($metaconsole);
// Establishes connection.
if (metaconsole_load_external_db($server_data) !== NOERR) {
continue;
}
$res[$server_data['server_name']] = get_status_data_agent_modules(
$content['id_group'],
$agents,
$modules
);
metaconsole_restore_db();
}
}
}
} else {
$res['node'] = get_status_data_agent_modules(
$content['id_group'],
$agents,
$modules
);
}
$return['data'] = $res;
return reporting_check_structure_content($return);
}
function reporting_exception(
$report,
$content,

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 'agent_module_status':
reporting_html_agent_module_status($table, $item);
break;
case 'alert_report_actions':
reporting_html_alert_report_actions($table, $item);
break;
@ -2000,6 +2004,125 @@ function reporting_html_agent_module($table, $item)
}
/**
* Html report agent modules status.
*
* @param object $table Head table or false if it comes from pdf.
* @param array $item Items data.
* @param integer $pdf Pdf output.
*
* @return mixed
*/
function reporting_html_agent_module_status($table, $item, $pdf=0)
{
global $config;
$return_pdf = '';
if (empty($item['data']) === true) {
if ($pdf !== 0) {
$return_pdf .= __('No items');
} else {
$table->colspan['group_report']['cell'] = 3;
$table->cellstyle['group_report']['cell'] = 'text-align: center;';
$table->data['group_report']['cell'] = __('No items');
}
} else {
$table_info = new stdClass();
$table_info->width = '99%';
$table_info->align = [];
if (is_metaconsole() === true) {
$table_info->align['server'] = 'left';
}
$table_info->align['name_group'] = 'left';
$table_info->align['name_agent'] = 'left';
$table_info->align['name_module'] = 'left';
$table_info->align['status_module'] = 'left';
$table_info->align['data_module'] = 'left';
$table_info->align['data_time_module'] = 'left';
$table_info->headstyle = [];
if (is_metaconsole() === true) {
$table_info->headstyle['server'] = 'text-align: left';
}
$table_info->headstyle['name_group'] = 'text-align: left';
$table_info->headstyle['name_agent'] = 'text-align: left';
$table_info->headstyle['name_module'] = 'text-align: left';
$table_info->headstyle['status_module'] = 'text-align: left';
$table_info->headstyle['data_module'] = 'text-align: left';
$table_info->headstyle['data_time_module'] = 'text-align: left';
$table_info->head = [];
if (is_metaconsole() === true) {
$table_info->head['server'] = __('Server');
}
$table_info->head['name_group'] = __('Group');
$table_info->head['name_agent'] = __('Agent');
$table_info->head['name_module'] = __('Module');
$table_info->head['status_module'] = __('Status');
$table_info->head['data_module'] = __('Data');
$table_info->head['data_time_module'] = __('Last time');
$table_info->data = [];
foreach ($item['data'] as $server => $info) {
foreach ($info as $data) {
$row = [];
if (is_metaconsole() === true) {
$row['server'] = $server;
}
$row['name_group'] = $data['name_group'];
$row['name_agent'] = $data['name_agent'];
$row['name_module'] = $data['name_module'];
$row['status_module'] = ui_print_module_status(
$data['status_module'],
true,
'status_rounded_rectangles',
null,
($pdf === 1) ? '       ' : ''
);
if (is_numeric($data['data_module']) === true) {
$row['data_module'] = remove_right_zeros(
number_format(
$data['data_module'],
$config['graph_precision']
)
);
} else {
$row['data_module'] = (empty($data['data_module']) === true) ? '--' : $data['data_module'];
}
$row['data_module'] .= $data['unit_module'];
$row['data_time_module'] = $data['data_time_module'];
$table_info->data[] = $row;
}
}
if ($pdf !== 0) {
$table_info->title = $item['title'];
$table_info->titleclass = 'title_table_pdf';
$table_info->titlestyle = 'text-align:left;';
$return_pdf .= html_print_table($table_info, true);
} else {
$table->colspan['data']['cell'] = 3;
$table->cellstyle['data']['cell'] = 'text-align: center;';
$table->data['data']['cell'] = html_print_table($table_info, true);
}
}
if ($pdf !== 0) {
return $return_pdf;
}
}
/**
* Function to print to HTML Exception report.
*

View File

@ -796,6 +796,11 @@ function reports_get_report_types($template=false, $not_editor=false)
}
}
$types['agent_module_status'] = [
'optgroup' => __('Grouped'),
'name' => __('Agents/Modules status'),
];
// Only pandora managers have access to the whole database.
if (check_acl($config['id_user'], 0, 'PM')) {
$types['sql'] = [

View File

@ -2737,10 +2737,11 @@ function ui_print_status_image(
/**
* Returns html code to print a shape for a module.
*
* @param integer $status Module status.
* @param boolean $return True or false.
* @param string $class Custom class or use defined.
* @param string $title Custom title or inherit from module status.
* @param integer $status Module status.
* @param boolean $return True or false.
* @param string $class Custom class or use defined.
* @param string $title Custom title or inherit from module status.
* @param string $div_content Content.
*
* @return string HTML code for shape.
*/
@ -2748,7 +2749,8 @@ function ui_print_module_status(
$status,
$return=false,
$class='status_rounded_rectangles',
$title=null
$title=null,
$div_content=''
) {
$color = modules_get_color_status($status, true);
if ($title === null) {
@ -2758,7 +2760,7 @@ function ui_print_module_status(
$output = '<div style="background: '.$color;
$output .= '" class="'.$class;
$output .= ' forced_title" data-title="'.$title.'" title="';
$output .= $title.'" data-use_title_for_force_title="1"></div>';
$output .= $title.'" data-use_title_for_force_title="1">'.$div_content.'</div>';
if ($return === false) {
echo $output;