From 329cafad4999ac325cb01768d2dd67767e21e65b Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Wed, 11 Sep 2019 10:04:18 +0200 Subject: [PATCH 1/4] fixed fixed error on stop_downtime --- pandora_server/util/pandora_manage.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 98cca10392..8243053c37 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4818,6 +4818,25 @@ sub cli_stop_downtime () { my $current_time = time; my $downtime_date_to = get_db_value ($dbh, 'SELECT date_to FROM tplanned_downtime WHERE id=?', $downtime_id); + my $type_execution = get_db_value ($dbh, 'SELECT type_execution FROM tplanned_downtime WHERE id=?', $downtime_id); + + if($type_execution eq 'periodically'){ + + my $downtime_running = get_db_value ($dbh, 'SELECT executed FROM tplanned_downtime WHERE id=?', $downtime_id); + if($downtime_running == 1){ + print_log "[INFO] Planned_downtime '$downtime_name' can't be stopped\n\n"; + exit; + } + } + + + + if($current_time >= $downtime_date_to) { + print_log "[INFO] Planned_downtime '$downtime_name' is already stopped\n\n"; + exit; + } + + if($current_time >= $downtime_date_to) { print_log "[INFO] Planned_downtime '$downtime_name' is already stopped\n\n"; exit; From d2b7ec7a6f7200f22cb9830ba6eefa575bdaf9d1 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Wed, 11 Sep 2019 10:06:08 +0200 Subject: [PATCH 2/4] deleted duplicated code --- pandora_server/util/pandora_manage.pl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 8243053c37..d0a6d890cd 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4829,14 +4829,6 @@ sub cli_stop_downtime () { } } - - - if($current_time >= $downtime_date_to) { - print_log "[INFO] Planned_downtime '$downtime_name' is already stopped\n\n"; - exit; - } - - if($current_time >= $downtime_date_to) { print_log "[INFO] Planned_downtime '$downtime_name' is already stopped\n\n"; exit; From 64e69da924f70785c256e2ade191d52750bba3fe Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Wed, 11 Sep 2019 11:41:14 +0200 Subject: [PATCH 3/4] simplify code --- pandora_server/util/pandora_manage.pl | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index d0a6d890cd..c1a87d6454 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4818,17 +4818,14 @@ sub cli_stop_downtime () { my $current_time = time; my $downtime_date_to = get_db_value ($dbh, 'SELECT date_to FROM tplanned_downtime WHERE id=?', $downtime_id); - my $type_execution = get_db_value ($dbh, 'SELECT type_execution FROM tplanned_downtime WHERE id=?', $downtime_id); - - if($type_execution eq 'periodically'){ + my $data = get_db_single_row ($dbh, 'SELECT type_execution, executed FROM tplanned_downtime WHERE id=?', $downtime_id); - my $downtime_running = get_db_value ($dbh, 'SELECT executed FROM tplanned_downtime WHERE id=?', $downtime_id); - if($downtime_running == 1){ - print_log "[INFO] Planned_downtime '$downtime_name' can't be stopped\n\n"; + if( $data->{'type_execution'} eq 'periodically' && $data->{'executed'} == 1){ + print_log "[ERROR] Planned_downtime '$downtime_name' cannot be stopped.\n"; + print_log "[INFO] Periodical and running planned downtime cannot be stopped.\n\n"; exit; - } } - + if($current_time >= $downtime_date_to) { print_log "[INFO] Planned_downtime '$downtime_name' is already stopped\n\n"; exit; From 47b61a20255165376045b2c6e87a63a38594bd0e Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Wed, 11 Sep 2019 12:36:15 +0200 Subject: [PATCH 4/4] refactor --stop_downtime --- pandora_server/util/pandora_manage.pl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index c1a87d6454..3bd8012dfe 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4816,9 +4816,8 @@ sub cli_stop_downtime () { exist_check($downtime_id,'planned downtime',$downtime_id); my $current_time = time; - my $downtime_date_to = get_db_value ($dbh, 'SELECT date_to FROM tplanned_downtime WHERE id=?', $downtime_id); - my $data = get_db_single_row ($dbh, 'SELECT type_execution, executed FROM tplanned_downtime WHERE id=?', $downtime_id); + my $data = get_db_single_row ($dbh, 'SELECT date_to, type_execution, executed FROM tplanned_downtime WHERE id=?', $downtime_id); if( $data->{'type_execution'} eq 'periodically' && $data->{'executed'} == 1){ print_log "[ERROR] Planned_downtime '$downtime_name' cannot be stopped.\n"; @@ -4826,7 +4825,7 @@ sub cli_stop_downtime () { exit; } - if($current_time >= $downtime_date_to) { + if($current_time >= $data->{'date_to'}) { print_log "[INFO] Planned_downtime '$downtime_name' is already stopped\n\n"; exit; }