From d7f3e1ecdec297aafefd83c86e8c3dd39980a17d Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 14 Sep 2017 12:10:41 +0200 Subject: [PATCH] New feature. Dynamic units --- .../godmode/agentes/configurar_agente.php | 10 ++- .../agentes/module_manager_editor_common.php | 8 +- pandora_console/include/ajax/module.php | 35 ++++++-- pandora_console/include/functions_graph.php | 7 +- pandora_console/include/functions_html.php | 79 +++++++++++++++++++ pandora_console/include/functions_modules.php | 29 +++++++ .../include/functions_treeview.php | 17 +++- pandora_console/include/javascript/pandora.js | 45 +++++++++++ .../operation/agentes/status_monitor.php | 16 +++- 9 files changed, 227 insertions(+), 19 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index bd34c56503..6d888079e6 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1043,9 +1043,7 @@ if ($update_module || $create_module) { } */ $configuration_data = str_replace('\\', "\", - io_safe_input($new_configuration_data));; - - html_debug($configuration_data, true); + io_safe_input($new_configuration_data)); } // Services are an enterprise feature, @@ -1110,7 +1108,11 @@ if ($update_module || $create_module) { $ff_event_critical = (int) get_parameter ('ff_event_critical'); $each_ff = (int) get_parameter ('each_ff'); $ff_timeout = (int) get_parameter ('ff_timeout'); - $unit = (string) get_parameter('unit'); + $unit = (string) get_parameter('unit_select'); + if($unit == "none"){ + $unit = (string) get_parameter('unit_text'); + } + $id_tag = (array) get_parameter('id_tag_selected'); $serialize_ops = (string) get_parameter('serialize_ops'); $critical_instructions = (string) get_parameter('critical_instructions'); diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index c2b8a0c7b1..f66aa17296 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -363,8 +363,12 @@ $table_advanced->data[1][1] = html_print_input_text ('custom_id', $custom_id, '' $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); $table_advanced->data[1][3] = __('Unit'); -$table_advanced->data[1][4] = html_print_input_text ('unit', $unit, '', 20, 65, true, - $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); +// $table_advanced->data[1][4] = html_print_input_text ('unit', $unit, '', 20, 65, true, +// $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); +// $table_advanced->colspan[1][4] = 3; +$table_advanced->data[1][4] = + html_print_extended_select_for_unit('unit', + $unit, '', '', '0', false, true, false, false); $table_advanced->colspan[1][4] = 3; $module_id_policy_module = 0; diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index c78c4d8adf..9284427061 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -256,7 +256,7 @@ if ($get_module_detail) { 'ttipo_modulo', 'nombre', 'web_content_string'); $post_process = db_get_value_filter('post_process','tagente_modulo',array('id_agente_modulo' => $module_id)); - + $unit = db_get_value_filter('unit','tagente_modulo',array('id_agente_modulo' =>$module_id)); foreach ($result as $row) { $data = array (); @@ -314,7 +314,12 @@ if ($get_module_detail) { break; default: - $data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision'])); + $data_macro = modules_get_unit_macro($row[$attr[0]],$unit); + if($data_macro){ + $data[] = $data_macro; + } else { + $data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision'])); + } break; } } @@ -327,7 +332,12 @@ if ($get_module_detail) { $data[] = ""; } else{ - $data[] = $row[$attr[0]]; + $data_macro = modules_get_unit_macro($row[$attr[0]],$unit); + if($data_macro){ + $data[] = $data_macro; + } else { + $data[] = $row[$attr[0]]; + } } } } @@ -1007,13 +1017,24 @@ if ($list_modules) { } // Show units ONLY in numeric data types if (isset($module["unit"])) { - $salida .= " " . ''. io_safe_output($module["unit"]) . ''; + $data_macro = modules_get_unit_macro($module["datos"],$module["unit"]); + if($data_macro){ + $salida = $data_macro; + } else { + $salida .= " " . ''. io_safe_output($module["unit"]) . ''; + } + } } else { - $salida = ui_print_module_string_value( - $module["datos"], $module["id_agente_modulo"], - $module["current_interval"], $module["module_name"]); + $data_macro = modules_get_unit_macro($module["datos"],$module["unit"]); + if($data_macro){ + $salida = $data_macro; + } else { + $salida = ui_print_module_string_value( + $module["datos"], $module["id_agente_modulo"], + $module["current_interval"], $module["module_name"]); + } } } if($module["id_tipo_modulo"] != 25){ diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d6ced0e99c..6fcca53864 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -702,6 +702,9 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, if (empty($unit)) { $unit = modules_get_unit($agent_module_id); + if(modules_is_unit_macro($unit)){ + $unit = ""; + } } if ($fullscale) { @@ -812,7 +815,9 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, 'alpha' => CHART_DEFAULT_ALPHA); $color['unit'.$series_suffix] = array('border' => null, 'color' => '#0097BC', 'alpha' => 10); - + if(modules_is_unit_macro($unit)){ + $unit = ""; + } if ($show_events) { $legend['event'.$series_suffix_str] = __('Events').$series_suffix_str; $chart_extra_data['legend_events'] = $legend['event'].$series_suffix_str; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 3de688c84a..7a3f911c0d 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -621,6 +621,85 @@ function html_print_select_from_sql ($sql, $name, $selected = '', $disabled, $style,'', $size); } +function html_print_extended_select_for_unit($name, $selected = '', + $script = '', $nothing = '', $nothing_value = '0', $size = false, + $return = false, $select_style = false, $unique_name = true, + $disabled = false, $no_change = 0) { + + global $config; + + + // $fields = post_process_get_custom_values(); + $fields['_timeticks_'] = 'timeticks'; + $fields['none'] = __('none'); + + if($no_change != 0){ + $fields[-1] = __('No change'); + } + + // $selected_float = (float)$selected; + // $found = false; + // + // if (array_key_exists($selected, $fields)) + // $found = true; + // + // if (!$found) { + // $fields[$selected] = floatval($selected); + // } + + if ($unique_name === true) { + $uniq_name = uniqid($name); + } + else { + $uniq_name = $name; + } + html_debug($selected); + ob_start(); + + echo '
'; + html_print_select ($fields, $uniq_name . '_select', $selected, + "" . $script, $nothing, $nothing_value, false, false, false, + '', $disabled, 'font-size: xx-small;' . $select_style); + echo ' ' . + html_print_image('images/pencil.png', true, + array('class' => $uniq_name . '_toggler', + 'alt' => __('Custom'), + 'title' => __('Custom'), + 'style' => 'width: 18px;')) . + ''; + echo '
'; + + echo '
'; + html_print_input_text ($uniq_name . '_text', $selected, '', 20); + + html_print_input_hidden($name, $selected, false, $uniq_name); + echo ' ' . + html_print_image('images/default_list.png', true, + array('class' => $uniq_name . '_toggler', + 'alt' => __('List'), + 'title' => __('List'), + 'style' => 'width: 18px;')) . ''; + echo '
'; + + echo ""; + + $returnString = ob_get_clean(); + + + + + if ($return) + return $returnString; + else + echo $returnString; +} + function html_print_extended_select_for_post_process($name, $selected = '', $script = '', $nothing = '', $nothing_value = '0', $size = false, $return = false, $select_style = false, $unique_name = true, diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index f10f7d1a42..bcdeb6819c 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1597,6 +1597,35 @@ function modules_get_agentmodule_last_status($id_agentmodule = 0) { return $status_row['known_status']; } +/** + * Get the data by applying the macro. + * + * @param string macro unit. + * + * @return false or data with applied macro. + */ +function modules_get_unit_macro($data,$macro) { + if(modules_is_unit_macro($macro)){ + $data = human_milliseconds_to_string($data); + return $data; + } + return false; +} + +/** + * Check if it's a unit macro. + * + * @param string macro unit. + * + * @return false or true. + */ +function modules_is_unit_macro($macro) { + if($macro == "_timeticks_"){ + return true; + } + return false; +} + /** * Get the current value of an agent module. * diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index f9847b4f76..1ef1d2fc39 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -247,8 +247,21 @@ function treeview_printModuleTable($id_module, $server_data = false, $no_head = $last_data_str = $data; if ($module['unit'] != '') { - $last_data_str .= " "; - $last_data_str .= '('.$module['unit'].')'; + $data_macro = modules_get_unit_macro($last_data["datos"],$module['unit']); + if($data_macro){ + if (is_numeric($data_macro)) + $last_data_str = "" . + remove_right_zeros(number_format($data_macro, $config['graph_precision'])) . ""; + else + $last_data_str = ui_print_truncate_text(io_safe_output($data_macro), + GENERIC_SIZE_TEXT, true, true, true, + '...', 'white-space: nowrap;'); + } else { + $last_data_str .= " "; + $last_data_str .= '('.$module['unit'].')'; + } + + } $last_data_str .= " "; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 2db3532cfb..a7ddd6074f 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -607,6 +607,51 @@ function post_process_select_init(name) { $('#' + name + '_default').show(); } +function post_process_select_init_unit(name,selected) { + // Manual mode is hidden by default + + $('#' + name + '_manual').hide(); + $('#' + name + '_default').show(); + + if(selected != "") { + var select_or_text = false; + $('#' + name + '_select option').each(function(i,item) { + if ($(item).val() == selected) { + select_or_text = true; + return false; + } + }); + + console.log(select_or_text); + if(select_or_text) { + $('#' + name + '_select option[value='+ selected +']').attr("selected",true); + $('#text-' + name + '_text').val(""); + } else { + $('#' + name + '_select option[value=none]').attr("selected",true); + $('#' + name + '_default').hide(); + $('#' + name + '_manual').show(); + } + } else { + $('#' + name + '_select option[value=none]').attr("selected",true); + } + + $('#' + name + '_select').change(function() { + var value = $('#' + name + '_select').val(); + $('#' + name + '_select option[value='+ value +']').attr("selected",true); + console.log(value); + }); + +} + +function post_process_select_events_unit(name,selected) { + + $('.' + name + '_toggler').click(function() { + $('#' + name + '_select option[value=none]').attr("selected",true); + $('#text-' + name + '_text').val(""); + toggleBoth(name); + }); +} + function post_process_select_events(name) { $('.' + name + '_toggler').click(function() { var value = $('#text-' + name + '_text').val(); diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 58f221bb76..27baeced96 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -1320,8 +1320,13 @@ if (!empty($result)) { // Show units ONLY in numeric data types if (isset($row['unit'])) { - $salida .= ' ' . '' . io_safe_output($row['unit']) . ''; - $salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[…]', 'font-size:7.5pt;'); + $data_macro = modules_get_unit_macro($row['datos'],$row['unit']); + if($data_macro) { + $salida = $data_macro; + } else { + $salida .= ' ' . '' . io_safe_output($row['unit']) . ''; + $salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[…]', 'font-size:7.5pt;'); + } } } else { @@ -1374,7 +1379,12 @@ if (!empty($result)) { $salida = 0; } else { - $salida = $row['datos']; + $data_macro = modules_get_unit_macro($row['datos'],$row['unit']); + if($data_macro) { + $salida = $data_macro; + } else { + $salida = $row['datos']; + } } } else {