Control inverse and percentege cannot be selected at same time

This commit is contained in:
Calvo 2021-11-26 11:55:38 +01:00
parent 5464a73a12
commit 54755db59b
6 changed files with 311 additions and 16 deletions

View File

@ -456,8 +456,9 @@ if (modules_is_string_type($id_module_type) || $edit) {
).'</span>'; ).'</span>';
} }
$table_simple->data[2][1] .= '<br /><em>'.__('Inverse interval').'</em>'; $table_simple->data[2][1] .= '<div id="warning_inverse"><em>'.__('Inverse interval').'</em>';
$table_simple->data[2][1] .= html_print_checkbox('warning_inverse', 1, $warning_inverse, true, $disabledBecauseInPolicy); $table_simple->data[2][1] .= html_print_checkbox('warning_inverse', 1, $warning_inverse, true, $disabledBecauseInPolicy);
$table_simple->data[2][1] .= '</div>';
if (modules_is_string_type($id_module_type) === false) { if (modules_is_string_type($id_module_type) === false) {
$table_simple->data[2][1] .= '<div id="percentage_warning"><em>'.__('Percentage').'</em>'; $table_simple->data[2][1] .= '<div id="percentage_warning"><em>'.__('Percentage').'</em>';
@ -515,8 +516,10 @@ if (modules_is_string_type($id_module_type) || $edit) {
).'</span>'; ).'</span>';
} }
$table_simple->data[3][1] .= '<br /><em>'.__('Inverse interval').'</em>'; $table_simple->data[3][1] .= '<div id="critical_inverse"><em>'.__('Inverse interval').'</em>';
$table_simple->data[3][1] .= html_print_checkbox('critical_inverse', 1, $critical_inverse, true, $disabledBecauseInPolicy); $table_simple->data[3][1] .= html_print_checkbox('critical_inverse', 1, $critical_inverse, true, $disabledBecauseInPolicy);
$table_simple->data[3][1] .= '</div>';
if (modules_is_string_type($id_module_type) === false) { if (modules_is_string_type($id_module_type) === false) {
$table_simple->data[3][1] .= '<div id="percentage_critical" /><em>'.__('Percentage').'</em>'; $table_simple->data[3][1] .= '<div id="percentage_critical" /><em>'.__('Percentage').'</em>';
@ -1644,11 +1647,64 @@ $(document).ready (function () {
$('#text-max_critical').val(0); $('#text-max_critical').val(0);
} }
}); });
if ($('#checkbox-warning_inverse').prop('checked') === true) {
$('#percentage_warning').hide();
}
if ($('#checkbox-critical_inverse').prop('checked') === true) {
$('#percentage_critical').hide();
}
if ($('#checkbox-percentage_warning').prop('checked') === true) {
$('#warning_inverse').hide();
}
if ($('#checkbox-percentage_critical').prop('checked') === true) {
$('#critical_inverse').hide();
}
$('#checkbox-warning_inverse').change (function() { $('#checkbox-warning_inverse').change (function() {
paint_graph_values(); paint_graph_values();
}); if ($('#checkbox-warning_inverse').prop('checked') === true){
$('#checkbox-percentage_warning').prop('checked', false);
$('#percentage_warning').hide();
} else {
$('#percentage_warning').show();
}
});
$('#checkbox-critical_inverse').change (function() { $('#checkbox-critical_inverse').change (function() {
paint_graph_values(); paint_graph_values();
if ($('#checkbox-critical_inverse').prop('checked') === true){
$('#checkbox-percentage_critical').prop('checked', false);
$('#percentage_critical').hide();
} else {
$('#percentage_critical').show();
}
});
$('#checkbox-percentage_warning').change (function() {
paint_graph_values();
if ($('#checkbox-percentage_warning').prop('checked') === true){
$('#checkbox-warning_inverse').prop('checked', false);
$('#warning_inverse').hide();
} else {
$('#warning_inverse').show();
}
});
$('#checkbox-percentage_critical').change (function() {
paint_graph_values();
if ($('#checkbox-percentage_critical').prop('checked') === true){
$('#checkbox-critical_inverse').prop('checked', false);
$('#critical_inverse').hide();
}
else {
$('#critical_inverse').show();
}
}); });
}); });
@ -1931,6 +1987,43 @@ function paint_graph_values(){
//messages error //messages error
var message_error_warning = '<?php echo __('Please introduce a maximum warning higher than the minimun warning'); ?>'; var message_error_warning = '<?php echo __('Please introduce a maximum warning higher than the minimun warning'); ?>';
var message_error_critical = '<?php echo __('Please introduce a maximum critical higher than the minimun critical'); ?>'; var message_error_critical = '<?php echo __('Please introduce a maximum critical higher than the minimun critical'); ?>';
var message_error_percentage = '<?php echo __('Please introduce a positive percentage value'); ?>';
//Percentage selector
var percentage_w = $('#checkbox-percentage_warning').prop('checked');
var percentage_c = $('#checkbox-percentage_critical').prop('checked');
if(percentage_w == true || percentage_c == true) {
d3.select("#svg_dinamic rect").remove();
//create svg
var svg = d3.select("#svg_dinamic");
svg.selectAll("g").remove();
if (percentage_w === true) {
if(max_w < 0 || min_w < 0) {
paint_graph_status(0,0,0,0,0,0,1,0,legend_normal,legend_warning,legend_critical,message_error_percentage,message_error_percentage);
} else {
$("#text-max_warning").removeClass("input_error");
$("#text-min_warning").removeClass("input_error");
}
}
if(percentage_c === true) {
if(max_c < 0 || min_c < 0) {
paint_graph_status(0,0,0,0,0,0,0,1,legend_normal,legend_warning,legend_critical,message_error_percentage,message_error_percentage);
} else {
$("#text-min-critical").removeClass("input_error");
$("#text-max_critical").removeClass("input_error");
}
}
return;
} else {
$('#svg_dinamic').show();
}
//if haven't error //if haven't error
if(max_w == 0 || max_w > min_w){ if(max_w == 0 || max_w > min_w){

View File

@ -1876,6 +1876,31 @@ $(document).ready (function () {
} }
} }
}); });
$('#warning_inverse').change(function() {
if($(this).val() == 1) {
$("#percentage_warning").val('0').change()
}
});
$('#critical_inverse').change(function() {
if($(this).val() == 1) {
$("#percentage_critical").val('0').change();
}
});
$('#percentage_warning').change(function() {
if($(this).val() == 1) {
$("#warning_inverse").val('0').change()
}
});
$('#percentage_critical').change(function() {
if($(this).val() == 1) {
$("#critical_inverse").val('0').change()
}
});
}); });

View File

@ -829,6 +829,60 @@ $(document).ready (function () {
}); });
$("#snmp_version" ).trigger("change"); $("#snmp_version" ).trigger("change");
if ($('#checkbox-warning_inverse').prop('checked') === true) {
$('#percentage_warning').hide();
}
if ($('#checkbox-critical_inverse').prop('checked') === true) {
$('#percentage_critical').hide();
}
if ($('#checkbox-percentage_warning').prop('checked') === true) {
$('#warning_inverse').hide();
}
if ($('#checkbox-percentage_critical').prop('checked') === true) {
$('#critical_inverse').hide();
}
$('#checkbox-warning_inverse').change (function() {
if ($('#checkbox-warning_inverse').prop('checked') === true){
$('#checkbox-percentage_warning').prop('checked', false);
$('#percentage_warning').hide();
} else {
$('#percentage_warning').show();
}
});
$('#checkbox-critical_inverse').change (function() {
if ($('#checkbox-critical_inverse').prop('checked') === true){
$('#checkbox-percentage_critical').prop('checked', false);
$('#percentage_critical').hide();
} else {
$('#percentage_critical').show();
}
});
$('#checkbox-percentage_warning').change (function() {
if ($('#checkbox-percentage_warning').prop('checked') === true){
$('#checkbox-warning_inverse').prop('checked', false);
$('#warning_inverse').hide();
} else {
$('#warning_inverse').show();
}
});
$('#checkbox-percentage_critical').change (function() {
if ($('#checkbox-percentage_critical').prop('checked') === true){
$('#checkbox-critical_inverse').prop('checked', false);
$('#critical_inverse').hide();
}
else {
$('#critical_inverse').show();
}
});
}); });
<?php <?php

