Fixed functions of cli/pai of planned downtime. Tiquet: #3020
(cherry picked from commit 89fcaec748
)
This commit is contained in:
parent
d83baeb230
commit
4c79c11027
|
@ -3536,7 +3536,7 @@ function api_get_all_planned_downtimes ($thrash1, $thrash2, $other, $returnType
|
||||||
|
|
||||||
$values = array();
|
$values = array();
|
||||||
$values = array(
|
$values = array(
|
||||||
'name' => $other['data'][0]
|
"name LIKE '%".$other['data'][0]."%'"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($other['data'][1]) && ($other['data'][1] != false ))
|
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.
|
* Return all items of planned downtime.
|
||||||
*
|
*
|
||||||
* @param $id id of planned downtime.
|
* @param $id id of planned downtime.
|
||||||
* @param
|
* @param array $other it's array, $other as param is <name>;<id_group>;<type_downtime>;<type_execution>;<type_periodicity>; in this order
|
||||||
|
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>)
|
||||||
|
*
|
||||||
* example:
|
* 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.
|
* @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')) {
|
if (defined ('METACONSOLE')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = array();
|
$values = array();
|
||||||
$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' )
|
if ( $returnType == 'json' )
|
||||||
unset($returned['list_index']);
|
unset($return['list_index']);
|
||||||
|
|
||||||
returnData($returnType,
|
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 $thrash1 not use.
|
||||||
* @param $thrash2 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.
|
* @param type of return json or csv.
|
||||||
*/
|
*/
|
||||||
|
@ -3644,8 +3671,8 @@ function api_set_planned_downtimes_created ($id, $thrash1, $other, $thrash3) {
|
||||||
$values = array(
|
$values = array(
|
||||||
'name' => $id,
|
'name' => $id,
|
||||||
'description' => $other['data'][0],
|
'description' => $other['data'][0],
|
||||||
'datetime_from' => $date_from,
|
'date_from' => $date_from,
|
||||||
'datetime_to' => $date_to,
|
'date_to' => $date_to,
|
||||||
'id_group' => $other['data'][3],
|
'id_group' => $other['data'][3],
|
||||||
'monday' => $other['data'][4],
|
'monday' => $other['data'][4],
|
||||||
'tuesday' => $other['data'][5],
|
'tuesday' => $other['data'][5],
|
||||||
|
@ -3706,7 +3733,7 @@ function api_set_planned_downtimes_additem ($id, $thrash1, $other, $thrash3) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset($other['data'][1]) )
|
if ( isset($other['data'][1]) )
|
||||||
$name_modules = explode(';',$other['data'][1]);
|
$name_modules = explode(';',io_safe_output($other['data'][1]));
|
||||||
else
|
else
|
||||||
$name_modules = false;
|
$name_modules = false;
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,8 @@ function planned_downtimes_add_items ($downtime_id, $agents, $all_modules = true
|
||||||
}
|
}
|
||||||
else if (!$all_modules) {
|
else if (!$all_modules) {
|
||||||
foreach ($module_names as $module_name) {
|
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;
|
$result = false;
|
||||||
|
|
||||||
if ($module) {
|
if ($module) {
|
||||||
|
@ -672,16 +673,16 @@ function planned_downtimes_created ($values) {
|
||||||
$now = time();
|
$now = time();
|
||||||
$result = false;
|
$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,
|
return array('return' => false,
|
||||||
'message' => __('Not created. Error inserting data. Start time must be higher than the current time'));
|
'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,
|
return array('return' => false,
|
||||||
'message' => __('Not created. Error inserting data') . ". "
|
'message' => __('Not created. Error inserting data') . ". "
|
||||||
. __('The end date must be higher than the start date'));
|
. __('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,
|
return array('return' => false,
|
||||||
'message' => __('Not created. Error inserting data') . ". "
|
'message' => __('Not created. Error inserting data') . ". "
|
||||||
. __('The end date must be higher than the current time'));
|
. __('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_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');
|
$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 ) {
|
foreach ( $downtime_agents as $key => $data ) {
|
||||||
$return[$key] = $data;
|
$return = $data;
|
||||||
$modules = array();
|
$modules = array();
|
||||||
if ($downtime['type_downtime'] === 'quiet') {
|
if ($downtime['type_downtime'] === 'quiet') {
|
||||||
if (!$data['all_modules']) {
|
if (!$data['all_modules']) {
|
||||||
|
@ -768,16 +767,12 @@ function planned_downtimes_items ($filter) {
|
||||||
foreach ( $downtime_modules as $data2 ) {
|
foreach ( $downtime_modules as $data2 ) {
|
||||||
$modules[] = $data2['id_agent_module'];
|
$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;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,8 +110,8 @@ sub help_screen{
|
||||||
help_screen_line('--stop_downtime', '<downtime_name>', 'Stop a planned downtime');
|
help_screen_line('--stop_downtime', '<downtime_name>', 'Stop a planned downtime');
|
||||||
help_screen_line('--create_downtime', "<downtime_name> <description> <date_from> <date_to> <id_group> <monday> <tuesday>\n\t <wednesday> <thursday> <friday> <saturday> <sunday> <periodically_time_from>\n\t <periodically_time_to> <periodically_day_from> <periodically_day_to> <type_downtime> <type_execution> <type_periodicity>", 'Create a planned downtime');
|
help_screen_line('--create_downtime', "<downtime_name> <description> <date_from> <date_to> <id_group> <monday> <tuesday>\n\t <wednesday> <thursday> <friday> <saturday> <sunday> <periodically_time_from>\n\t <periodically_time_to> <periodically_day_from> <periodically_day_to> <type_downtime> <type_execution> <type_periodicity>", 'Create a planned downtime');
|
||||||
help_screen_line('--add_item_planned_downtime', "<id_downtime> <id_agente1,id_agente2,id_agente3...id_agenteN> <name_module1,name_module2,name_module3...name_moduleN> ", 'Add a items planned downtime');
|
help_screen_line('--add_item_planned_downtime', "<id_downtime> <id_agente1,id_agente2,id_agente3...id_agenteN> <name_module1,name_module2,name_module3...name_moduleN> ", 'Add a items planned downtime');
|
||||||
help_screen_line('--get_all_planned_downtimes', '<name> <id_group> <type_downtime> <type_execution> <type_periodicity>', 'Get all planned downtime');
|
help_screen_line('--get_all_planned_downtimes', '<name> [<id_group> <type_downtime> <type_execution> <type_periodicity>]', 'Get all planned downtime');
|
||||||
help_screen_line('--get_planned_downtimes_items', '<name> <id_group> <type_downtime> <type_execution> <type_periodicity>', 'Get all items of planned downtimes');
|
help_screen_line('--get_planned_downtimes_items', '<name> [<id_group> <type_downtime> <type_execution> <type_periodicity>]', 'Get all items of planned downtimes');
|
||||||
help_screen_line('--set_planned_downtimes_deleted', '<name> ', 'Deleted a planned downtime');
|
help_screen_line('--set_planned_downtimes_deleted', '<name> ', 'Deleted a planned downtime');
|
||||||
help_screen_line('--get_agent_group', '<agent_name>', 'Get the group name of an agent');
|
help_screen_line('--get_agent_group', '<agent_name>', 'Get the group name of an agent');
|
||||||
help_screen_line('--get_agent_modules', '<agent_name>', 'Get the modules of an agent');
|
help_screen_line('--get_agent_modules', '<agent_name>', 'Get the modules of an agent');
|
||||||
|
@ -635,7 +635,7 @@ sub pandora_get_planned_downtime_id ($$) {
|
||||||
##########################################################################
|
##########################################################################
|
||||||
sub pandora_get_all_planned_downtime ($$$$$$) {
|
sub pandora_get_all_planned_downtime ($$$$$$) {
|
||||||
my ($dbh, $downtime_name, $id_group, $type_downtime, $type_execution, $type_periodicity) = @_;
|
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 = '';
|
my $text_sql = '';
|
||||||
|
|
||||||
if (defined($id_group) && $id_group != '') {
|
if (defined($id_group) && $id_group != '') {
|
||||||
|
@ -655,8 +655,7 @@ sub pandora_get_all_planned_downtime ($$$$$$) {
|
||||||
$text_sql = '';
|
$text_sql = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
my @downtimes = get_db_rows ($dbh, $sql,
|
my @downtimes = get_db_rows ($dbh, $sql, $text_sql);
|
||||||
safe_input($downtime_name), $text_sql);
|
|
||||||
|
|
||||||
return @downtimes;
|
return @downtimes;
|
||||||
}
|
}
|
||||||
|
@ -3413,7 +3412,7 @@ sub cli_create_planned_downtime() {
|
||||||
my $other = join('|', @todo);
|
my $other = join('|', @todo);
|
||||||
|
|
||||||
my $result = api_call(\%conf,'set', 'planned_downtimes_created', $name, undef, "$other");
|
my $result = api_call(\%conf,'set', 'planned_downtimes_created', $name, undef, "$other");
|
||||||
print $result;
|
print "$result \n\n ";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cli_add_item_planned_downtime() {
|
sub cli_add_item_planned_downtime() {
|
||||||
|
@ -3450,7 +3449,7 @@ sub cli_get_all_planned_downtime() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foreach my $result (@results) {
|
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'}) .
|
localtime($result->{'date_from'}) . " DATE TO: " . localtime($result->{'date_to'}) .
|
||||||
" \nID GROUP: " . $result->{'id_group'} . ", MONDAY: " . $result->{'monday'} . ", TUESDAY: " . $result->{'tuesday'} .
|
" \nID GROUP: " . $result->{'id_group'} . ", MONDAY: " . $result->{'monday'} . ", TUESDAY: " . $result->{'tuesday'} .
|
||||||
", WEDNESDAY: " . $result->{'wednesday'} . ", THURSDAY: " . $result->{'thursday'} . ", FRIDAY: " . $result->{'friday'} .
|
", 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'} .
|
" \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'} .
|
"PEDIODICALLY DAY TO: " . $result->{'periodically_day_to'} . ", TYPE DOWNTIME: " . $result->{'type_downtime'} .
|
||||||
", TYPE OF EXECUTION: " . $result->{'type_execution'} . "\nTYPE OF PERIODICITY: " . $result->{'type_periodicity'} .
|
", TYPE OF EXECUTION: " . $result->{'type_execution'} . "\nTYPE OF PERIODICITY: " . $result->{'type_periodicity'} .
|
||||||
", USER: " . $result->{'id_user'} ."\n");
|
", USER: " . $result->{'id_user'} ."\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue