Merge branch '393-Feature-para-mostrar-los-timesticks-en-Dias-Horas-Minutos-Seg-dev' into 'develop'

New feature. Dynamic units

See merge request !818
This commit is contained in:
vgilc 2017-10-04 17:41:37 +02:00
commit d181edc471
10 changed files with 237 additions and 22 deletions

View File

@ -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');

View File

@ -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;

View File

@ -565,7 +565,7 @@ foreach ($targets2 as $t) {
$table->data['edit6'][1] = html_print_select ($targets, 'id_export', '','', __('No change'), '', true, false, false);
$table->data['edit6'][2] = __('Unit');
$table->data['edit6'][3] = html_print_input_text ('unit', '', '', 15, 60, true);
$table->data['edit6'][3] = html_print_extended_select_for_unit('unit','', '', '', '0', '15', true, false, false);
/* FF stands for Flip-flop */
@ -1160,7 +1160,7 @@ function process_manage_edit ($module_name, $agents_select = null, $module_statu
/* List of fields which can be updated */
$fields = array ('dynamic_interval', 'dynamic_max', 'dynamic_min', 'dynamic_two_tailed', 'min_warning', 'max_warning', 'str_warning',
'min_critical', 'max_critical', 'str_critical', 'min_ff_event',
'module_interval', 'disabled', 'post_process', 'unit',
'module_interval', 'disabled', 'post_process', 'unit_select',
'snmp_community', 'tcp_send', 'custom_string_1',
'plugin_parameter', 'custom_string_2', 'custom_string_3', 'min',
'max', 'id_module_group', 'plugin_user', 'plugin_pass',
@ -1192,6 +1192,13 @@ function process_manage_edit ($module_name, $agents_select = null, $module_statu
$values['post_process'] = $value;
}
break;
case 'unit_select':
if($value == "none"){
$values['unit'] = (string) get_parameter('unit_text');
} else {
$values['unit'] = $value;
}
break;
default:
if ($value != '') {
$values[$field] = $value;

View File

@ -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[] = "<a target='_blank' href='".io_safe_input($row[$attr[0]])."'><img style='width:300px' src='".io_safe_input($row[$attr[0]])."'></a>";
}
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 .= "&nbsp;" . '<i>'. io_safe_output($module["unit"]) . '</i>';
$data_macro = modules_get_unit_macro($module["datos"],$module["unit"]);
if($data_macro){
$salida = $data_macro;
} else {
$salida .= "&nbsp;" . '<i>'. io_safe_output($module["unit"]) . '</i>';
}
}
}
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){

View File

@ -699,6 +699,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 = "";
}
}
// Get module warning_min and critical_min
@ -788,8 +791,10 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
'border' => '#000000', 'color' => $config['graph_color1'],
'alpha' => CHART_DEFAULT_ALPHA);
$color['unit'.$series_suffix] = array('border' => null, 'color' => '#0097BC', 'alpha' => 10);
$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];

View File

@ -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;
}
ob_start();
echo '<div id="' . $uniq_name . '_default" style="width:100%;display:inline;">';
html_print_select ($fields, $uniq_name . '_select', $selected,
"" . $script, $nothing, $nothing_value, false, false, false,
'', $disabled, 'font-size: xx-small;' . $select_style);
echo ' <a href="javascript:">' .
html_print_image('images/pencil.png', true,
array('class' => $uniq_name . '_toggler',
'alt' => __('Custom'),
'title' => __('Custom'),
'style' => 'width: 18px;')) .
'</a>';
echo '</div>';
echo '<div id="' . $uniq_name . '_manual" style="width:100%;display:inline;">';
html_print_input_text ($uniq_name . '_text', $selected, '', 20);
html_print_input_hidden($name, $selected, false, $uniq_name);
echo ' <a href="javascript:">' .
html_print_image('images/default_list.png', true,
array('class' => $uniq_name . '_toggler',
'alt' => __('List'),
'title' => __('List'),
'style' => 'width: 18px;')) . '</a>';
echo '</div>';
echo "<script type='text/javascript'>
$(document).ready (function () {
post_process_select_init_unit('$uniq_name','$selected');
post_process_select_events_unit('$uniq_name','$selected');
});
</script>";
$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,

View File

@ -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.
*

View File

@ -247,8 +247,21 @@ function treeview_printModuleTable($id_module, $server_data = false, $no_head =
$last_data_str = $data;
if ($module['unit'] != '') {
$last_data_str .= "&nbsp;";
$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 = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" .
remove_right_zeros(number_format($data_macro, $config['graph_precision'])) . "</span>";
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 .= "&nbsp;";
$last_data_str .= '('.$module['unit'].')';
}
}
$last_data_str .= "&nbsp;";

View File

@ -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();

View File

@ -1320,8 +1320,13 @@ if (!empty($result)) {
// Show units ONLY in numeric data types
if (isset($row['unit'])) {
$salida .= '&nbsp;' . '<i>' . io_safe_output($row['unit']) . '</i>';
$salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[&hellip;]', 'font-size:7.5pt;');
$data_macro = modules_get_unit_macro($row['datos'],$row['unit']);
if($data_macro) {
$salida = $data_macro;
} else {
$salida .= '&nbsp;' . '<i>' . io_safe_output($row['unit']) . '</i>';
$salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[&hellip;]', '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 {