Added a new report item which shows network interfaces information by agents of the selected group

* pandora_console/godmode/reporting/reporting_builder.item_editor.php: Added the item
	'network_interfaces_report'.

* pandora_console/include/functions_agents.php: Added the function
	"agents_get_network_interfaces" to get a list of network interfaces
	information by agent.

* pandora_console/include/functions_custom_graphs.php: Added the 'ttl' parameter
	to the function "custom_graphs_print".

* pandora_console/include/functions_reporting.php: Added the item
	'network_interfaces_report' to the function
	"reporting_render_report_html_item". Added the function
	"reporting_network_interfaces_table".

* pandora_console/include/functions_reports.php: Added the item
	'network_interfaces_report' to the function
	"reports_get_report_types".
This commit is contained in:
Alejandro Gallardo Escobar 2014-09-30 15:56:24 +02:00
parent f945b8253f
commit c73d901873
5 changed files with 324 additions and 4 deletions

View File

@ -125,6 +125,7 @@ switch ($action) {
case 'top_n':
case 'exception':
case 'general':
case 'network_interfaces_report':
$get_data_editor = true;
break;
default:
@ -420,6 +421,11 @@ switch ($action) {
$description = $item['description'];
$group = $item['id_group'];
break;
case 'network_interfaces_report':
$description = $item['description'];
$group = $item['id_group'];
$period = $item['period'];
break;
case 'top_n':
$description = $item['description'];
$period = $item['period'];
@ -2147,6 +2153,11 @@ function chooseType() {
$("#row_servers").show();
$("#row_description").show();
break;
case 'network_interfaces_report':
$("#row_group").show();
$("#row_description").show();
$("#row_period").show();
break;
case 'top_n':
$("#row_description").show();
$("#row_period").show();

View File

@ -2144,4 +2144,157 @@ function agents_update_gis($idAgente, $latitude, $longitude, $altitude,
return (bool)$return;
}
?>
/**
* Returns a list with network interfaces data by agent
*
* @param array Agents with the columns 'id_agente', 'nombre' and 'id_grupo'.
* @param mixed A filter to search the agents if the first parameter is false.
*
* @return array A list of network interfaces information by agents.
*/
function agents_get_network_interfaces ($agents = false, $agents_filter = false) {
if ($agents === false) {
$filter = false;
if ($agents_filter !== false) {
$filter = $agents_filter;
}
$fields = array(
'id_agente',
'nombre',
'id_grupo'
);
$agents = agents_get_agents($filter, $fields);
}
$ni_by_agents = array();
foreach ($agents as $agent) {
$agent_id = $agent['id_agente'];
$agent_group_id = $agent['id_grupo'];
$agent_name = $agent['nombre'];
$agent_interfaces = array();
$columns = array(
"id_agente_modulo",
"nombre",
"descripcion",
"ip_target"
);
$filter = array(
"id_agente" => $agent_id,
"id_tipo_modulo" => (int) db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc"),
"disabled" => 0
);
$modules = agents_get_modules($agent_id, $columns, $filter, true, false);
if (!empty($modules)) {
$interfaces = array();
foreach ($modules as $module) {
$module_name = (string) $module['nombre'];
// Trying to get the interface name from the module name
if (preg_match ("/_(.+)$/", $module_name, $matches)) {
if ($matches[1]) {
$interface_name = $matches[1];
$interface_name_escaped = str_replace("/", "\/", $interface_name);
if (!isset($interfaces[$interface_name])
|| (isset($interfaces[$interface_name])
&& preg_match ("/^ifOperStatus_$interface_name_escaped$/i", $module_name, $matches))) {
$interfaces[$interface_name] = $module;
}
}
}
}
unset($modules);
foreach ($interfaces as $interface_name => $module) {
$interface_name_escaped = str_replace("/", "\/", $interface_name);
$module_id = $module['id_agente_modulo'];
$module_name = $module['nombre'];
$module_description = $module['descripcion'];
$db_status = modules_get_agentmodule_status($module_id);
$module_value = modules_get_last_value ($module_id);
modules_get_status($module_id, $db_status, $module_value, $status, $title);
$status_image = ui_print_status_image($status, $title, true);
$ip_target = "";
if (isset($module['ip_target']) && !empty($module['ip_target'])) {
$ip_target = $module['ip_target'];
}
// Trying to get something like an IP from the description
else if (preg_match ("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $module_description, $matches)
|| preg_match ("/(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:?)|\2))(?4){5}((?4){2}|(25[0-5]|
(2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})/i", $module_description, $matches)) {
if ($matches[0]) {
$ip_target = $matches[0];
}
}
$mac = "";
// Trying to get something like a mac from the description
if (preg_match ("/([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})/i", $module_description, $matches)) {
if ($matches[0]) {
$mac = $matches[0];
}
}
// Get the ifInOctets and ifOutOctets modules of the interface
$columns = array(
"id_agente_modulo",
"nombre"
);
$interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE 'if%Octets_$interface_name'");
if (!empty($interface_traffic_modules) && count($interface_traffic_modules) >= 2) {
$interface_traffic_modules_aux = array('in' => '', 'out' => '');
foreach ($interface_traffic_modules as $interface_traffic_module) {
$interface_name_escaped = str_replace("/", "\/", $interface_name);
if (preg_match ("/^if(.+)Octets_$interface_name_escaped$/i", $interface_traffic_module['nombre'], $matches)) {
if (strtolower($matches[1]) == 'in') {
$interface_traffic_modules_aux['in'] = $interface_traffic_module['id_agente_modulo'];
}
elseif (strtolower($matches[1]) == 'out') {
$interface_traffic_modules_aux['out'] = $interface_traffic_module['id_agente_modulo'];
}
}
}
if (!empty($interface_traffic_modules_aux['in']) && !empty($interface_traffic_modules_aux['out'])) {
$interface_traffic_modules = $interface_traffic_modules_aux;
}
else {
$interface_traffic_modules = false;
}
}
else {
$interface_traffic_modules = false;
}
$agent_interfaces[$interface_name] = array();
$agent_interfaces[$interface_name]['status_image'] = $status_image;
$agent_interfaces[$interface_name]['status_module_id'] = $module_id;
$agent_interfaces[$interface_name]['status_module_name'] = $module_name;
$agent_interfaces[$interface_name]['ip'] = $ip_target;
$agent_interfaces[$interface_name]['mac'] = $mac;
if ($interface_traffic_modules !== false) {
$agent_interfaces[$interface_name]['traffic'] = array();
$agent_interfaces[$interface_name]['traffic']['in'] = $interface_traffic_modules['in'];
$agent_interfaces[$interface_name]['traffic']['out'] = $interface_traffic_modules['out'];
}
}
}
if (!empty($agent_interfaces)) {
$ni_by_agents[$agent_id] = array();
$ni_by_agents[$agent_id]['name'] = $agent_name;
$ni_by_agents[$agent_id]['group'] = $agent_group_id;
$ni_by_agents[$agent_id]['interfaces'] = $agent_interfaces;
}
}
return $ni_by_agents;
}
?>

View File

@ -163,7 +163,7 @@ function custom_graphs_print($id_graph, $height, $width, $period,
$stacked = null, $return = false, $date = 0, $only_image = false,
$background_color = 'white', $modules_param = array(), $homeurl = '',
$name_list = array(), $unit_list = array(), $show_last = true,
$show_max = true, $show_min = true, $show_avg = true) {
$show_max = true, $show_min = true, $show_avg = true, $ttl = 1) {
global $config;
@ -222,7 +222,7 @@ function custom_graphs_print($id_graph, $height, $width, $period,
$date,
$only_image,
$homeurl,
1,
$ttl,
false,
false,
$background_color,

View File

@ -5051,6 +5051,9 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
</tr>
</table>";
break;
case 'network_interfaces_report':
reporting_network_interfaces_table($content, $report, $mini, $item_title, $table);
break;
case 'general':
if (empty($item_title)) {
@ -7567,4 +7570,155 @@ function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $
echo $out;
}
}
?>
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 = 600;
$graph_height = 200;
$datetime = $report['datetime'];
$period = $content['period'];
if ($is_pdf) {
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);
}
}
$network_interfaces_by_agents = agents_get_network_interfaces(false, array('id_grupo' => $content['id_group']));
if (empty($network_interfaces_by_agents)) {
$data = array();
$table->colspan[$next_row][0] = 3;
$next_row++;
$data[0] = __('The group has no agents or none of the agents has any network interface');
array_push ($table->data, $data);
$slas = array();
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] = $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 = $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);
}
}
}
}
?>

View File

@ -574,6 +574,8 @@ function reports_get_report_types ($template = false, $not_editor = false) {
}
$types['top_n'] = array('optgroup' => __('Grouped'),
'name' => __('Top n'));
$types['network_interfaces_report'] = array('optgroup' => __('Grouped'),
'name' => __('Network interfaces'));