Working in the refactoring the code of reports (group_configuration).

This commit is contained in:
mdtrooper 2015-04-15 21:00:17 +02:00
parent 1d0bab4b64
commit 713988d674
2 changed files with 73 additions and 166 deletions

View File

@ -353,12 +353,58 @@ function reporting_make_reporting_data($id_report, $date, $time,
$report,
$content);
break;
case 'group_configuration':
$report['contents'][] = reporting_group_configuration(
$report,
$content);
break;
}
}
return reporting_check_structure_report($report);
}
function reporting_group_configuration($report, $content) {
global $config;
$return['type'] = 'group_configuration';
if (empty($content['name'])) {
$content['name'] = __('Group configuration');
}
$group_name = groups_get_name($content['id_group'], true);
$return['title'] = $content['name'];
$return['subtitle'] = $group_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['id_group'] = $content['id_group'];
if ($content['id_group'] == 0) {
$sql = "SELECT * FROM tagente;";
}
else {
$sql = "SELECT * FROM tagente WHERE id_grupo=" . $content['id_group'];
}
$agents_list = db_get_all_rows_sql($sql);
if ($agents_list === false)
$agents_list = array();
$return['data'] = array();
foreach ($agents_list as $agent) {
$content_agent = $content;
$content_agent['id_agent'] = $agent['id_agente'];
$agent_report = reporting_agent_configuration($report, $content_agent);
$return['data'][] = $agent_report['data'];
}
return reporting_check_structure_content($return);
}
function reporting_network_interfaces_report($report, $content,
$type = 'dinamic', $force_width_chart = null, $force_height_chart = null) {
@ -1192,8 +1238,11 @@ function reporting_agent_configuration($report, $content) {
$tags = db_get_all_rows_sql($sql_tag);
if ($tags === false)
$data_module['tags'] = array();
else
$data_module['tags'] = $tags;
else {
foreach ($tags as $tag) {
$data_module['tags'][] = $tag['name'];
}
}
$agent_configuration['modules'][] = $data_module;
}

View File

@ -221,6 +221,9 @@ function reporting_html_print_report($report, $mini = false) {
case 'network_interfaces_report':
reporting_html_network_interfaces_report($table, $item);
break;
case 'group_configuration':
reporting_html_group_configuration($table, $item);
break;
}
if ($item['type'] == 'agent_module')
@ -233,6 +236,25 @@ function reporting_html_print_report($report, $mini = false) {
}
}
function reporting_html_group_configuration($table, $item) {
$table1->width = '100%';
$table1->head = array ();
$table1->data = array ();
$cell = "";
foreach ($item['data'] as $agent) {
$table2->width = '100%';
$table2->data = array ();
reporting_html_agent_configuration(&$table2, array('data' => $agent));
$cell .= html_print_table($table2, true);
}
$table->colspan['group_configuration']['cell'] = 3;
$table->cellstyle['group_configuration']['cell'] = 'text-align: center;';
$table->data['group_configuration']['cell'] = $cell;
}
function reporting_html_network_interfaces_report($table, $item) {
if ($item['error']) {
@ -5221,170 +5243,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table->data, $data);
break;
case 'group_configuration':
$group_name = groups_get_name($content['id_group']);
if (empty($item_title)) {
$item_title = __('Group configuration: ').$group_name;
}
reporting_header_content($mini, $content, $report, $table, $item_title);
$sql = "SELECT * FROM tagente WHERE id_grupo=".$content['id_group'];
$agents_list = db_get_all_rows_sql($sql);
if ($agents_list === false)
$agents_list = array();
$table->colspan[0][1] = 10;
$i = 1;
foreach ($agents_list as $agent) {
$data= array ();
$table->colspan[$i][3] = 2;
$table->colspan[$i][4] = 4;
$table->colspan[$i][5] = 2;
$table->colspan[$i][5] = 2;
$i++;
//Agent's data
$data[0] = '<b>'.__('Agent name').'</b>';
$data[1] = '<b>'.__('Group').'</b>';
$data[2] = '<b>'.__('SO').'</b>';
$data[3] = '<b>'.__('IP').'</b>';
$data[4] = '<b>'.__('Description').'</b>';
$data[5] = '<b>'.__('Status').'</b>';
array_push ($table->data, $data);
unset($data);
$sql = "SELECT * FROM tagente WHERE id_agente=".$agent['id_agente'];
$agent_data = db_get_row_sql($sql);
$data[0] = $agent_data['nombre'];
$data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false);
$data[2] = ui_print_os_icon ($agent_data["id_os"], true, true);
$data[3] = $agent_data['direccion'];
$agent_data_comentarios = strip_tags(ui_bbcode_to_html($agent_data['comentarios']));
$data[4] = $agent_data_comentarios;
if ($agent_data['disabled'] == 0)
$data[5] = __('Enabled');
else
$data[5] = __('Disabled');
$table->colspan[$i][3] = 2;
$table->colspan[$i][4] = 4;
$table->colspan[$i][5] = 2;
$table->colspan[$i][5] = 2;
$i++;
array_push ($table->data, $data);
unset($data);
$modules = agents_get_modules ($agent['id_agente']);
if ($modules == null) {
$modules = array();
}
else {
//Agent's modules
$data[0] = '';
$data[1] = '<b>'.agents_get_name ($agent['id_agente'], 'upper').__(' MODULES').'</b>';
$table->colspan[$i][1] = 10;
$i++;
array_push ($table->data, $data);
unset($data);
$data[0] = '';
$data[1] = '<b>'.__('Name').'</b>';
$data[2] = '<b>'.__('Type').'</b>';
$data[3] = '<b>'.__('Warning').'/'.'<br>'.__('Critical').'</b>';
$data[4] = '<b>'.__('Threshold').'</b>';
$data[5] = '<b>'.__('Group').'</b>';
$data[6] = '<b>'.__('Description').'</b>';
$data[7] = '<b>'.__('Interval').'</b>';
$data[8] = '<b>'.__('Unit').'</b>';
$data[9] = '<b>'.__('Status').'</b>';
$data[10] = '<b>'.__('Tags').'</b>';
$table->style[0] = 'width:10px';
$table->style[1] = 'text-align: left';
$table->style[2] = 'text-align: center';
$table->style[3] = 'text-align: center';
$table->style[4] = 'text-align: center';
$table->style[5] = 'text-align: center';
$table->style[6] = 'text-align: left';
$table->style[7] = 'text-align: center';
$table->style[8] = 'text-align: center';
$table->style[9] = 'text-align: left';
$table->style[10] = 'text-align: left';
array_push ($table->data, $data);
$i++;
}
foreach ($modules as $id_agent_module=>$module) {
$sql = "SELECT *
FROM tagente_modulo
WHERE id_agente_modulo=$id_agent_module";
$data_module = db_get_row_sql($sql);
$data = array();
$data[0] = '';
if ($data_module['disabled'] == 0)
$disabled = '';
else
$disabled = ' (Disabled)';
$data[1] = $data_module['nombre'].$disabled;
$data[2] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true);
$data[3] = $data_module['max_warning'].'/'.$data_module['min_warning'].' <br> '.$data_module['max_critical'].'/'.$data_module['min_critical'];
$data[4] = $data_module['module_ff_interval'];
$data[5] = groups_get_name ($content['id_group'], true);
$data[6] = $data_module['descripcion'];
if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == ''))
$data[7] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']);
else
$data[7] = $data_module['module_interval'];
$data[8] = $data_module['unit'];
$module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module);
modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title);
$data[9] = ui_print_status_image($status, $title, true);
$sql_tag = "SELECT name
FROM ttag
WHERE id_tag IN (
SELECT id_tag
FROM ttag_module
WHERE id_agente_modulo = $id_agent_module)";
$tags = db_get_all_rows_sql($sql_tag);
if ($tags === false)
$tags = '';
else
$tags = implode (",", $tags);
$data[10] = $tags;
array_push ($table->data, $data);
$i++;
}
}
break;
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) {