Add new calls in cli file. Tiquet: #3020

This commit is contained in:
m-lopez-f 2015-12-02 17:01:28 +01:00
parent 4d558f9919
commit afdb958451
1 changed files with 216 additions and 52 deletions

View File

@ -111,6 +111,9 @@ 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_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('--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');
help_screen_line('--get_agents', '[<group_name> <os_name> <status> <max_modules> <filter_substring> <policy_name>]', "Get \n\t list of agents with optative filter parameters"); help_screen_line('--get_agents', '[<group_name> <os_name> <status> <max_modules> <filter_substring> <policy_name>]', "Get \n\t list of agents with optative filter parameters");
@ -415,6 +418,29 @@ sub pandora_delete_user_profile ($$$$) {
return db_do ($dbh, 'DELETE FROM tusuario_perfil WHERE id_usuario=? AND id_perfil=? AND id_grupo=?', $user_id, $profile_id, $group_id); return db_do ($dbh, 'DELETE FROM tusuario_perfil WHERE id_usuario=? AND id_perfil=? AND id_grupo=?', $user_id, $profile_id, $group_id);
} }
##########################################################################
## Delete a planned downtime
##########################################################################
sub pandora_delete_planned_downtime ($$) {
my ($dbh, $id_downtime) = @_;
my $execute = get_db_single_row($dbh, 'SELECT executed FROM tplanned_downtime WHERE id = ? ', $id_downtime);
if ( !$execute->{'executed'} ) {
my $result = db_do ($dbh, 'DELETE FROM tplanned_downtime WHERE id = ? ', $id_downtime);
if ($result) {
return "This planned downtime is deleted";
}
else {
return "Problems with this planned downtime";
}
}
else {
return "The scheduled downtime is still being executed";
}
}
########################################################################## ##########################################################################
## Delete all the data of module, agent's modules or group's agent's modules ## Delete all the data of module, agent's modules or group's agent's modules
########################################################################## ##########################################################################
@ -645,6 +671,72 @@ sub pandora_get_planned_downtime_id ($$) {
return defined ($downtime_id) ? $downtime_id : -1; return defined ($downtime_id) ? $downtime_id : -1;
} }
##########################################################################
## SUB get_all_planned_downtime
## Return the planned downtime id, given "downtime_name"
##########################################################################
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 $text_sql = '';
if (defined($id_group) && $id_group != '') {
$text_sql .= " id_group = $id_group ";
}
if ( defined($type_downtime) && $type_downtime != '' ) {
$text_sql .= " type_downtime = $type_downtime ";
}
if (defined($type_execution) && $type_execution != '') {
$text_sql .= " type_execution = $type_execution ";
}
if (defined($type_periodicity) && $type_periodicity != '') {
$text_sql .= " type_periodicity = $type_periodicity ";
}
if ($text_sql eq '') {
$text_sql = '';
}
my @downtimes = get_db_rows ($dbh, $sql,
safe_input($downtime_name), $text_sql);
return @downtimes;
}
##########################################################################
## SUB get_planned_downtimes_items
## Return the planned downtime id, given "downtime_name"
##########################################################################
sub pandora_get_planned_downtimes_items ($$) {
my ($dbh, $downtime) = @_;
my $sql = "SELECT * FROM tplanned_downtime_agents WHERE id_downtime = ?";
my @agents_items = get_db_rows ($dbh, $sql, $downtime->{"id"});
my @modules_downtime;
my @return;
my $text_modules;
foreach my $agents_item (@agents_items) {
if ( $downtime->{"type_downtime"} eq 'quiet' ) {
if ( !$agents_item->{'all_modules'} ) {
$sql = "SELECT id_agent_module FROM tplanned_downtime_modules WHERE id_downtime = ? AND id_agent = ?";
my @modules_items = get_db_rows ($dbh, $sql, $downtime->{"id"}, $agents_item->{"id_agent"});
foreach my $modules_item (@modules_items) {
push(@modules_downtime,$modules_item->{"id_agent_module"});
}
}
}
if ( @modules_downtime != undef ) {
$text_modules = join(",", @modules_downtime);
$agents_item->{"modules"} = $text_modules;
@modules_downtime = undef;
}
push (@return,$agents_item);
}
return @return;
}
########################################################################## ##########################################################################
## Create a special day from hash ## Create a special day from hash
########################################################################## ##########################################################################
@ -3387,6 +3479,66 @@ sub cli_add_item_planned_downtime() {
print_log "$result \n\n"; print_log "$result \n\n";
} }
sub cli_set_delete_planned_downtime() {
my $name_downtime = @ARGV[2];
my $id_downtime = pandora_get_planned_downtime_id($dbh,$name_downtime);
my $result = pandora_delete_planned_downtime ($dbh,$id_downtime);
print_log "$result \n\n";
}
sub cli_get_all_planned_downtime() {
my $name_downtime = @ARGV[2];
my ($id_group, $type_downtime, $type_execution, $type_periodicity) = @ARGV[3..6];
my @results = pandora_get_all_planned_downtime($dbh, $name_downtime, $id_group, $type_downtime, $type_execution, $type_periodicity);
if (!defined($results[0])) {
print_log "[ERROR] No data found with this parameters. Please check and launch again\n\n";
}
else {
foreach my $result (@results) {
print("ID: " . $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'} .
", SATURDAY: " . $result->{'saturday'} .", SUNDAY: " . $result->{'sunday'} .", PEDIODICALLY TIME FROM: " . $result->{'periodically_time_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'} .
", TYPE OF EXECUTION: " . $result->{'type_execution'} . "\nTYPE OF PERIODICITY: " . $result->{'type_periodicity'} .
", USER: " . $result->{'id_user'} ."\n");
}
}
}
sub cli_get_planned_downtimes_items() {
my $name_downtime = @ARGV[2];
my ($id_group, $type_downtime, $type_execution, $type_periodicity) = @ARGV[3..6];
my $text;
my @results = pandora_get_all_planned_downtime($dbh, $name_downtime, $id_group, $type_downtime, $type_execution, $type_periodicity);
if (!defined($results[0])) {
print_log "[ERROR] No data found with this parameters. Please check and launch again\n\n";
}
else {
my @items;
foreach my $result (@results) {
print(" ITEMS OF $result->{'name'} \n ");
@items = pandora_get_planned_downtimes_items($dbh,$result);
foreach my $item (@items) {
if ( $item->{'modules'} != '' ){
$text = " This Agent have this MODULES ID: " . $item->{"modules"};
}else{
$text = " All modules quiet of this agent";
}
print("AGENT ID: " . $item->{"id_agent"} . $text ."\n ");
}
}
}
}
############################################################################## ##############################################################################
# Create group # Create group
# Related option: --create_group # Related option: --create_group
@ -4190,6 +4342,18 @@ sub pandora_manage_main ($$$) {
param_check($ltotal, 3); param_check($ltotal, 3);
cli_add_item_planned_downtime(); cli_add_item_planned_downtime();
} }
elsif ($param eq '--get_all_planned_downtimes') {
param_check($ltotal, 5, 4);
cli_get_all_planned_downtime();
}
elsif ($param eq '--get_planned_downtimes_items') {
param_check($ltotal, 5, 4);
cli_get_planned_downtimes_items();
}
elsif ($param eq '--set_planned_downtimes_deleted') {
param_check($ltotal, 1);
cli_set_delete_planned_downtime();
}
else { else {
print_log "[ERROR] Invalid option '$param'.\n\n"; print_log "[ERROR] Invalid option '$param'.\n\n";
$param = ''; $param = '';