From 2d6fa8d0e0e2fa2723c36f40c4826a2955046ef2 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 12 Jun 2018 15:46:05 +0200 Subject: [PATCH] fixed errors graphs --- .../godmode/setup/setup_general.php | 4 ++ pandora_console/include/functions.php | 2 +- pandora_console/include/functions_config.php | 39 +++++++++----- pandora_console/include/functions_graph.php | 53 ++++++------------- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 352f2dda56..37f595a9fb 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -59,6 +59,10 @@ $table->data[1][0] = __('Remote config directory') . $table->data[1][1] = html_print_input_text ('remote_config', io_safe_output($config["remote_config"]), '', 30, 100, true); +$table->data[2][0] = __('Phantomjs bin directory') . ui_print_help_tip (__("Directory where phantomjs binary file exists and has execution grants."), true); + +$table->data[2][1] = html_print_input_text ('phantomjs_bin', io_safe_output($config["phantomjs_bin"]), '', 30, 100, true); + $table->data[6][0] = __('Auto login (hash) password'); $table->data[6][1] = html_print_input_password ('loginhash_pwd', io_output_password($config["loginhash_pwd"]), '', 15, 15, true); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index debf6cebe2..b509ca2da6 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3169,7 +3169,7 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = fal $session_id = session_id(); $result = exec( - "phantomjs " . $file_js . " " . + $config['phantomjs_bin'] ."/phantomjs " . $file_js . " " . $url . " '" . $type_graph_pdf . "' '" . $params_encode_json . "' '" . diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 11ab9f3c94..f51f409d8f 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -129,9 +129,10 @@ function config_update_config () { $error_update[] = __('Language settings'); if (!config_update_value ('remote_config', (string) get_parameter ('remote_config'))) $error_update[] = __('Remote config directory'); + if (!config_update_value ('phantomjs_bin', (string) get_parameter ('phantomjs_bin'))) + $error_update[] = __('phantomjs config directory'); if (!config_update_value ('loginhash_pwd', io_input_password((string) get_parameter ('loginhash_pwd')))) $error_update[] = __('Auto login (hash) password'); - if (!config_update_value ('timesource', (string) get_parameter ('timesource'))) $error_update[] = __('Time source'); if (!config_update_value ('autoupdate', (bool) get_parameter ('autoupdate'))) @@ -804,12 +805,9 @@ function config_update_config () { if (!config_update_value('ehorus_custom_field', (string) get_parameter('ehorus_custom_field', $config['ehorus_custom_field']))) $error_update[] = __('eHorus id custom field'); break; - } - - } - + if (count($error_update) > 0) { $config['error_config_update_config'] = array(); $config['error_config_update_config']['correct'] = false; @@ -820,7 +818,7 @@ function config_update_config () { $config['error_config_update_config'] = array(); $config['error_config_update_config']['correct'] = true; } - + enterprise_include_once('include/functions_policies.php'); $enterprise = enterprise_include_once ('include/functions_skins.php'); if ($enterprise !== ENTERPRISE_NOT_HOOK) { @@ -869,7 +867,17 @@ function config_process_config () { config_update_value ('remote_config', $default); } - + + if (!isset ($config['phantomjs_bin'])) { + if ($is_windows){ + $default = 'C:\\PandoraFMS\\Pandora_Server\\data_in'; + } + else{ + $default = '/usr/bin'; + } + config_update_value ('phantomjs_bin', $default); + } + if (!isset ($config['date_format'])) { config_update_value ('date_format', 'F j, Y, g:i a'); } @@ -2178,21 +2186,28 @@ function config_check () { sprintf(__('Recommended value is: %s'), sprintf(__('%s or greater'), '800M')) . '

' . __('Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)'), sprintf(__("Not recommended '%s' value in PHP configuration"), 'upload_max_filesize')); } - + $PHPmemory_limit_min = config_return_in_bytes('500M'); - + if ($PHPmemory_limit < $PHPmemory_limit_min && $PHPmemory_limit !== '-1') { set_pandora_error_for_header( sprintf(__('Recommended value is: %s'), sprintf(__('%s or greater'), '500M')) . '

' . __('Please, change it on your PHP configuration file (php.ini) or contact with administrator'), sprintf(__("Not recommended '%s' value in PHP configuration"), 'memory_limit')); } - + if (preg_match("/system/", $PHPdisable_functions) or preg_match("/exec/", $PHPdisable_functions)) { - set_pandora_error_for_header( + set_pandora_error_for_header( __("Variable disable_functions containts functions system() or exec(), in PHP configuration file (php.ini)"). '

' . __('Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)'), __("Problems with disable functions in PHP.INI")); } - + + $result_ejectuion = exec($config['phantomjs_bin'] . 'phantomjs --version'); + if(isset($result_ejectuion) || $result_ejectuion == ''){ + set_pandora_error_for_header( + __('To be able to create images of the graphs for PDFs, please install the phantom.js extension. For that, it is necessary to follow these steps:') . + 'Click here', + __("phantomjs is not installed")); + } } function config_return_in_bytes($val) { diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 732bb8147d..220d9c686f 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -234,27 +234,20 @@ function grafico_modulo_sparse_data_chart ( global $config; + //XXX add zoom + $data_slice = $date_array['period'] / 250; //zoom + if( $data_module_graph['id_module_type'] == 23 || $data_module_graph['id_module_type'] == 3 || $data_module_graph['id_module_type'] == 17 || $data_module_graph['id_module_type'] == 10 || $data_module_graph['id_module_type'] == 33 ){ - -//XXXXXXXXXXX SLICES -/* -"SELECT count(*) as data, min(utimestamp) as utimestamp - FROM tagente_datos_string - WHERE id_agente_modulo = 227 - AND utimestamp > 1527584831 - AND utimestamp < 1527671231 - GROUP by ROUND(utimestamp / 300);" -*/ $data = db_get_all_rows_filter ( 'tagente_datos_string', array ('id_agente_modulo' => (int)$agent_module_id, "utimestamp > '". $date_array['start_date']. "'", "utimestamp < '". $date_array['final_date'] . "'", - 'group' => "ROUND(utimestamp / 300)", + 'group' => "ROUND(utimestamp / $data_slice)", 'order' => 'utimestamp ASC'), array ('count(*) as datos', 'min(utimestamp) as utimestamp'), 'AND', @@ -262,33 +255,17 @@ function grafico_modulo_sparse_data_chart ( ); } else{ - /* - if(true){ - $data = db_get_all_rows_filter ( - 'tagente_datos', - array ('id_agente_modulo' => (int)$agent_module_id, - "utimestamp > '". $date_array['start_date']. "'", - "utimestamp < '". $date_array['final_date'] . "'", - 'group' => "ROUND(utimestamp / 86400)", - 'order' => 'utimestamp ASC'), - array ('max(datos) as datos', 'min(utimestamp) as utimestamp'), - 'AND', - $data_module_graph['history_db'] - ); - } - else{ - */ - $data = db_get_all_rows_filter ( - 'tagente_datos', - array ('id_agente_modulo' => (int)$agent_module_id, - "utimestamp > '". $date_array['start_date']. "'", - "utimestamp < '". $date_array['final_date'] . "'", - 'order' => 'utimestamp ASC'), - array ('datos', 'utimestamp'), - 'AND', - $data_module_graph['history_db'] - ); - //} + $data = db_get_all_rows_filter ( + 'tagente_datos', + array ('id_agente_modulo' => (int)$agent_module_id, + "utimestamp > '". $date_array['start_date']. "'", + "utimestamp < '". $date_array['final_date'] . "'", + 'group' => "ROUND(utimestamp / $data_slice)", + 'order' => 'utimestamp ASC'), + array ('max(datos) as datos', 'min(utimestamp) as utimestamp'), + 'AND', + $data_module_graph['history_db'] + ); } if($data === false){