Working in the refactoring the code of reports (network_interfaces_report).
This commit is contained in:
parent
befd3bedbf
commit
1d0bab4b64
|
@ -348,12 +348,115 @@ function reporting_make_reporting_data($id_report, $date, $time,
|
|||
$report,
|
||||
$content);
|
||||
break;
|
||||
case 'network_interfaces_report':
|
||||
$report['contents'][] = reporting_network_interfaces_report(
|
||||
$report,
|
||||
$content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return reporting_check_structure_report($report);
|
||||
}
|
||||
|
||||
function reporting_network_interfaces_report($report, $content,
|
||||
$type = 'dinamic', $force_width_chart = null, $force_height_chart = null) {
|
||||
|
||||
global $config;
|
||||
|
||||
$return['type'] = 'network_interfaces_report';
|
||||
|
||||
if (empty($content['name'])) {
|
||||
$content['name'] = __('Network interfaces report');
|
||||
}
|
||||
|
||||
$group_name = groups_get_name($content['id_group']);
|
||||
|
||||
$return['title'] = $content['name'];
|
||||
$return['subtitle'] = $group_name;
|
||||
$return["description"] = $content["description"];
|
||||
$return["date"] = reporting_get_date_text($report, $content);
|
||||
|
||||
include_once($config['homedir'] . "/include/functions_custom_graphs.php");
|
||||
|
||||
$filter = array(
|
||||
'id_grupo' => $content['id_group'],
|
||||
'disabled' => 0);
|
||||
$network_interfaces_by_agents = agents_get_network_interfaces(false, $filter);
|
||||
|
||||
if (empty($network_interfaces_by_agents)) {
|
||||
$return['error'] = 1;
|
||||
$return['data'] = array();
|
||||
}
|
||||
else {
|
||||
$return['error'] = 0;
|
||||
$return['data'] = array();
|
||||
|
||||
foreach ($network_interfaces_by_agents as $agent_id => $agent) {
|
||||
$row_data = array();
|
||||
|
||||
$row_data['agent'] = $agent['name'];
|
||||
|
||||
$row_data['interfaces'] = array();
|
||||
foreach ($agent['interfaces'] as $interface_name => $interface) {
|
||||
$row_interface = array();
|
||||
|
||||
$row_interface['name'] = $interface_name;
|
||||
$row_interface['ip'] = $interface['ip'];
|
||||
$row_interface['mac'] = $interface['mac'];
|
||||
$row_interface['status'] = $interface['status_image'];
|
||||
$row_interface['chart'] = null;
|
||||
|
||||
// Get chart
|
||||
reporting_set_conf_charts($width, $height, $only_image,
|
||||
$type, $content, $ttl);
|
||||
|
||||
if (!empty($force_width_chart)) {
|
||||
$width = $force_width_chart;
|
||||
}
|
||||
|
||||
if (!empty($force_height_chart)) {
|
||||
$height = $force_height_chart;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'dinamic':
|
||||
case 'static':
|
||||
if (!empty($interface['traffic'])) {
|
||||
$row_interface['chart'] = custom_graphs_print(0,
|
||||
$height,
|
||||
$width,
|
||||
$content['period'],
|
||||
null,
|
||||
true,
|
||||
$report["datetime"],
|
||||
$only_image,
|
||||
'white',
|
||||
array_values($interface['traffic']),
|
||||
$config['homeurl'],
|
||||
array_keys($interface['traffic']),
|
||||
array_fill(0, count($interface['traffic']), __("bytes/s")),
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
$ttl);
|
||||
}
|
||||
break;
|
||||
case 'data':
|
||||
break;
|
||||
}
|
||||
|
||||
$row_data['interfaces'][] = $row_interface;
|
||||
}
|
||||
|
||||
$return['data'][] = $row_data;
|
||||
}
|
||||
}
|
||||
|
||||
return reporting_check_structure_content($return);
|
||||
}
|
||||
|
||||
function reporting_alert_report_group($report, $content) {
|
||||
|
||||
global $config;
|
||||
|
@ -2078,14 +2181,16 @@ function reporting_check_structure_content($report) {
|
|||
return $report;
|
||||
}
|
||||
|
||||
function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, $content) {
|
||||
function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, $content, &$ttl) {
|
||||
switch ($type) {
|
||||
case 'dinamic':
|
||||
$only_image = false;
|
||||
$width = 900;
|
||||
$height = 230;
|
||||
$ttl = 1;
|
||||
break;
|
||||
case 'static':
|
||||
$ttl = 2;
|
||||
$only_image = true;
|
||||
if ($content['style']['show_in_landscape']) {
|
||||
$height = 1100;
|
||||
|
|
|
@ -218,6 +218,9 @@ function reporting_html_print_report($report, $mini = false) {
|
|||
case 'alert_report_group':
|
||||
reporting_html_alert_report_group($table, $item);
|
||||
break;
|
||||
case 'network_interfaces_report':
|
||||
reporting_html_network_interfaces_report($table, $item);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($item['type'] == 'agent_module')
|
||||
|
@ -230,6 +233,68 @@ function reporting_html_print_report($report, $mini = false) {
|
|||
}
|
||||
}
|
||||
|
||||
function reporting_html_network_interfaces_report($table, $item) {
|
||||
|
||||
if ($item['error']) {
|
||||
$table->colspan['interfaces']['cell'] = 3;
|
||||
$table->cellstyle['interfaces']['cell'] = 'text-align: left;';
|
||||
$table->data['interfaces']['cell'] =
|
||||
__('The group has no agents or none of the agents has any network interface');
|
||||
}
|
||||
else {
|
||||
|
||||
foreach ($item['data'] as $agent) {
|
||||
$table_agent = new StdCLass();
|
||||
$table_agent->width = '100%';
|
||||
$table_agent->data = array();
|
||||
$table_agent->head = array();
|
||||
$table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']);
|
||||
$table_agent->headstyle = array();
|
||||
$table_agent->headstyle[0] = 'font-size: 16px;';
|
||||
$table_agent->style[0] = 'text-align: center';
|
||||
|
||||
$table_agent->data['interfaces'] = "";
|
||||
|
||||
foreach ($agent['interfaces'] as $interface) {
|
||||
$table_interface = new StdClass();
|
||||
$table_interface->width = '100%';
|
||||
$table_interface->data = array();
|
||||
$table_interface->rowstyle = array();
|
||||
$table_interface->head = array();
|
||||
$table_interface->cellstyle = array();
|
||||
$table_interface->title = sprintf(__("Interface '%s' throughput graph"),
|
||||
$interface['name']);
|
||||
$table_interface->head['ip'] = __('IP');
|
||||
$table_interface->head['mac'] = __('Mac');
|
||||
$table_interface->head['status'] = __('Actual status');
|
||||
$table_interface->style['ip'] = 'text-align: left';
|
||||
$table_interface->style['mac'] = 'text-align: left';
|
||||
$table_interface->style['status'] = 'width: 150px; text-align: center';
|
||||
|
||||
$data = array();
|
||||
$data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--";
|
||||
$data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--";
|
||||
$data['status'] = $interface['status_image'];
|
||||
$table_interface->data['data'] = $data;
|
||||
|
||||
if (!empty($interface['chart'])) {
|
||||
$table_interface->data['graph'] = $interface['chart'];
|
||||
$table_interface->colspan['graph'][0] = 3;
|
||||
$table_interface->cellstyle['graph'][0] = 'text-align: center;';
|
||||
}
|
||||
|
||||
$table_agent->data['interfaces'] .= html_print_table($table_interface, true);
|
||||
$table_agent->colspan[$interface_name][0] = 3;
|
||||
}
|
||||
|
||||
$id = uniq_id();
|
||||
|
||||
$table->data['agents'][$id] = html_print_table($table_agent, true);
|
||||
$table->colspan[$id][0] = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reporting_html_alert_report_group($table, $item) {
|
||||
$table->colspan['alerts']['cell'] = 3;
|
||||
$table->cellstyle['alerts']['cell'] = 'text-align: left;';
|
||||
|
@ -4155,9 +4220,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
|
|||
</table>";
|
||||
|
||||
break;
|
||||
case 'network_interfaces_report':
|
||||
reporting_network_interfaces_table($content, $report, $mini, $item_title, $table);
|
||||
break;
|
||||
|
||||
case 'top_n':
|
||||
$top_n = $content['top_n'];
|
||||
|
||||
|
@ -5494,167 +5557,6 @@ function reporting_get_count_events_validated ($filter, $period = 0,
|
|||
$filter_event_warning, $filter_event_no_validated);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function reporting_network_interfaces_table ($content, $report, $mini, $item_title = "", &$table = null, &$pdf = null) {
|
||||
global $config;
|
||||
|
||||
include_once($config['homedir'] . "/include/functions_custom_graphs.php");
|
||||
|
||||
if (empty($item_title)) {
|
||||
$group_name = groups_get_name($content['id_group']);
|
||||
$item_title = __('Network interfaces') . " - " . sprintf(__('Group "%s"'), $group_name);
|
||||
}
|
||||
|
||||
$is_html = $table !== null;
|
||||
$is_pdf = $pdf !== null;
|
||||
|
||||
$ttl = $is_pdf ? 2 : 1;
|
||||
|
||||
$graph_width = 900;
|
||||
$graph_height = 200;
|
||||
|
||||
$datetime = $report['datetime'];
|
||||
$period = $content['period'];
|
||||
|
||||
if ($is_pdf) {
|
||||
$graph_width = 800;
|
||||
$graph_height = 200;
|
||||
pdf_header_content($pdf, $content, $report, $item_title, false, $content["description"]);
|
||||
}
|
||||
else if ($is_html) {
|
||||
reporting_header_content($mini, $content, $report, $table, $item_title);
|
||||
|
||||
//RUNNING
|
||||
$table->style[1] = 'text-align: right';
|
||||
|
||||
// Put description at the end of the module (if exists)
|
||||
$table->colspan[0][1] = 2;
|
||||
$next_row = 1;
|
||||
if ($content["description"] != "") {
|
||||
$table->colspan[$next_row][0] = 3;
|
||||
$next_row++;
|
||||
$data_desc = array();
|
||||
$data_desc[0] = $content["description"];
|
||||
array_push ($table->data, $data_desc);
|
||||
}
|
||||
}
|
||||
|
||||
$filter = array(
|
||||
'id_grupo' => $content['id_group'],
|
||||
'disabled' => 0
|
||||
);
|
||||
$network_interfaces_by_agents = agents_get_network_interfaces(false, $filter);
|
||||
|
||||
if (empty($network_interfaces_by_agents)) {
|
||||
if ($is_pdf) {
|
||||
$pdf->addHTML(__('The group has no agents or none of the agents has any network interface'));
|
||||
}
|
||||
else if ($is_html) {
|
||||
$data = array();
|
||||
$data[0] = __('The group has no agents or none of the agents has any network interface');
|
||||
$table->colspan[$next_row][0] = 3;
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
foreach ($network_interfaces_by_agents as $agent_id => $agent) {
|
||||
|
||||
$table_agent = new StdCLass();
|
||||
$table_agent->width = '100%';
|
||||
$table_agent->data = array();
|
||||
$table_agent->head = array();
|
||||
$table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']);
|
||||
$table_agent->headstyle = array();
|
||||
$table_agent->headstyle[0] = 'font-size: 16px;';
|
||||
$table_agent->style[0] = 'text-align: center';
|
||||
|
||||
if ($is_pdf) {
|
||||
$table_agent->class = 'table_sla table_beauty';
|
||||
$table_agent->headstyle[0] = 'background: #373737; color: #FFF; display: table-cell; font-size: 16px; border: 1px solid grey';
|
||||
}
|
||||
|
||||
$table_agent->data['interfaces'] = "";
|
||||
|
||||
foreach ($agent['interfaces'] as $interface_name => $interface) {
|
||||
$table_interface = new StdClass();
|
||||
$table_interface->width = '100%';
|
||||
$table_interface->data = array();
|
||||
$table_interface->rowstyle = array();
|
||||
$table_interface->head = array();
|
||||
$table_interface->cellstyle = array();
|
||||
$table_interface->title = sprintf(__("Interface '%s' throughput graph"), $interface_name);
|
||||
$table_interface->head['ip'] = __('IP');
|
||||
$table_interface->head['mac'] = __('Mac');
|
||||
$table_interface->head['status'] = __('Actual status');
|
||||
$table_interface->style['ip'] = 'text-align: left';
|
||||
$table_interface->style['mac'] = 'text-align: left';
|
||||
$table_interface->style['status'] = 'width: 150px; text-align: center';
|
||||
|
||||
if ($is_pdf) {
|
||||
$table_interface->class = 'table_sla table_beauty';
|
||||
$table_interface->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey';
|
||||
|
||||
$table_interface->headstyle['ip'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey';
|
||||
$table_interface->headstyle['mac'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey';
|
||||
$table_interface->headstyle['status'] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey';
|
||||
|
||||
$table_interface->style['ip'] = 'text-align: left; display: table-cell; font-size: 10px;';
|
||||
$table_interface->style['mac'] = 'text-align: left; display: table-cell; font-size: 10px;';
|
||||
$table_interface->style['status'] = 'text-align: center; display: table-cell; font-size: 10px;';
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--";
|
||||
$data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--";
|
||||
$data['status'] = $interface['status_image'];
|
||||
$table_interface->data['data'] = $data;
|
||||
|
||||
if (!empty($interface['traffic'])) {
|
||||
|
||||
$only_image = !(bool)$config['flash_charts'] || $is_pdf ? true : false;
|
||||
|
||||
$graph = custom_graphs_print(0,
|
||||
$graph_height,
|
||||
$graph_width,
|
||||
$period,
|
||||
null,
|
||||
true,
|
||||
$date,
|
||||
$only_image,
|
||||
'white',
|
||||
array_values($interface['traffic']),
|
||||
$config['homeurl'],
|
||||
array_keys($interface['traffic']),
|
||||
array_fill(0, count($interface['traffic']),"bytes/s"),
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
$ttl);
|
||||
|
||||
$table_interface->data['graph'] = $graph;
|
||||
$table_interface->colspan['graph'][0] = count($table_interface->head);
|
||||
$table_interface->cellstyle['graph'][0] = 'text-align: center;';
|
||||
}
|
||||
|
||||
$table_agent->data['interfaces'] .= html_print_table($table_interface, true);
|
||||
$table_agent->colspan[$interface_name][0] = 3;
|
||||
}
|
||||
|
||||
if ($is_html) {
|
||||
$table->data[$agent_id] = html_print_table($table_agent, true);
|
||||
$table->colspan[$agent_id][0] = 3;
|
||||
}
|
||||
else if ($is_pdf) {
|
||||
$html = html_print_table($table_agent, true);
|
||||
$pdf->addHTML($html);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) {
|
||||
global $config;
|
||||
|
||||
|
|
Loading…
Reference in New Issue