/* * Deletes all host and service downtimes on a host by hostname, * optionally filtered by service description, start time and comment. * All char* must be set or NULL - "" will silently fail to match * Returns number deleted */ int delete_downtime_by_hostname_service_description_start_time_comment(char *hostname, char *service_description, time_t start_time, char *cmnt) { scheduled_downtime *temp_downtime; scheduled_downtime *next_downtime; void *downtime_cpy; int deleted = 0; objectlist *matches = NULL, *tmp_match = NULL; /* Do not allow deletion of everything - must have at least 1 filter on */ if(hostname == NULL && service_description == NULL && start_time == 0 && cmnt == NULL) return deleted; for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) { next_downtime = temp_downtime->next; if(start_time != 0 && temp_downtime->start_time != start_time) { continue; } if(cmnt != NULL && strcmp(temp_downtime->comment, cmnt) != 0) continue; if(temp_downtime->type == HOST_DOWNTIME) { /* If service is specified, then do not delete the host downtime */ if(service_description != NULL) continue; if(hostname != NULL && strcmp(temp_downtime->host_name, hostname) != 0) continue; } else if(temp_downtime->type == SERVICE_DOWNTIME) { if(hostname != NULL && strcmp(temp_downtime->host_name, hostname) != 0) continue; if(service_description != NULL && strcmp(temp_downtime->service_description, service_description) != 0) continue; } downtime_cpy = malloc(sizeof(scheduled_downtime)); memcpy(downtime_cpy, temp_downtime, sizeof(scheduled_downtime)); prepend_object_to_objectlist(&matches, downtime_cpy); deleted++; } for(tmp_match = matches; tmp_match != NULL; tmp_match = tmp_match->next) { temp_downtime = (scheduled_downtime *)tmp_match->object_ptr; unschedule_downtime(temp_downtime->type, temp_downtime->downtime_id); my_free(temp_downtime); } free_objectlist(&matches); return deleted; }
void destroy_service(service *this_service) { struct contactgroupsmember *this_contactgroupsmember, *next_contactgroupsmember; struct contactsmember *this_contactsmember, *next_contactsmember; struct customvariablesmember *this_customvariablesmember, *next_customvariablesmember; struct objectlist *slavelist; if (!this_service) return; /* free memory for contact groups */ this_contactgroupsmember = this_service->contact_groups; while (this_contactgroupsmember != NULL) { next_contactgroupsmember = this_contactgroupsmember->next; nm_free(this_contactgroupsmember); this_contactgroupsmember = next_contactgroupsmember; } /* free memory for contacts */ this_contactsmember = this_service->contacts; while (this_contactsmember != NULL) { next_contactsmember = this_contactsmember->next; nm_free(this_contactsmember); this_contactsmember = next_contactsmember; } /* free memory for custom variables */ this_customvariablesmember = this_service->custom_variables; while (this_customvariablesmember != NULL) { next_customvariablesmember = this_customvariablesmember->next; nm_free(this_customvariablesmember->variable_name); nm_free(this_customvariablesmember->variable_value); nm_free(this_customvariablesmember); this_customvariablesmember = next_customvariablesmember; } while (this_service->servicegroups_ptr) remove_service_from_servicegroup(this_service->servicegroups_ptr->object_ptr, this_service); for (slavelist = this_service->notify_deps; slavelist; slavelist = slavelist->next) destroy_servicedependency(slavelist->object_ptr); for (slavelist = this_service->exec_deps; slavelist; slavelist = slavelist->next) destroy_servicedependency(slavelist->object_ptr); for (slavelist = this_service->escalation_list; slavelist; slavelist = slavelist->next) destroy_serviceescalation(slavelist->object_ptr); if (this_service->display_name != this_service->description) nm_free(this_service->display_name); nm_free(this_service->description); nm_free(this_service->check_command); nm_free(this_service->plugin_output); nm_free(this_service->long_plugin_output); nm_free(this_service->perf_data); nm_free(this_service->event_handler_args); free_objectlist(&this_service->servicegroups_ptr); free_objectlist(&this_service->notify_deps); free_objectlist(&this_service->exec_deps); free_objectlist(&this_service->escalation_list); nm_free(this_service->event_handler); nm_free(this_service->notes); nm_free(this_service->notes_url); nm_free(this_service->action_url); nm_free(this_service->icon_image); nm_free(this_service->icon_image_alt); nm_free(this_service); }
void destroy_host(host *this_host) { struct servicesmember *this_servicesmember, *next_servicesmember; struct contactgroupsmember *this_contactgroupsmember, *next_contactgroupsmember; struct contactsmember *this_contactsmember, *next_contactsmember; struct customvariablesmember *this_customvariablesmember, *next_customvariablesmember; struct objectlist *slavelist; if (!this_host) return; /* free memory for service links */ this_servicesmember = this_host->services; while (this_servicesmember != NULL) { next_servicesmember = this_servicesmember->next; nm_free(this_servicesmember); this_servicesmember = next_servicesmember; } /* free memory for contact groups */ this_contactgroupsmember = this_host->contact_groups; while (this_contactgroupsmember != NULL) { next_contactgroupsmember = this_contactgroupsmember->next; nm_free(this_contactgroupsmember); this_contactgroupsmember = next_contactgroupsmember; } /* free memory for contacts */ this_contactsmember = this_host->contacts; while (this_contactsmember != NULL) { next_contactsmember = this_contactsmember->next; nm_free(this_contactsmember); this_contactsmember = next_contactsmember; } /* free memory for custom variables */ this_customvariablesmember = this_host->custom_variables; while (this_customvariablesmember != NULL) { next_customvariablesmember = this_customvariablesmember->next; nm_free(this_customvariablesmember->variable_name); nm_free(this_customvariablesmember->variable_value); nm_free(this_customvariablesmember); this_customvariablesmember = next_customvariablesmember; } for (slavelist = this_host->notify_deps; slavelist; slavelist = slavelist->next) destroy_hostdependency(slavelist->object_ptr); for (slavelist = this_host->exec_deps; slavelist; slavelist = slavelist->next) destroy_hostdependency(slavelist->object_ptr); for (slavelist = this_host->escalation_list; slavelist; slavelist = slavelist->next) destroy_hostescalation(slavelist->object_ptr); while (this_host->hostgroups_ptr) remove_host_from_hostgroup(this_host->hostgroups_ptr->object_ptr, this_host); if (this_host->child_hosts) { struct host *curhost = NULL; do { curhost = NULL; g_tree_foreach(this_host->child_hosts, my_g_tree_visit_pick_one, &curhost); if(curhost) { remove_parent_from_host(curhost, this_host); } } while(curhost != NULL); g_tree_unref(this_host->child_hosts); this_host->child_hosts = NULL; } if (this_host->parent_hosts) { struct host *curhost = NULL; do { curhost = NULL; g_tree_foreach(this_host->parent_hosts, my_g_tree_visit_pick_one, &curhost); if(curhost) { remove_parent_from_host(this_host, curhost); } } while(curhost != NULL); g_tree_unref(this_host->parent_hosts); this_host->parent_hosts = NULL; } if (this_host->display_name != this_host->name) nm_free(this_host->display_name); if (this_host->alias != this_host->name) nm_free(this_host->alias); if (this_host->address != this_host->name) nm_free(this_host->address); nm_free(this_host->name); nm_free(this_host->plugin_output); nm_free(this_host->long_plugin_output); nm_free(this_host->perf_data); free_objectlist(&this_host->hostgroups_ptr); free_objectlist(&this_host->notify_deps); free_objectlist(&this_host->exec_deps); free_objectlist(&this_host->escalation_list); nm_free(this_host->check_command); nm_free(this_host->event_handler); nm_free(this_host->notes); nm_free(this_host->notes_url); nm_free(this_host->action_url); nm_free(this_host->icon_image); nm_free(this_host->icon_image_alt); nm_free(this_host->vrml_image); nm_free(this_host->statusmap_image); nm_free(this_host); }