pandorafms/pandora_console/include/ajax/graph.ajax.php

291 lines
11 KiB
PHP
Raw Normal View History

<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2012 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.
require_once('include/functions_custom_graphs.php');
require_once('include/functions_graph.php');
$save_custom_graph = (bool) get_parameter('save_custom_graph');
$print_custom_graph = (bool) get_parameter('print_custom_graph');
$print_sparse_graph = (bool) get_parameter('print_sparse_graph');
2017-05-23 17:13:47 +02:00
$get_graphs = (bool)get_parameter('get_graphs_container');
if ($save_custom_graph) {
$return = array();
2018-05-28 17:47:40 +02:00
$id_modules = (array)get_parameter('id_modules', array());
$name = get_parameter('name', '');
$description = get_parameter('description', '');
$stacked = get_parameter('stacked', CUSTOM_GRAPH_LINE);
$width = get_parameter('width', 0);
$height = get_parameter('height', 0);
$events = get_parameter('events', 0);
$period = get_parameter('period', 0);
2018-01-03 15:53:49 +01:00
$fullscale = get_parameter('fullscale', 0);
2018-05-28 17:47:40 +02:00
$result = (bool)custom_graphs_create($id_modules, $name,
2018-01-03 15:53:49 +01:00
$description, $stacked, $width, $height, $events, $period, 0, 0, false, $fullscale);
2018-05-28 17:47:40 +02:00
$return['correct'] = $result;
2018-05-28 17:47:40 +02:00
echo json_encode($return);
return;
}
if ($print_custom_graph) {
ob_clean();
2018-05-28 17:47:40 +02:00
2018-06-01 13:58:29 +02:00
$params =array(
'period' => (int) get_parameter('period', SECONDS_5MINUTES),
'width' => (int) get_parameter('width', CHART_DEFAULT_WIDTH),
'height' => (int) get_parameter('height', CHART_DEFAULT_HEIGHT),
'unit_name' => get_parameter('unit_list', array()),
'date' => (int) get_parameter('date', time()),
'only_image' => (bool) get_parameter('only_image', false),
'homeurl' => (string) get_parameter('homeurl', ''),
'ttl' => (int) get_parameter('ttl', 1),
'dashboard' => (bool) get_parameter('dashboard', false),
'vconsole' => (bool) get_parameter('vconsole', false),
'fullscale' => (bool) get_parameter('fullscale', false),
'backgroundColor' => (string) get_parameter('background_color', 'white'),
'show_alerts' => (bool) get_parameter('show_alerts'),
'show_events' => (bool) get_parameter('show_events'),
'type_graph' => get_parameter('type_g', $config['type_module_charts']),
);
$params_combined = array(
'stacked' => (int) get_parameter('stacked', CUSTOM_GRAPH_LINE),
'labels' => get_parameter('name_list', array()),
'modules_series' => get_parameter('modules_param', array()),
'id_graph' => (int) get_parameter('id_graph', 0),
'return' => 1
);
echo graphic_combined_module(
get_parameter('modules_param', array()),
$params,
$params_combined
);
return;
}
if ($print_sparse_graph) {
ob_clean();
2018-05-28 17:47:40 +02:00
$params =array(
'agent_module_id' => (int)get_parameter('agent_module_id'),
'period' => (int) get_parameter('period', SECONDS_5MINUTES),
'show_events' => (bool) get_parameter('show_events'),
'title' => (string) get_parameter('title'),
'unit_name' => (string) get_parameter('unit_name'),
'show_alerts' => (bool) get_parameter('show_alerts'),
'pure' => (bool) get_parameter('pure'),
'date' => (int) get_parameter('date', time()),
'unit' => (string) get_parameter('unit'),
'baseline' => (int) get_parameter('baseline'),
'return_data' => (int) get_parameter('return_data'),
'show_title' => (bool) get_parameter('show_title', true),
'only_image' => (bool) get_parameter('only_image'),
'homeurl' => (string) get_parameter('homeurl'),
'ttl' => (int) get_parameter('ttl', 1),
'projection' => (bool) get_parameter('projection'),
'adapt_key' => (string) get_parameter('adapt_key'),
'compare' => (bool) get_parameter('compare'),
'show_unknown' => (bool) get_parameter('show_unknown'),
'menu' => (bool) get_parameter('menu', true),
'backgroundColor' => (string) get_parameter('background_color', 'white'),
'percentil' => get_parameter('percentil', null),
'dashboard' => (bool) get_parameter('dashboard'),
'vconsole' => (bool) get_parameter('vconsole'),
'type_graph' => get_parameter('type_g', $config['type_module_charts']),
'fullscale' => get_parameter('fullscale', 0),
'id_widget_dashboard' => false,
'force_interval' => '',
'time_interval' => 300,
'array_data_create' => 0
);
echo grafico_modulo_sparse($params);
return;
}
2017-05-23 17:13:47 +02:00
if ($get_graphs){
$id_container = get_parameter('id_container',0);
//config token max_graph
$max_graph = $config['max_graph_container'];
$result_items = db_get_all_rows_sql("SELECT * FROM tcontainer_item WHERE id_container = " . $id_container);
if (!empty($result_items)){
$hash = get_parameter('hash',0);
$period = get_parameter('time',0);
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
$periods = array ();
$periods[1] = __('none');
$periods[SECONDS_1HOUR] = __('1 hour');
$periods[SECONDS_2HOUR] = sprintf(__('%s hours'), '2 ');
$periods[SECONDS_6HOURS] = sprintf(__('%s hours'), '6 ');
$periods[SECONDS_12HOURS] = sprintf(__('%s hours'), '12 ');
$periods[SECONDS_1DAY] = __('1 day');
$periods[SECONDS_2DAY] = sprintf(__('%s days'), '2 ');
$periods[SECONDS_5DAY] = sprintf(__('%s days'), '5 ');
$periods[SECONDS_1WEEK] = __('1 week');
$periods[SECONDS_15DAYS] = __('15 days');
$periods[SECONDS_1MONTH] = __('1 month');
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
$table = '';
$single_table = "<table width='100%' cellpadding=4 cellspacing=4>";
$single_table .= "<tr id='row_time_lapse' style='' class='datos'>";
$single_table .= "<td style='font-weight:bold;width: 12%;'>";
$single_table .= __('Time container lapse');
// $single_table .= ui_print_help_tip(__('This is the range, or period of time over which the report renders the information for this report type. For example, a week means data from a week ago from now. '),true);
$single_table .= "</td>";
$single_table .= "<td>";
$single_table .= html_print_extended_select_for_time('period_container_'.$hash, $period,
'', '', '0', 10, true,'font-size: 9pt;width: 130px;',true,'',false,$periods,'vertical-align: middle;');
$single_table .= "</td>";
$single_table .= "</tr>";
$single_table .= "</table>";
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
$table .= $single_table;
$contador = $config['max_graph_container'];
foreach ($result_items as $key => $value) {
$table .= "</br>";
if($period > 1){
$value['time_lapse'] = $period;
}
2018-05-28 17:47:40 +02:00
$type_graph = ($value['type_graph'])? "line" : "area";
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
switch ($value['type']) {
case 'simple_graph':
if ($contador > 0) {
$sql_modulo = db_get_all_rows_sql("SELECT nombre, id_agente FROM
tagente_modulo WHERE id_agente_modulo = ". $value['id_agent_module']);
$sql_alias = db_get_all_rows_sql("SELECT alias from tagente
WHERE id_agente = ". $sql_modulo[0]['id_agente']);
2017-07-24 10:53:04 +02:00
$table .= "<div style='width: 90%'><h4>AGENT " .$sql_alias[0]['alias']." MODULE ".$sql_modulo[0]['nombre']."</h4><hr></div>";
2018-05-28 17:47:40 +02:00
$params =array(
'agent_module_id' => $value['id_agent_module'],
'period' => $value['time_lapse'],
'homeurl' => ui_get_full_url(false, false, false, false),
'type_graph' => $type_graph,
'fullscale' => $value['fullscale']
);
$table .= grafico_modulo_sparse($params);
2017-05-23 17:13:47 +02:00
$contador --;
}
// $table .= "</br>";
break;
case 'custom_graph':
if ($contador > 0) {
$graph_conf = db_get_row('tgraph', 'id_graph', $value['id_graph']);
2017-05-23 17:13:47 +02:00
if($graph_conf['stacked'] == 4 || $graph_conf['stacked'] == 9){
$height = 50;
} else if ($graph_conf['stacked'] == 5){
$height = 200;
} else {
$height = 300;
}
2018-06-01 13:58:29 +02:00
2017-07-24 10:53:04 +02:00
$table .= "<div style='width: 90%'><h4>".$graph[0]['name']."</h4><hr></div>";
2018-06-01 13:58:29 +02:00
$params =array(
'period' => $value['time_lapse'],
'width' => 1000,
'height' => $height,
'percentil' => $graph_conf['percentil'] == 1,
'fullscale' => $value['fullscale']
);
$params_combined = array(
'stacked' => $graph_conf['stacked'],
'id_graph' => $value['id_graph']
);
$table .= graphic_combined_module(
2017-05-23 17:13:47 +02:00
false,
2018-06-01 13:58:29 +02:00
$params,
$params_combined
2018-01-03 15:53:49 +01:00
);
2018-06-01 13:58:29 +02:00
2017-05-23 17:13:47 +02:00
$contador --;
}
break;
case 'dynamic_graph':
2017-07-24 10:53:04 +02:00
if($value['agent'] != ''){
$alias = " AND alias REGEXP '".$value['agent']."'";
}
2017-05-23 17:13:47 +02:00
if($value['id_group'] === '0'){
$id_group = "";
} else {
$id_group = " AND id_grupo = ".$value['id_group'];
}
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
if($value['id_module_group'] === '0'){
$id_module_group = "";
} else {
$id_module_group = " AND id_module_group = ".$value['id_module_group'];
}
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
if($value['id_tag'] === '0'){
$tag = "";
$id_tag = "";
} else {
$tag = " INNER JOIN ttag_module ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo ";
$id_tag = " AND ttag_module.id_tag = ".$value['id_tag'];
}
2018-05-28 17:47:40 +02:00
2017-07-24 10:53:04 +02:00
if($value['module'] != ''){
$module_name = " AND nombre REGEXP '".$value['module']."'";
}
2017-05-23 17:13:47 +02:00
$id_agent_module = db_get_all_rows_sql("SELECT tagente_modulo.id_agente_modulo FROM tagente_modulo
". $tag . "WHERE 1=1" . $id_module_group . $module_name .
" AND id_agente IN (SELECT id_agente FROM tagente WHERE 1=1" .$alias.$id_group.")"
. $id_tag);
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
foreach ($id_agent_module as $key2 => $value2) {
if ($contador > 0) {
$sql_modulo2 = db_get_all_rows_sql("SELECT nombre, id_agente FROM
tagente_modulo WHERE id_agente_modulo = ". $value2['id_agente_modulo']);
2018-05-28 17:47:40 +02:00
2017-05-23 17:13:47 +02:00
$sql_alias2 = db_get_all_rows_sql("SELECT alias from tagente
WHERE id_agente = ". $sql_modulo2[0]['id_agente']);
2018-05-28 17:47:40 +02:00
2017-07-24 10:53:04 +02:00
$table .= "<div style='width: 90%'><h4>AGENT " .$sql_alias2[0]['alias']." MODULE ".$sql_modulo2[0]['nombre']."</h4><hr></div>";
2018-05-28 17:47:40 +02:00
$params =array(
'agent_module_id' => $value2['id_agente_modulo'],
'period' => $value['time_lapse'],
'homeurl' => ui_get_full_url(false, false, false, false),
'type_graph' => $type_graph,
'fullscale' => $value['fullscale']
);
$table .= grafico_modulo_sparse($params);
2017-05-23 17:13:47 +02:00
$contador --;
}
}
break;
}
}
$table .= "</br>";
echo $table;
return;
}
}
?>