View File

@ -13,6 +13,8 @@
// GNU General Public License for more details. // GNU General Public License for more details.
global $config; global $config;
require_once $config['homedir'].'/include/graphs/functions_d3.php'; require_once $config['homedir'].'/include/graphs/functions_d3.php';
include_javascript_d3();
if (! check_acl($config['id_user'], 0, 'PM') && ! check_acl($config['id_user'], 0, 'AW')) { if (! check_acl($config['id_user'], 0, 'PM') && ! check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit( db_pandora_audit(
@ -185,8 +187,9 @@ $table->data[4][1] .= html_print_input_text(
1024, 1024,
true true
).'</span>'; ).'</span>';
$table->data[4][1] .= '<br /><em>'.__('Inverse interval').'</em>'; $table->data[4][1] .= '<div id="warning_inverse"><em>'.__('Inverse interval').'</em>';
$table->data[4][1] .= html_print_checkbox('warning_inverse', 1, $warning_inverse, true); $table->data[4][1] .= html_print_checkbox('warning_inverse', 1, $warning_inverse, true);
$table->data[4][1] .= '</div>';
$table->data[4][1] .= '<div id="percentage_warning"><em>'.__('Percentage').'</em>'; $table->data[4][1] .= '<div id="percentage_warning"><em>'.__('Percentage').'</em>';
$table->data[4][1] .= html_print_checkbox('percentage_warning', 1, $percentage_warning, true); $table->data[4][1] .= html_print_checkbox('percentage_warning', 1, $percentage_warning, true);
@ -224,8 +227,9 @@ $table->data[5][1] .= html_print_input_text(
1024, 1024,
true true
).'</span>'; ).'</span>';
$table->data[5][1] .= '<br /><em>'.__('Inverse interval').'</em>'; $table->data[5][1] .= '<div id="critical_inverse"><em>'.__('Inverse interval').'</em>';
$table->data[5][1] .= html_print_checkbox('critical_inverse', 1, $critical_inverse, true); $table->data[5][1] .= html_print_checkbox('critical_inverse', 1, $critical_inverse, true);
$table->data[5][1] .= '</div>';
$table->data[5][1] .= '<div id="percentage_critical"><em>'.__('Percentage').'</em>'; $table->data[5][1] .= '<div id="percentage_critical"><em>'.__('Percentage').'</em>';
$table->data[5][1] .= html_print_checkbox('percentage_critical', 1, $percentage_critical, true); $table->data[5][1] .= html_print_checkbox('percentage_critical', 1, $percentage_critical, true);
@ -580,11 +584,64 @@ $next_row++;
$('#text-max_critical').val(0); $('#text-max_critical').val(0);
} }
}); });
if ($('#checkbox-warning_inverse').prop('checked') === true) {
$('#percentage_warning').hide();
}
if ($('#checkbox-critical_inverse').prop('checked') === true) {
$('#percentage_critical').hide();
}
if ($('#checkbox-percentage_warning').prop('checked') === true) {
$('#warning_inverse').hide();
}
if ($('#checkbox-percentage_critical').prop('checked') === true) {
$('#critical_inverse').hide();
}
$('#checkbox-warning_inverse').change (function() { $('#checkbox-warning_inverse').change (function() {
paint_graph_values(); paint_graph_values();
}); if ($('#checkbox-warning_inverse').prop('checked') === true){
$('#checkbox-percentage_warning').prop('checked', false);
$('#percentage_warning').hide();
} else {
$('#percentage_warning').show();
}
});
$('#checkbox-critical_inverse').change (function() { $('#checkbox-critical_inverse').change (function() {
paint_graph_values(); paint_graph_values();
if ($('#checkbox-critical_inverse').prop('checked') === true){
$('#checkbox-percentage_critical').prop('checked', false);
$('#percentage_critical').hide();
} else {
$('#percentage_critical').show();
}
});
$('#checkbox-percentage_warning').change (function() {
paint_graph_values();
if ($('#checkbox-percentage_warning').prop('checked') === true){
$('#checkbox-warning_inverse').prop('checked', false);
$('#warning_inverse').hide();
} else {
$('#warning_inverse').show();
}
});
$('#checkbox-percentage_critical').change (function() {
paint_graph_values();
if ($('#checkbox-percentage_critical').prop('checked') === true){
$('#checkbox-critical_inverse').prop('checked', false);
$('#critical_inverse').hide();
}
else {
$('#critical_inverse').show();
}
}); });
}); });
@ -648,6 +705,43 @@ $next_row++;
//messages error //messages error
var message_error_warning = '<?php echo __('Please introduce a maximum warning higher than the minimun warning'); ?>'; var message_error_warning = '<?php echo __('Please introduce a maximum warning higher than the minimun warning'); ?>';
var message_error_critical = '<?php echo __('Please introduce a maximum critical higher than the minimun critical'); ?>'; var message_error_critical = '<?php echo __('Please introduce a maximum critical higher than the minimun critical'); ?>';
var message_error_percentage = '<?php echo __('Please introduce a positive percentage value'); ?>';
//Percentage selector
var percentage_w = $('#checkbox-percentage_warning').prop('checked');
var percentage_c = $('#checkbox-percentage_critical').prop('checked');
if(percentage_w == true || percentage_c == true) {
d3.select("#svg_dinamic rect").remove();
//create svg
var svg = d3.select("#svg_dinamic");
svg.selectAll("g").remove();
if (percentage_w === true) {
if(max_w < 0 || min_w < 0) {
paint_graph_status(0,0,0,0,0,0,1,0,legend_normal,legend_warning,legend_critical,message_error_percentage,message_error_percentage);
} else {
$("#text-max_warning").removeClass("input_error");
$("#text-min_warning").removeClass("input_error");
}
}
if(percentage_c === true) {
if(max_c < 0 || min_c < 0) {
paint_graph_status(0,0,0,0,0,0,0,1,legend_normal,legend_warning,legend_critical,message_error_percentage,message_error_percentage);
} else {
$("#text-min-critical").removeClass("input_error");
$("#text-max_critical").removeClass("input_error");
}
}
return;
} else {
$('#svg_dinamic').show();
}
//if haven't error //if haven't error
if(max_w == 0 || max_w > min_w){ if(max_w == 0 || max_w > min_w){

View File

@ -389,10 +389,13 @@ $data[1] .= '</span>';
$data[1] .= '<span class="string_values" id="warning_string_values"><em>'.__('String').' </em>&nbsp;'; $data[1] .= '<span class="string_values" id="warning_string_values"><em>'.__('String').' </em>&nbsp;';
$data[1] .= html_print_input_text('str_warning', $str_warning, '', 5, 1024, true).'</span>'; $data[1] .= html_print_input_text('str_warning', $str_warning, '', 5, 1024, true).'</span>';
// Warning inverse values. // Warning inverse values.
$data[1] .= '<br /><em>'.__('Inverse interval').'</em>&nbsp;'; $data[1] .= '<div id="warning_inverse"><em>'.__('Inverse interval').'</em>&nbsp;';
$data[1] .= html_print_checkbox('warning_inverse', 1, $warning_inverse, true); $data[1] .= html_print_checkbox('warning_inverse', 1, $warning_inverse, true);
$data[1] .= '<br /><em>'.__('Percentage').'</em>&nbsp;'; $data[1] .= '</div>';
$data[1] .= '<div id="percentage_warning"><em>'.__('Percentage').'</em>&nbsp;';
$data[1] .= html_print_checkbox('percentage_warning', 1, $percentage_warning, true); $data[1] .= html_print_checkbox('percentage_warning', 1, $percentage_warning, true);
$data[1] .= '</div>';
$data[2] = '<svg id="svg_dinamic" width="500" height="300"> </svg>'; $data[2] = '<svg id="svg_dinamic" width="500" height="300"> </svg>';
$table->colspan['warning-svg-row'][2] = 2; $table->colspan['warning-svg-row'][2] = 2;
@ -427,10 +430,13 @@ $data[1] .= '</span>';
$data[1] .= '<span class="string_values" id="critical_string_values"><em>'.__('String').' </em>&nbsp;'; $data[1] .= '<span class="string_values" id="critical_string_values"><em>'.__('String').' </em>&nbsp;';
$data[1] .= html_print_input_text('str_critical', $str_critical, '', 5, 1024, true).'</span>'; $data[1] .= html_print_input_text('str_critical', $str_critical, '', 5, 1024, true).'</span>';
// Critical inverse values. // Critical inverse values.
$data[1] .= '<br /><em>'.__('Inverse interval').'</em>&nbsp;'; $data[1] .= '<div id="critical_inverse"><em>'.__('Inverse interval').'</em>&nbsp;';
$data[1] .= html_print_checkbox('critical_inverse', 1, $critical_inverse, true); $data[1] .= html_print_checkbox('critical_inverse', 1, $critical_inverse, true);
$data[1] .= '<br /><em>'.__('Percentage').'</em>&nbsp;'; $data[1] .= '</div>';
$data[1] .= '<Ddiv id="percentage_critical"><em>'.__('Percentage').'</em>&nbsp;';
$data[1] .= html_print_checkbox('percentage_critical', 1, $percentage_critical, true); $data[1] .= html_print_checkbox('percentage_critical', 1, $percentage_critical, true);
$data[1] .= '</div>';
push_table_row($data, 'critical-row'); push_table_row($data, 'critical-row');

View File

@ -4105,7 +4105,7 @@ class AgentWizard extends HTML
$module['inv_warning'], $module['inv_warning'],
true, true,
false, false,
'', 'change_control(this, \''.$uniqueId.'\')',
false, false,
'form="form-create-modules"' 'form="form-create-modules"'
), ),
@ -4122,7 +4122,7 @@ class AgentWizard extends HTML
$module['perc_warning'], $module['perc_warning'],
true, true,
false, false,
'', 'change_control(this, \''.$uniqueId.'\')',
false, false,
'form="form-create-modules"' 'form="form-create-modules"'
), ),
@ -4184,12 +4184,12 @@ class AgentWizard extends HTML
'class' => 'wizard-column-levels-check', 'class' => 'wizard-column-levels-check',
'style' => 'margin-top: 0.3em;', 'style' => 'margin-top: 0.3em;',
'content' => html_print_checkbox( 'content' => html_print_checkbox(
'module-critical_inv_'.$uniqueId, 'module-critical-inv-'.$uniqueId,
$module['inv_critical'], $module['inv_critical'],
$module['inv_critical'], $module['inv_critical'],
true, true,
false, false,
'', 'change_control(this, \''.$uniqueId.'\')',
false, false,
'form="form-create-modules"' 'form="form-create-modules"'
), ),
@ -4207,7 +4207,7 @@ class AgentWizard extends HTML
$module['perc_critical'], $module['perc_critical'],
true, true,
false, false,
'', 'change_control(this,\''.$uniqueId.'\')',
false, false,
'form="form-create-modules"' 'form="form-create-modules"'
), ),
@ -5922,6 +5922,29 @@ class AgentWizard extends HTML
}); });
} }
function change_control(checkbox, uniqueId) {
var checkbox_name = $(checkbox).attr('name');
if($(checkbox).prop('checked', true)) {
if(checkbox_name.match(/warning-inv/gm) !== null) {
$('#checkbox-module-warning-perc-'+uniqueId).prop('checked', false);
}
if(checkbox_name.match(/critical-inv/gm) !== null) {
$('#checkbox-module-critical-perc-'+uniqueId).prop('checked', false);
}
if(checkbox_name.match(/warning-perc/gm) !== null) {
$('#checkbox-module-warning-inv-'+uniqueId).prop('checked', false);
}
if(checkbox_name.match(/critical-perc/gm) !== null) {
$('#checkbox-module-critical-inv-'+uniqueId).prop('checked', false);
}
}
}
</script> </script>
<?php <?php
$str = ob_get_clean(); $str = ob_get_clean();