diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index a46251f664..a30b2932d2 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -3536,7 +3536,7 @@ function api_get_all_planned_downtimes ($thrash1, $thrash2, $other, $returnType $values = array(); $values = array( - 'name' => $other['data'][0] + "name LIKE '%".$other['data'][0]."%'" ); if (isset($other['data'][1]) && ($other['data'][1] != false )) @@ -3559,31 +3559,58 @@ function api_get_all_planned_downtimes ($thrash1, $thrash2, $other, $returnType * Return all items of planned downtime. * * @param $id id of planned downtime. - * @param + * @param array $other it's array, $other as param is ;;;;; in this order + * and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_) + * * example: * - * api.php?op=set&op2=planned_downtimes_items&id=10&other_mode=url_encode_separator_|&return_type=json + * api.php?op=get&op2=planned_downtimes_items&other=test|0|quiet|periodically|weekly&other_mode=url_encode_separator_|&return_type=json * * @param type of return json or csv. */ -function api_get_planned_downtimes_items ($id, $thrash2, $other, $returnType = 'json') { +function api_get_planned_downtimes_items ($thrash1, $thrash2, $other, $returnType = 'json') { if (defined ('METACONSOLE')) { return; } $values = array(); $values = array( - 'id_downtime' => $id + "name LIKE '%".$other['data'][0]."%'" ); - $returned = planned_downtimes_items($values); + if (isset($other['data'][1]) && ($other['data'][1] != false )) + $values['id_group'] = $other['data'][1]; + if (isset($other['data'][2]) && ($other['data'][2] != false)) + $values['type_downtime'] = $other['data'][2]; + if (isset($other['data'][3]) && ($other['data'][3]!= false) ) + $values['type_execution'] = $other['data'][3]; + if (isset($other['data'][4]) && ($other['data'][4] != false) ) + $values['type_periodicity'] = $other['data'][4]; + + + $returned = all_planned_downtimes($values); + + $is_quiet = false; + $return = array('list_index'=>array('id_agents','id_downtime','all_modules')); + + foreach ($returned as $downtime) { + if ($downtime['type_downtime'] === 'quiet') + $is_quiet = true; + + $filter['id_downtime'] = $downtime['id']; + + $return[] = planned_downtimes_items ($filter); + } + + if ($is_quiet) + $return['list_index'][] = 'modules'; if ( $returnType == 'json' ) - unset($returned['list_index']); + unset($return['list_index']); returnData($returnType, - array('type' => 'array', 'data' => $returned)); + array('type' => 'array', 'data' => $return)); } /** @@ -3593,7 +3620,7 @@ function api_get_planned_downtimes_items ($id, $thrash2, $other, $returnType = ' * @param $thrash1 not use. * @param $thrash2 not use. * - * api.php?op=set&op2=planned_downtimes_deleted &id=10&return_type=json + * api.php?op=set&op2=planned_downtimes_deleted &id=10 * * @param type of return json or csv. */ @@ -3644,8 +3671,8 @@ function api_set_planned_downtimes_created ($id, $thrash1, $other, $thrash3) { $values = array( 'name' => $id, 'description' => $other['data'][0], - 'datetime_from' => $date_from, - 'datetime_to' => $date_to, + 'date_from' => $date_from, + 'date_to' => $date_to, 'id_group' => $other['data'][3], 'monday' => $other['data'][4], 'tuesday' => $other['data'][5], @@ -3706,7 +3733,7 @@ function api_set_planned_downtimes_additem ($id, $thrash1, $other, $thrash3) { } if ( isset($other['data'][1]) ) - $name_modules = explode(';',$other['data'][1]); + $name_modules = explode(';',io_safe_output($other['data'][1])); else $name_modules = false; diff --git a/pandora_console/include/functions_planned_downtimes.php b/pandora_console/include/functions_planned_downtimes.php index 3be7e4833e..8da0660504 100644 --- a/pandora_console/include/functions_planned_downtimes.php +++ b/pandora_console/include/functions_planned_downtimes.php @@ -182,7 +182,8 @@ function planned_downtimes_add_items ($downtime_id, $agents, $all_modules = true } else if (!$all_modules) { foreach ($module_names as $module_name) { - $module = modules_get_agentmodule_id($module_name, $agent_id); + + $module = modules_get_agentmodule_id(io_safe_input($module_name), $agent_id); $result = false; if ($module) { @@ -672,16 +673,16 @@ function planned_downtimes_created ($values) { $now = time(); $result = false; - if ($values['type_execution'] == 'once' && !$config["past_planned_downtimes"] && $values['datetime_from'] < $now) { + if ($values['type_execution'] == 'once' && !$config["past_planned_downtimes"] && $values['date_from'] < $now) { return array('return' => false, 'message' => __('Not created. Error inserting data. Start time must be higher than the current time')); } - else if ($values['type_execution'] == 'once' && $values['datetime_from'] >= $values['datetime_to']) { + else if ($values['type_execution'] == 'once' && $values['date_from'] >= $values['date_to']) { return array('return' => false, 'message' => __('Not created. Error inserting data') . ". " . __('The end date must be higher than the start date')); } - else if ($values['type_execution'] == 'once' && $values['datetime_to'] <= $now) { + else if ($values['type_execution'] == 'once' && $values['date_to'] <= $now) { return array('return' => false, 'message' => __('Not created. Error inserting data') . ". " . __('The end date must be higher than the current time')); @@ -752,10 +753,8 @@ function planned_downtimes_items ($filter) { $downtime_agents = db_get_all_rows_filter('tplanned_downtime_agents',$filter, 'id_agent,id_downtime,all_modules'); $downtime = db_get_row_filter('tplanned_downtime',array('id' => $filter['id_downtime']), 'type_downtime'); - $return = array('list_index'=>array('id_agents','id_downtime','all_modules')); - foreach ( $downtime_agents as $key => $data ) { - $return[$key] = $data; + $return = $data; $modules = array(); if ($downtime['type_downtime'] === 'quiet') { if (!$data['all_modules']) { @@ -768,16 +767,12 @@ function planned_downtimes_items ($filter) { foreach ( $downtime_modules as $data2 ) { $modules[] = $data2['id_agent_module']; } - $return[$key]['modules'] = implode(',', $modules); + $return['modules'] = implode(',', $modules); } } } } - if ($downtime['type_downtime'] === 'quiet') { - $return['list_index'][] = 'modules'; - } - return $return; } diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 742499e17a..a19718907e 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -110,8 +110,8 @@ sub help_screen{ 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('--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'); + help_screen_line('--get_all_planned_downtimes', ' [ ]', 'Get all planned downtime'); + help_screen_line('--get_planned_downtimes_items', ' [ ]', 'Get all items of planned downtimes'); help_screen_line('--set_planned_downtimes_deleted', ' ', 'Deleted a planned downtime'); help_screen_line('--get_agent_group', '', 'Get the group name of an agent'); help_screen_line('--get_agent_modules', '', 'Get the modules of an agent'); @@ -635,7 +635,7 @@ sub pandora_get_planned_downtime_id ($$) { ########################################################################## sub pandora_get_all_planned_downtime ($$$$$$) { my ($dbh, $downtime_name, $id_group, $type_downtime, $type_execution, $type_periodicity) = @_; - my $sql = "SELECT * FROM tplanned_downtime WHERE name = ? ?"; + my $sql = "SELECT * FROM tplanned_downtime WHERE name LIKE '%".safe_input($downtime_name)."%' ?"; my $text_sql = ''; if (defined($id_group) && $id_group != '') { @@ -655,8 +655,7 @@ sub pandora_get_all_planned_downtime ($$$$$$) { $text_sql = ''; } - my @downtimes = get_db_rows ($dbh, $sql, - safe_input($downtime_name), $text_sql); + my @downtimes = get_db_rows ($dbh, $sql, $text_sql); return @downtimes; } @@ -3413,7 +3412,7 @@ sub cli_create_planned_downtime() { my $other = join('|', @todo); my $result = api_call(\%conf,'set', 'planned_downtimes_created', $name, undef, "$other"); - print $result; + print "$result \n\n "; } sub cli_add_item_planned_downtime() { @@ -3450,7 +3449,7 @@ sub cli_get_all_planned_downtime() { } else { foreach my $result (@results) { - print("ID: " . $result->{'id'} . ", NAME: " . $result->{'name'} . ", DESC: " . safe_output($result->{'description'}) . ", DATE FROM: " . + print("\nID: " . $result->{'id'} . ", NAME: " . $result->{'name'} . ", DESC: " . safe_output($result->{'description'}) . ", DATE FROM: " . localtime($result->{'date_from'}) . " DATE TO: " . localtime($result->{'date_to'}) . " \nID GROUP: " . $result->{'id_group'} . ", MONDAY: " . $result->{'monday'} . ", TUESDAY: " . $result->{'tuesday'} . ", WEDNESDAY: " . $result->{'wednesday'} . ", THURSDAY: " . $result->{'thursday'} . ", FRIDAY: " . $result->{'friday'} . @@ -3458,7 +3457,7 @@ sub cli_get_all_planned_downtime() { " \nPEDIODICALLY TIME TO: " . $result->{'periodically_time_to'} . ", PEDIODICALLY DAY FROM: " . $result->{'periodically_day_from'} . "PEDIODICALLY DAY TO: " . $result->{'periodically_day_to'} . ", TYPE DOWNTIME: " . $result->{'type_downtime'} . ", TYPE OF EXECUTION: " . $result->{'type_execution'} . "\nTYPE OF PERIODICITY: " . $result->{'type_periodicity'} . - ", USER: " . $result->{'id_user'} ."\n"); + ", USER: " . $result->{'id_user'} ."\n\n"); } } }