fixed errors pdf

Former-commit-id: f7ad69f6b5e0910e5f31464ddfe94593529ef6a7
This commit is contained in:
daniel 2019-02-05 10:40:24 +01:00
parent 20e0508e01
commit 418d497291
2 changed files with 226 additions and 138 deletions

View File

@ -1,25 +1,32 @@
<?php <?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/** /**
* @package Include * Extension to manage a list of gateways and the node address where they should
* @subpackage Reporting * point to.
*
* @category Extensions
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/ */
/**
* Include the usual functions
*/
require_once $config['homedir'].'/include/functions.php'; require_once $config['homedir'].'/include/functions.php';
require_once $config['homedir'].'/include/functions_db.php'; require_once $config['homedir'].'/include/functions_db.php';
require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_agents.php';
@ -153,8 +160,6 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
$label = ''; $label = '';
} }
// $aux = explode("-",$item['subtitle']);
// $item['subtitle'] = db_get_value ("alias","tagente","nombre",$item['agent_name']) .' -'. $aux[1];
reporting_html_header( reporting_html_header(
$table, $table,
$mini, $mini,
@ -177,6 +182,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
switch ($item['type']) { switch ($item['type']) {
case 'availability': case 'availability':
default:
reporting_html_availability($table, $item); reporting_html_availability($table, $item);
break; break;
@ -380,7 +386,11 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
break; break;
case 'module_histogram_graph': case 'module_histogram_graph':
reporting_enterprise_html_module_histogram_graph($table, $item, $mini); reporting_enterprise_html_module_histogram_graph(
$table,
$item,
$mini
);
break; break;
} }
@ -399,11 +409,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
function reporting_html_SLA($table, $item, $mini, $pdf=0) function reporting_html_SLA($table, $item, $mini, $pdf=0)
{ {
if ($table === false) { $return_pdf = '';
$table = new stdClass();
$table->width = '99%';
$table->class = 'table_beauty';
}
$style = db_get_value( $style = db_get_value(
'style', 'style',
@ -411,6 +417,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
'id_rc', 'id_rc',
$item['id_rc'] $item['id_rc']
); );
$style = json_decode(io_safe_output($style), true); $style = json_decode(io_safe_output($style), true);
$same_agent_in_resume = ''; $same_agent_in_resume = '';
@ -447,7 +454,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
if (isset($item['data'])) { if (isset($item['data'])) {
$table1 = new stdClass(); $table1 = new stdClass();
$table1->width = '99%'; $table1->width = '99%';
$table1->class = 'content_table databox';
$table1->align = []; $table1->align = [];
$table1->align[0] = 'left'; $table1->align[0] = 'left';
$table1->align[1] = 'left'; $table1->align[1] = 'left';
@ -475,6 +482,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
// Second_table for time globals. // Second_table for time globals.
$table2 = new stdClass(); $table2 = new stdClass();
$table2->width = '99%'; $table2->width = '99%';
$table2->class = 'content_table';
$table2->align = []; $table2->align = [];
$table2->align[0] = 'left'; $table2->align[0] = 'left';
@ -506,6 +514,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
// Third_table for time globals. // Third_table for time globals.
$table3 = new stdClass(); $table3 = new stdClass();
$table3->width = '99%'; $table3->width = '99%';
$table3->class = 'content_table';
$table3->align = []; $table3->align = [];
$table3->align[0] = 'left'; $table3->align[0] = 'left';
@ -562,12 +571,12 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
} else if (reporting_sla_is_ignored_from_array($sla)) { } else if (reporting_sla_is_ignored_from_array($sla)) {
$row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_IGNORED.';">'.__('N/A').'</span>'; $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_IGNORED.';">'.__('N/A').'</span>';
$row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_IGNORED.';">'.__('No data').'</span>'; $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_IGNORED.';">'.__('No data').'</span>';
// Normal calculation // Normal calculation.
} else if ($sla['sla_status']) { } else if ($sla['sla_status']) {
$row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_NORMAL.';">'.sla_truncate($sla['sla_value'], $config['graph_precision']).'%'.'</span>'; $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_NORMAL.';">'.sla_truncate($sla['sla_value'], $config['graph_precision']).'%</span>';
$row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_NORMAL.';">'.__('OK').'</span>'; $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_NORMAL.';">'.__('OK').'</span>';
} else { } else {
$row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_CRITICAL.';">'.sla_truncate($sla['sla_value'], $config['graph_precision']).'%'.'</span>'; $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_CRITICAL.';">'.sla_truncate($sla['sla_value'], $config['graph_precision']).'%</span>';
$row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_CRITICAL.';">'.__('Fail').'</span>'; $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_CRITICAL.';">'.__('Fail').'</span>';
} }
@ -642,6 +651,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
} }
} }
if ($pdf === 0) {
$table->colspan['sla']['cell'] = 2; $table->colspan['sla']['cell'] = 2;
$table->data['sla']['cell'] = html_print_table( $table->data['sla']['cell'] = html_print_table(
$table1, $table1,
@ -657,12 +667,35 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
$table3, $table3,
true true
); );
} else {
$return_pdf .= '<tr><td colspan=3>';
$return_pdf .= html_print_table(
$table1,
true
);
$return_pdf .= '</td></tr>';
$return_pdf .= '<tr><td colspan=3>';
$return_pdf .= html_print_table(
$table2,
true
);
$return_pdf .= '</td></tr>';
$return_pdf .= '<tr><td colspan=3>';
$return_pdf .= html_print_table(
$table3,
true
);
$return_pdf .= '</td></tr>';
}
} else { } else {
$table->colspan['error']['cell'] = 3; $table->colspan['error']['cell'] = 3;
$table->data['error']['cell'] = __('There are no Agent/Modules defined'); $table->data['error']['cell'] = __('There are no Agent/Modules defined');
} }
if (!empty($item['charts'])) { if (!empty($item['charts'])) {
/*
$table1 = new stdClass(); $table1 = new stdClass();
$table1->width = '99%'; $table1->width = '99%';
$table1->size = []; $table1->size = [];
@ -677,11 +710,18 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
]; ];
} }
if ($pdf === 0) {
$table->colspan['charts']['cell'] = 2; $table->colspan['charts']['cell'] = 2;
$table->data['charts']['cell'] = html_print_table( $table->data['charts']['cell'] = html_print_table(
$table1, $table1,
true true
); );
} else {
$return_pdf .= html_print_table(
$table1,
true
);
}
// Table_legend_graphs. // Table_legend_graphs.
$table1 = new stdClass(); $table1 = new stdClass();
@ -718,16 +758,24 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0)
$table1->size[11] = '15%'; $table1->size[11] = '15%';
$table1->data[0][11] = '<span>'.__('Ignore time').'</span>'; $table1->data[0][11] = '<span>'.__('Ignore time').'</span>';
if ($pdf === 0) {
$table->colspan['legend']['cell'] = 2; $table->colspan['legend']['cell'] = 2;
$table->data['legend']['cell'] = html_print_table( $table->data['legend']['cell'] = html_print_table(
$table1, $table1,
true true
); );
} else {
$return_pdf .= html_print_table(
$table1,
true
);
}
*/
} }
} }
if ($pdf !== 0) { if ($pdf !== 0) {
return html_print_table($table, true); return $return_pdf;
} }
} }
@ -860,7 +908,7 @@ function reporting_html_event_report_group($table, $item, $pdf=0)
$data = []; $data = [];
// Colored box // Colored box.
switch ($event['estado']) { switch ($event['estado']) {
case 0: case 0:
$img_st = 'images/star.png'; $img_st = 'images/star.png';
@ -1075,9 +1123,10 @@ function reporting_html_event_report_module($table, $item, $pdf=0)
$table1->cellclass[$i][1] = $table1->cellclass[$i][3] = $table1->cellclass[$i][4] = get_priority_class($event['criticity']); $table1->cellclass[$i][1] = $table1->cellclass[$i][3] = $table1->cellclass[$i][4] = get_priority_class($event['criticity']);
} }
// Colored box // Colored box.
switch ($event['estado']) { switch ($event['estado']) {
case 0: case 0:
default:
$img_st = 'images/star.png'; $img_st = 'images/star.png';
$title_st = __('New event'); $title_st = __('New event');
break; break;
@ -1233,8 +1282,10 @@ function reporting_html_inventory_changes($table, $item)
foreach ($item['data'] as $module_item) { foreach ($item['data'] as $module_item) {
$table1 = null; $table1 = null;
$table1->width = '99%'; $table1->width = '99%';
$table1->cellstyle = [];
$table1->cellstyle[0][0] = $table1->cellstyle[0][1] = 'background: #373737; color: #FFF;'; $table1->cellstyle[0][0] = 'background: #373737; color: #FFF;';
$table1->cellstyle[0][1] = 'background: #373737; color: #FFF;';
$table1->data[0][0] = $module_item['agent']; $table1->data[0][0] = $module_item['agent'];
$table1->data[0][1] = $module_item['module']; $table1->data[0][1] = $module_item['module'];
@ -1700,9 +1751,10 @@ function reporting_html_event_report_agent($table, $item, $pdf=0)
} }
$data = []; $data = [];
// Colored box // Colored box.
switch ($event['status']) { switch ($event['status']) {
case 0: case 0:
default:
$img_st = 'images/star.png'; $img_st = 'images/star.png';
$title_st = __('New event'); $title_st = __('New event');
break; break;
@ -1738,7 +1790,7 @@ function reporting_html_event_report_agent($table, $item, $pdf=0)
false, false,
true true
); );
// $data[] = $event['event_type'];
$data[] = events_print_type_img($event['type'], true); $data[] = events_print_type_img($event['type'], true);
$data[] = get_priority_name($event['criticity']); $data[] = get_priority_name($event['criticity']);
@ -2361,7 +2413,7 @@ function reporting_html_url(&$table, $item, $key)
$table->data['data']['cell'] = ' $table->data['data']['cell'] = '
<iframe id="item_'.$key.'" src ="'.$item['url'].'" width="100%" height="100%"> <iframe id="item_'.$key.'" src ="'.$item['url'].'" width="100%" height="100%">
</iframe>'; </iframe>';
// TODO: make this dynamic and get the height if the iframe to resize this item // TODO: make this dynamic and get the height if the iframe to resize this item.
$table->data['data']['cell'] .= ' $table->data['data']['cell'] .= '
<script type="text/javascript"> <script type="text/javascript">
$(document).ready (function () { $(document).ready (function () {
@ -2395,7 +2447,7 @@ function reporting_html_availability(&$table, $item)
$table1->head = []; $table1->head = [];
$table1->head[0] = __('Agent'); $table1->head[0] = __('Agent');
// HACK it is saved in show_graph field. // HACK it is saved in show_graph field.
// Show interfaces instead the modules // Show interfaces instead the modules.
if ($item['kind_availability'] == 'address') { if ($item['kind_availability'] == 'address') {
$table1->head[1] = __('IP Address'); $table1->head[1] = __('IP Address');
} else { } else {
@ -2438,7 +2490,7 @@ function reporting_html_availability(&$table, $item)
$table2->head = []; $table2->head = [];
$table2->head[0] = __('Agent'); $table2->head[0] = __('Agent');
// HACK it is saved in show_graph field. // HACK it is saved in show_graph field.
// Show interfaces instead the modules // Show interfaces instead the modules.
if ($item['kind_availability'] == 'address') { if ($item['kind_availability'] == 'address') {
$table2->head[1] = __('IP Address'); $table2->head[1] = __('IP Address');
} else { } else {
@ -2449,7 +2501,7 @@ function reporting_html_availability(&$table, $item)
$table2->head[3] = __('Checks failed'); $table2->head[3] = __('Checks failed');
$table2->head[4] = __('Checks OK'); $table2->head[4] = __('Checks OK');
$table2->head[5] = __('Checks Uknown'); $table2->head[5] = __('Checks Uknown');
// $table2->head[6] = __('% Ok');
$table2->headstyle = []; $table2->headstyle = [];
$table2->headstyle[0] = 'text-align: left'; $table2->headstyle[0] = 'text-align: left';
$table2->headstyle[1] = 'text-align: left'; $table2->headstyle[1] = 'text-align: left';
@ -2457,53 +2509,73 @@ function reporting_html_availability(&$table, $item)
$table2->headstyle[3] = 'text-align: right'; $table2->headstyle[3] = 'text-align: right';
$table2->headstyle[4] = 'text-align: right'; $table2->headstyle[4] = 'text-align: right';
$table2->headstyle[5] = 'text-align: right'; $table2->headstyle[5] = 'text-align: right';
// $table2->headstyle[6] = 'text-align: right';
$table2->style[0] = 'text-align: left'; $table2->style[0] = 'text-align: left';
$table2->style[1] = 'text-align: left'; $table2->style[1] = 'text-align: left';
$table2->style[2] = 'text-align: right'; $table2->style[2] = 'text-align: right';
$table2->style[3] = 'text-align: right'; $table2->style[3] = 'text-align: right';
$table2->style[4] = 'text-align: right'; $table2->style[4] = 'text-align: right';
$table2->style[5] = 'text-align: right'; $table2->style[5] = 'text-align: right';
// $table2->style[6] = 'text-align: right';
foreach ($item['data'] as $row) { foreach ($item['data'] as $row) {
$the_first_men_time = get_agent_first_time(io_safe_output($row['agent'])); $the_first_men_time = get_agent_first_time(
io_safe_output($row['agent'])
);
$table_row = []; $table_row = [];
$table_row[] = $row['agent']; $table_row[] = $row['agent'];
$table_row[] = $row['availability_item']; $table_row[] = $row['availability_item'];
if ($row['time_total'] != 0) { if ($row['time_total'] != 0) {
$table_row[] = human_time_description_raw($row['time_total'], true); $table_row[] = human_time_description_raw(
$row['time_total'],
true
);
} else { } else {
$table_row[] = '--'; $table_row[] = '--';
} }
if ($row['time_error'] != 0) { if ($row['time_error'] != 0) {
$table_row[] = human_time_description_raw($row['time_error'], true); $table_row[] = human_time_description_raw(
$row['time_error'],
true
);
} else { } else {
$table_row[] = '--'; $table_row[] = '--';
} }
if ($row['time_ok'] != 0) { if ($row['time_ok'] != 0) {
$table_row[] = human_time_description_raw($row['time_ok'], true); $table_row[] = human_time_description_raw(
$row['time_ok'],
true
);
} else { } else {
$table_row[] = '--'; $table_row[] = '--';
} }
if ($row['time_unknown'] != 0) { if ($row['time_unknown'] != 0) {
$table_row[] = human_time_description_raw($row['time_unknown'], true); $table_row[] = human_time_description_raw(
$row['time_unknown'],
true
);
} else { } else {
$table_row[] = '--'; $table_row[] = '--';
} }
if ($row['time_not_init'] != 0) { if ($row['time_not_init'] != 0) {
$table_row[] = human_time_description_raw($row['time_not_init'], true); $table_row[] = human_time_description_raw(
$row['time_not_init'],
true
);
} else { } else {
$table_row[] = '--'; $table_row[] = '--';
} }
if ($row['time_downtime'] != 0) { if ($row['time_downtime'] != 0) {
$table_row[] = human_time_description_raw($row['time_downtime'], true); $table_row[] = human_time_description_raw(
$row['time_downtime'],
true
);
} else { } else {
$table_row[] = '--'; $table_row[] = '--';
} }
@ -2897,7 +2969,7 @@ function reporting_get_stats_summary($data, $graph_width, $graph_height)
{ {
global $config; global $config;
// Alerts table // Alerts table.
$table_sum = html_get_predefined_table(); $table_sum = html_get_predefined_table();
$tdata = []; $tdata = [];
@ -2917,10 +2989,10 @@ function reporting_get_stats_summary($data, $graph_width, $graph_height)
$table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;';
if ($data['monitor_checks'] > 0) { if ($data['monitor_checks'] > 0) {
// Fixed width non interactive charts // Fixed width non interactive charts.
$status_chart_width = $graph_width; $status_chart_width = $graph_width;
$tdata[0] = '<div style="margin: auto; width: '.$graph_width.'px;">'.'<div id="status_pie" style="margin: auto; width: '.$graph_width.'">'.graph_agent_status(false, $graph_width, $graph_height, true, true).'</div>'.'</div>'; $tdata[0] = '<div style="margin: auto; width: '.$graph_width.'px;"><div id="status_pie" style="margin: auto; width: '.$graph_width.'">'.graph_agent_status(false, $graph_width, $graph_height, true, true).'</div></div>';
} else { } else {
$tdata[2] = html_print_image('images/image_problem_area_small.png', true, ['width' => $graph_width]); $tdata[2] = html_print_image('images/image_problem_area_small.png', true, ['width' => $graph_width]);
} }
@ -3015,7 +3087,7 @@ function reporting_get_fired_alerts_table($alerts_fired)
$alert_module = alerts_get_alert_agent_module($id_alert); $alert_module = alerts_get_alert_agent_module($id_alert);
$template = alerts_get_alert_template($id_alert); $template = alerts_get_alert_template($id_alert);
// Add alerts fired to $agents_fired_alerts indexed by id_agent // Add alerts fired to $agents_fired_alerts indexed by id_agent.
$id_agent = db_get_value( $id_agent = db_get_value(
'id_agente', 'id_agente',
'tagente_modulo', 'tagente_modulo',
@ -3076,7 +3148,7 @@ function reporting_get_monitors_down_table($monitors_down)
$agents = []; $agents = [];
if ($monitors_down) { if ($monitors_down) {
foreach ($monitors_down as $monitor) { foreach ($monitors_down as $monitor) {
// Add monitors fired to $agents_fired_alerts indexed by id_agent // Add monitors fired to $agents_fired_alerts indexed by id_agent.
$id_agent = $monitor['id_agente']; $id_agent = $monitor['id_agente'];
if (!isset($agents[$id_agent])) { if (!isset($agents[$id_agent])) {
$agents[$id_agent] = []; $agents[$id_agent] = [];
@ -3172,6 +3244,7 @@ function reporting_get_agent_alerts_table($id_agent, $period=0, $date=0)
switch ($template['type']) { switch ($template['type']) {
case 'regex': case 'regex':
default:
if ($template['matches_value']) { if ($template['matches_value']) {
$data[2] = '&#8771; "'.$template['value'].'"'; $data[2] = '&#8771; "'.$template['value'].'"';
} else { } else {
@ -3236,7 +3309,11 @@ function reporting_get_agent_monitors_table($id_agent, $period=0, $date=0)
} }
foreach ($monitors as $monitor) { foreach ($monitors as $monitor) {
$downs = modules_get_monitor_downs_in_period($monitor['id_agente_modulo'], $period, $date); $downs = modules_get_monitor_downs_in_period(
$monitor['id_agente_modulo'],
$period,
$date
);
if (! $downs) { if (! $downs) {
continue; continue;
} }
@ -3248,7 +3325,11 @@ function reporting_get_agent_monitors_table($id_agent, $period=0, $date=0)
$data[0] = $monitor['nombre']; $data[0] = $monitor['nombre'];
} }
$data[1] = modules_get_last_down_timestamp_in_period($monitor['id_agente_modulo'], $period, $date); $data[1] = modules_get_last_down_timestamp_in_period(
$monitor['id_agente_modulo'],
$period,
$date
);
array_push($table->data, $data); array_push($table->data, $data);
} }

View File

@ -26,46 +26,53 @@
* ============================================================================ * ============================================================================
*/ */
.content_table { table {
width: 100%;
font-size: 20pt !important;
page-break-inside: avoid;
border-collapse: collapse; border-collapse: collapse;
} }
table th {
background-color: #434343;
color: #fff;
}
table.databox {
margin-bottom: 15px;
}
table.databox td {
width: 100%;
}
.content_table tr th, table.content_table {
.content_table tr td { page-break-inside: avoid;
}
table.header_table {
width: 100%;
}
table.header_table tbody tr th,
table.header_table tbody tr td {
padding: 10px; padding: 10px;
} }
thead.header_tr tr { thead.header_tr tbody tr {
background: #e6e6e6; background: #e6e6e6;
} }
thead.header_tr tr th {
thead.header_tr tbody tr th {
font-weight: normal; font-weight: normal;
text-align: right; text-align: right;
} }
thead.header_tr tr th.th_first { thead.header_tr tr th.th_first {
font-weight: bold; font-weight: bold;
text-align: left; text-align: left;
} }
.table_beauty { table.table_beauty {
font-size: 20pt !important;
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
} }
.table_beauty tr td { table.table_beauty tbody tr td {
font-size: 20pt !important;
padding: 5px; padding: 5px;
border: 0.1pt solid #acacac; border: 0.1pt solid #acacac;
} }
.table_beauty tr td table {
font-size: 20pt !important;
}
.table_beauty tr td table tr td {
font-size: 20pt !important;
}