From a80c7e493e71dc46c52706a59ba2a634e4de49ec Mon Sep 17 00:00:00 2001 From: samucarc Date: Tue, 6 Nov 2018 16:42:03 +0100 Subject: [PATCH] Added check for the creation of planned downtimes by pandora manage --- pandora_console/include/functions_api.php | 3 ++- .../include/functions_planned_downtimes.php | 21 +++++++++++++++++++ pandora_server/util/pandora_manage.pl | 6 +++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 479929c619..7eb03e7248 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -5411,7 +5411,8 @@ function api_set_planned_downtimes_created ($id, $thrash1, $other, $thrash3) { 'periodically_day_to' => $other['data'][14], 'type_downtime' => $other['data'][15], 'type_execution' => $other['data'][16], - 'type_periodicity' => $other['data'][17] + 'type_periodicity' => $other['data'][17], + 'id_user' => $other['data'][18] ); $returned = planned_downtimes_created($values); diff --git a/pandora_console/include/functions_planned_downtimes.php b/pandora_console/include/functions_planned_downtimes.php index 67f9ec9f29..6e5ac261a2 100644 --- a/pandora_console/include/functions_planned_downtimes.php +++ b/pandora_console/include/functions_planned_downtimes.php @@ -666,6 +666,7 @@ function planned_downtimes_stop ($downtime) { function planned_downtimes_created ($values) { global $config; + $check_id_user = (bool) db_get_value ('id_user', 'tusuario', 'id_user', $values['id_user']); $check_group = (bool) db_get_value ('id_grupo', 'tgrupo', 'id_grupo', $values['id_group']); $check = (bool) db_get_value ('name', 'tplanned_downtime', 'name', $values['name']); @@ -703,6 +704,26 @@ function planned_downtimes_created ($values) { 'message' => __('Not created. Error inserting data') . ". " . __('The end day must be higher than the start day')); } + else if ($values['type_downtime'] !== 'quiet' && $values['type_downtime'] !== 'disable_agents' && $values['type_downtime'] !== 'disable_agents_alerts') { + return array('return' => false, + 'message' => __('Not created. Error inserting data') . ". " + . __('The downtime must be quiet, disable_agents or disable_agents_alerts')); + } + else if ($values['type_execution'] !== 'periodically' && $values['type_execution'] !== 'once' ) { + return array('return' => false, + 'message' => __('Not created. Error inserting data') . ". " + . __('The execution must be once or periodically')); + } + else if ($values['type_periodicity'] !== 'weekly' && $values['type_periodicity'] !== 'monthly' ) { + return array('return' => false, + 'message' => __('Not created. Error inserting data') . ". " + . __('The periodicity must be weekly or monthly')); + } + else if (!$check_id_user){ + return array('return' => false, + 'message' => __('Not created. Error inserting data') . ". " + . __('User not exist')); + } else if (!$check_group && $values['id_group'] != 0) { return array('return' => false, 'message' => __('Not created. Error inserting data') . ". " diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index f755c6f0bd..57b0c05a63 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -112,7 +112,7 @@ sub help_screen{ help_screen_line('--delete_group', '', 'Delete an agent group'); help_screen_line('--update_group', '','[ ]', 'Update an agent group'); help_screen_line('--stop_downtime', '', 'Stop a planned downtime'); - help_screen_line('--create_downtime', " \n\t \n\t ", 'Create a planned downtime'); + help_screen_line('--create_downtime', " \n\t \n\t ", 'Create a planned downtime'); help_screen_line('--add_item_planned_downtime', " ", 'Add a items planned downtime'); help_screen_line('--get_all_planned_downtimes', ' [ ]', 'Get all planned downtime'); help_screen_line('--get_planned_downtimes_items', ' [ ]', 'Get all items of planned downtimes'); @@ -4095,7 +4095,7 @@ sub cli_policy_add_agent() { sub cli_create_planned_downtime() { my $name = @ARGV[2]; - my @todo = @ARGV[3..20]; + my @todo = @ARGV[3..21]; my $other = join('|', @todo); my $result = api_call(\%conf,'set', 'planned_downtimes_created', $name, undef, "$other"); @@ -6035,7 +6035,7 @@ sub pandora_manage_main ($$$) { cli_add_tag_to_module(); } elsif ($param eq '--create_downtime') { - param_check($ltotal, 19); + param_check($ltotal, 20); cli_create_planned_downtime(); } elsif ($param eq '--add_item_downtime') {