Added feature of custom post process values. TICKET: #1743

This commit is contained in:
mdtrooper 2015-02-09 19:34:36 +01:00
parent ba1c14ec4f
commit 2842970c83
12 changed files with 373 additions and 17 deletions

View File

@ -58,3 +58,8 @@ ALTER TABLE `tusuario` ADD COLUMN `strict_acl` tinyint(1) DEFAULT 0;
-- Table `talert_commands`
-- ---------------------------------------------------------------------
UPDATE `talert_commands` SET `fields_descriptions` = '[\"Destination address\",\"Subject\",\"Text\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]', `fields_values` = '[\"\",\"\",\"_html_editor_\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]' WHERE `id` = 1 AND `name` = 'eMail';
-- ---------------------------------------------------------------------
-- Table `tconfig`
-- ---------------------------------------------------------------------
INSERT INTO `tconfig` (`token`, `value`) VALUES ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}')

View File

@ -358,8 +358,10 @@ else {
$table_advanced->data[2][1] .= html_print_input_hidden ('moduletype', $moduletype, true);
$table_advanced->data[2][3] = __('Post process').' ' . ui_print_help_icon ('postprocess', true);
$table_advanced->data[2][4] = html_print_input_text ('post_process',
$post_process, '', 15, 25, true, $disabledBecauseInPolicy);
$table_advanced->data[2][4] =
html_print_extended_select_for_post_process('post_process',
$post_process, '', __('Empty'), '0', false, true, false, true,
$disabledBecauseInPolicy);
$table_advanced->colspan[2][4] = 3;
$table_advanced->data[3][0] = __('Min. Value');
@ -1005,7 +1007,7 @@ function delete_relation (num_row, id_relation) {
function validate_post_process() {
var post_process = $("#text-post_process").val();
var new_post_process = post_process.replace(',','.');
var new_post_process = post_process.replace(',', '.');
$("#text-post_process").val(new_post_process);
}

View File

@ -403,10 +403,12 @@ $table->data['edit2'][1] = html_print_extended_select_for_time ('module_interval
$table->data['edit2'][2] = __('Disabled');
$table->data['edit2'][3] = html_print_select(array('' => __('No change'), '1' => __('Yes'), '0' => __('No')),'disabled','','','', '', true);
$table->data['edit3'][0] = __('Post process').ui_print_help_icon ('postprocess', true);
$table->data['edit3'][0] = __('Post process') .
ui_print_help_icon ('postprocess', true);
$table->data['edit3'][1] = html_print_input_text ('post_process', '', '', 10, 15, true);
$table->data['edit3'][2] = __('SMNP community');
$table->data['edit3'][3] = html_print_input_text ('snmp_community', '', '', 10, 15, true);
$table->data['edit35'][0] = __('Target IP');
$table->data['edit35'][1] = html_print_input_text ('ip_target', '', '', 15, 60, true);
$table->data['edit35'][2] = __('SNMP version');

View File

@ -78,7 +78,8 @@ push_table_row($data, 'field_snmpv3_row3');
$data = array();
$data[0] = __('Post process') . ' ' . ui_print_help_icon ('postprocess', true );
$data[1] = html_print_input_text ('post_process', $post_process, '', 12, 25, true);
$data[1] = html_print_extended_select_for_post_process('post_process',
$post_process, '', __('Empty'), '0', false, true, false, true);
$data[2] = $data[3] = '';
push_table_row($data, 'field_process');

View File

@ -25,7 +25,8 @@ $data[1] = html_print_select_from_sql ('SELECT id, name FROM tplugin ORDER BY na
// Store the macros in base64 into a hidden control to move between pages
$data[1] .= html_print_input_hidden('macros',base64_encode($macros),true);
$data[2] = __('Post process') . ' ' . ui_print_help_icon ('postprocess', true, ui_get_full_url(false, false, false, false));
$data[3] = html_print_input_text ('post_process', $post_process, '', 12, 25, true);
$data[3] = html_print_extended_select_for_post_process('post_process',
$post_process, '', __('Empty'), '0', false, true, false, true);
push_table_row ($data, 'plugin_1');

View File

@ -54,7 +54,8 @@ push_table_row ($data, 'wmi_3');
$data = array();
$data[0] = __('Post process') . ' ' . ui_print_help_icon ('postprocess', true, ui_get_full_url(false, false, false, false));
$data[1] = html_print_input_text ('post_process', $post_process, '', 12, 25, true);
$data[1] = html_print_extended_select_for_post_process('post_process',
$post_process, '', __('Empty'), '0', false, true, false, true);
$data[2] = $data[3] = '';
push_table_row($data, 'field_process');
?>

View File

@ -28,6 +28,7 @@ if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_us
//Constant with fonts directory
define ('_MPDF_TTFONTPATH', $config['homedir'] . '/include/fonts/');
require_once("include/functions_post_process.php");
// Load enterprise extensions
enterprise_include ('godmode/setup/setup_visuals.php');
@ -125,10 +126,45 @@ $row++;
$table->data[$row][0] = __('Graphic resolution (1-low, 5-high)');
$table->data[$row][1] = html_print_input_text ('graph_res', $config["graph_res"], '', 5, 5, true);
//----------------------------------------------------------------------
// CUSTOM VALUES POST PROCESS
//----------------------------------------------------------------------
$row++;
$table->data[$row][0] = __('Custom values post process');
$table->data[$row][1] = "<table>";
$table->data[$row][1] .= __('Value') . ':&nbsp;' .
html_print_input_text ('custom_value', '', '', 25, 50, true);
$table->data[$row][1] .= '&nbsp;' . __('Text') . ':&nbsp;' .
html_print_input_text ('custom_text', '', '', 25, 50, true);
$table->data[$row][1] .= "&nbsp;";
$table->data[$row][1] .= html_print_input_hidden(
'custom_value_add', '', true);
$table->data[$row][1] .= html_print_button (__('Add'),
'custom_value_add_btn', false, "", 'class="sub next"', true);
$table->data[$row][1] .= '<br /><br />';
$table->data[$row][1] .= __('Delete custom values') . ': ';
$table->data[$row][1] .= html_print_select(
post_process_get_custom_values(), 'custom_values', "", "", '', '',
true);
$count_custom_postprocess = post_process_get_custom_values();
$table->data[$row][1] .= html_print_button (__('Delete'),
'custom_values_del_btn',
empty($count_custom_postprocess), "",
'class="sub cancel"', true);
// This hidden field will be filled from jQuery before submit
$table->data[$row][1] .= html_print_input_hidden(
'custom_value_to_delete', '', true);
$table->data[$row][1] .= "</table>";
//----------------------------------------------------------------------
//----------------------------------------------------------------------
// CUSTOM INTERVAL VALUES
//----------------------------------------------------------------------
$row++;
$table->data[$row][0] = __('Interval values');
$units = array(
1 => __('seconds'),
SECONDS_1MINUTE => __('minutes'),
@ -136,7 +172,6 @@ $units = array(
SECONDS_1DAY => __('days'),
SECONDS_1MONTH => __('months'),
SECONDS_1YEAR => __('years'));
$table->data[$row][1] = __('Add new custom value to intervals') . ': ';
$table->data[$row][1] .= html_print_input_text ('interval_value', '', '', 5, 5, true);
$table->data[$row][1] .= html_print_select ($units, 'interval_unit', 1, "", '', '', true, false, false);
@ -150,9 +185,11 @@ $table->data[$row][1] .= html_print_button (__('Delete'), 'interval_del_btn', em
$table->data[$row][1] .= html_print_input_hidden ('interval_values', $config["interval_values"], true);
// This hidden field will be filled from jQuery before submit
$table->data[$row][1] .= html_print_input_hidden ('interval_to_delete', '', true);
//----------------------------------------------------------------------
$row++;
$table->data[$row][0] = __('Style template');
$table->data[$row][1] = html_print_select (themes_get_css (), 'style', $config["style"].'.css', '', '', '', true);
@ -597,6 +634,31 @@ $(document).ready (function () {
$("#form_setup #text-graph_color9").attachColorPicker();
$("#form_setup #text-graph_color10").attachColorPicker();
//------------------------------------------------------------------
// CUSTOM VALUES POST PROCESS
//------------------------------------------------------------------
$("#button-custom_values_del_btn").click( function() {
var interval_selected = $('#custom_values').val();
$('#hidden-custom_value_to_delete').val(interval_selected);
$("input[name='custom_value']").val("");
$("input[name='custom_text']").val("");
$('#submit-update_button').trigger('click');
});
$("#button-custom_value_add_btn").click( function() {
$('#hidden-custom_value_add').val(1);
$('#submit-update_button').trigger('click');
});
//------------------------------------------------------------------
//------------------------------------------------------------------
// CUSTOM INTERVAL VALUES
//------------------------------------------------------------------
$("#button-interval_del_btn").click( function() {
var interval_selected = $('#intervals option:selected').val();
$('#hidden-interval_to_delete').val(interval_selected);
@ -606,6 +668,8 @@ $(document).ready (function () {
$("#button-interval_add_btn").click( function() {
$('#submit-update_button').trigger('click');
});
//------------------------------------------------------------------
// Juanma (06/05/2014) New feature: Custom front page for reports
var custom_report = $('#checkbox-custom_report_front')

View File

@ -456,6 +456,41 @@ function config_update_config () {
if (!config_update_value ('show_group_name', get_parameter('show_group_name')))
$error_update[] = __('Show the group name instead the group icon.');
//--------------------------------------------------
// CUSTOM VALUES POST PROCESS
//--------------------------------------------------
$custom_value = get_parameter('custom_value');
$custom_text = get_parameter('custom_text');
$custom_value_add = (bool)get_parameter('custom_value_add', 0);
$custom_value_to_delete = get_parameter('custom_value_to_delete', 0);
$custom_value = str_replace(',', '.', $custom_value);
if ($custom_value_add) {
require_once("include/functions_post_process.php");
if (!post_process_add_custom_value(
$custom_text, (string)$custom_value))
$error_update[] = __('Add the custom post process');
}
if ($custom_value_to_delete > 0) {
require_once("include/functions_post_process.php");
if (!post_process_delete_custom_value($custom_value_to_delete)) {
$error_update[] = __('Delete the custom post process');
}
}
//--------------------------------------------------
//--------------------------------------------------
// CUSTOM INTERVAL VALUES
//--------------------------------------------------
$interval_values = get_parameter ('interval_values');
// Add new interval value if is provided
@ -489,8 +524,12 @@ function config_update_config () {
$interval_values = implode(',',$interval_values_array);
}
if (!config_update_value ('interval_values', $interval_values))
$error_update[] = __('Delete interval');
if (!config_update_value ('interval_values', $interval_values))
$error_update[] = __('Delete interval');
//--------------------------------------------------
// Juanma (06/05/2014) New feature: Custom front page for reports
if (!config_update_value ('custom_report_front', get_parameter('custom_report_front')))
@ -1245,6 +1284,11 @@ function config_process_config () {
config_update_value ('tutorial_mode', 'full');
}
if (!isset($config['post_process_custom_values'])) {
config_update_value ('post_process_custom_values',
json_encode(array()));
}
/* Finally, check if any value was overwritten in a form */
config_update_config();
}

View File

@ -599,6 +599,90 @@ function html_print_select_from_sql ($sql, $name, $selected = '',
$disabled, $style,'', $size);
}
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,
$disabled = false) {
global $config;
require_once("include/functions_post_process.php");
$fields = post_process_get_custom_values();
$selected_float = (float)$selected;
$found = false;
foreach ($fields as $value => $text) {
$value = (float)$value;
if ($value == $selected_float) {
$found = true;
break;
}
}
if (!$found) {
$fields[floatval($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('$uniq_name');
post_process_select_events('$uniq_name');
});
</script>";
$returnString = ob_get_clean();
if ($return)
return $returnString;
else
echo $returnString;
}
/**
* Render a pair of select for times and text box for set the time more fine.
*
@ -615,8 +699,10 @@ function html_print_select_from_sql ($sql, $name, $selected = '',
* @return string HTML code if return parameter is true.
*/
function html_print_extended_select_for_time ($name, $selected = '', $script = '', $nothing = '',
$nothing_value = '0', $size = false, $return = false, $select_style = false, $unique_name = true) {
function html_print_extended_select_for_time ($name, $selected = '',
$script = '', $nothing = '', $nothing_value = '0', $size = false,
$return = false, $select_style = false, $unique_name = true) {
global $config;
$fields = get_periods();
@ -635,7 +721,7 @@ function html_print_extended_select_for_time ($name, $selected = '', $script = '
SECONDS_1YEAR => __('years'));
// The advanced control is only for admins
if(!is_user_admin($config['id_user'])) {
if (!is_user_admin($config['id_user'])) {
unset($fields[-1]);
$returnString = html_print_select ($fields, $name, $selected,"" . $script,

View File

@ -0,0 +1,86 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 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 Lesser General Public License
// as published by the Free Software Foundation; 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.
/**
* @package Include
* @subpackage Post Process
*/
// Load global vars
global $config;
function post_process_get_custom_values() {
global $config;
if (!isset($config['post_process_custom_values'])) {
$return = array();
}
else {
$return = json_decode(
$config['post_process_custom_values'], true);
}
if (empty($return)) {
$return = array();
}
return $return;
}
function post_process_add_custom_value($text, $value) {
global $config;
$value = (string)$value;
$post_process_custom_values = post_process_get_custom_values();
$post_process_custom_values[$value] = $text;
$new_conf = json_encode($post_process_custom_values);
$return = config_update_value(
'post_process_custom_values', $new_conf);
if ($return) {
$config['post_process_custom_values'] = $new_conf;
return true;
}
else {
return false;
}
}
function post_process_delete_custom_value($value) {
global $config;
$post_process_custom_values = post_process_get_custom_values();
unset($post_process_custom_values[$value]);
$new_conf = json_encode($post_process_custom_values);
$return = config_update_value(
'post_process_custom_values', $new_conf);
if ($return) {
$config['post_process_custom_values'] = $new_conf;
return true;
}
else {
return false;
}
}
?>

View File

@ -493,6 +493,69 @@ function agent_changed_by_multiple_agents_id (event, id_agent, selected) {
);
}
function post_process_select_init(name) {
// Manual mode is hidden by default
$('#' + name + '_manual').hide();
$('#' + name + '_default').show();
}
function post_process_select_events(name) {
$('.' + name + '_toggler').click(function() {
var value = $('#text-' + name + '_text').val();
var count = $('#' + name + '_select option')
.filter(function(i, item) {
if (Number($(item).val()) == Number(value))
return true;
else return false;
})
.length;
if (count != 1) {
$('#' + name + '_select')
.append($("<option>").val(value).text(value));
}
$('#' + name + '_select option')
.filter(function(i, item) {
if (Number($(item).val()) == Number(value))
return true;
else return false;
})
.prop("selected", true);
//~ $('#' + name + '_select').val(value);
toggleBoth(name);
$('#text-' + name + '_text').focus();
});
// When select a default period, is setted in seconds
$('#' + name + '_select').change(function() {
var value = $('#' + name + '_select').val();
$('.' + name).val(value);
$('#text-' + name + '_text').val(value);
});
$('#text-' + name + '_text').keyup (function () {
var value = $('#text-' + name + '_text').val();
if (isNaN(value)) {
value = 0;
$('#text-' + name + '_text').val(value);
}
else {
$('.' + name).val(value);
}
});
}
/**
* Init values for html_extended_select_for_time
*
@ -550,7 +613,7 @@ function period_select_events(name) {
$('#text-'+name+'_text').focus();
}
$('.'+name).val(value);
$('.'+name).val(value);
$('#text-'+name+'_text').val(value);
adjustTextUnits(name);
});

View File

@ -106,7 +106,8 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('custom_report_front_font', 'FreeSans.ttf'),
('custom_report_front_logo', 'images/pandora_logo_white.jpg'),
('custom_report_front_header', ''),
('custom_report_front_footer', '');
('custom_report_front_footer', ''),
('post_process_custom_values', '{"0.00000038580247":"Seconds&#x20;to&#x20;months","0.00000165343915":"Seconds&#x20;to&#x20;weeks","0.00001157407407":"Seconds&#x20;to&#x20;days","0.01666666666667":"Seconds&#x20;to&#x20;minutes","0.00000000093132":"Bytes&#x20;to&#x20;Gigabytes","0.00000095367432":"Bytes&#x20;to&#x20;Megabytes","0.0009765625":"Bytes&#x20;to&#x20;Kilobytes","0.00000001653439":"Timeticks&#x20;to&#x20;weeks","0.00000011574074":"Timeticks&#x20;to&#x20;days"}');
UNLOCK TABLES;