/* adds a new host comment */ int xcddefault_add_new_host_comment(int entry_type, char *host_name, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) { /* find the next valid comment id */ while(find_host_comment(next_comment_id) != NULL) next_comment_id++; /* add comment to list in memory */ add_host_comment(entry_type, host_name, entry_time, author_name, comment_data, next_comment_id, persistent, expires, expire_time, source); /* return the id for the comment we are about to add (this happens in the main code) */ if(comment_id != NULL) *comment_id = next_comment_id; /* increment the comment id */ next_comment_id++; return OK; }
int main(int argc, char **argv) { int result; int error = FALSE; char *buffer = NULL; int display_license = FALSE; int display_help = FALSE; int c = 0; struct tm *tm; time_t now; char datestring[256]; host *temp_host = NULL; hostgroup *temp_hostgroup = NULL; hostsmember *temp_member = NULL; plan_tests(14); /* reset program variables */ reset_variables(); printf("Reading configuration data...\n"); config_file = strdup("smallconfig/nagios.cfg"); /* read in the configuration files (main config file, resource and object config files) */ result = read_main_config_file(config_file); ok(result == OK, "Read main configuration file okay - if fails, use nagios -v to check"); result = read_all_object_data(config_file); ok(result == OK, "Read all object config files"); result = pre_flight_check(); ok(result == OK, "Preflight check okay"); for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) { c++; //printf("Hostgroup=%s\n", temp_hostgroup->group_name); } ok(c == 2, "Found all hostgroups"); temp_hostgroup = find_hostgroup("hostgroup1"); for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) { //printf("host pointer=%d\n", temp_member->host_ptr); } temp_hostgroup = find_hostgroup("hostgroup2"); for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) { //printf("host pointer=%d\n", temp_member->host_ptr); } temp_host = find_host("host1"); ok(temp_host->current_state == 0, "State is assumed OK on initial load"); xrddefault_retention_file = strdup("smallconfig/retention.dat"); ok(xrddefault_read_state_information() == OK, "Reading retention data"); ok(temp_host->current_state == 1, "State changed due to retention file settings"); ok(find_host_comment(418) != NULL, "Found host comment id 418"); ok(find_service_comment(419) != NULL, "Found service comment id 419"); ok(find_service_comment(420) == NULL, "Did not find service comment id 420 as not persistent"); ok(find_host_comment(1234567888) == NULL, "No such host comment"); ok(find_host_downtime(1102) != NULL, "Found host downtime id 1102"); ok(find_service_downtime(1110) != NULL, "Found service downtime 1110"); ok(find_host_downtime(1234567888) == NULL, "No such host downtime"); cleanup(); my_free(config_file); return exit_status(); }
int main(int argc, char **argv) { int result; int c = 0; struct host *host1, *host2; hostgroup *temp_hostgroup = NULL; hostsmember *temp_member = NULL; plan_tests(19); /* reset program variables */ reset_variables(); /* * avoid updating the checked-in retention data * file when testing */ retain_state_information = FALSE; printf("Reading configuration data...\n"); config_file = strdup(get_default_config_file()); config_file_dir = nspath_absolute_dirname(config_file, NULL); /* read in the configuration files (main config file, resource and object config files) */ result = read_main_config_file(config_file); ok(result == OK, "Read main configuration file okay - if fails, use nagios -v to check"); result = read_all_object_data(config_file); ok(result == OK, "Read all object config files"); result = pre_flight_check(); ok(result == OK, "Preflight check okay"); for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) { c++; //printf("Hostgroup=%s\n", temp_hostgroup->group_name); } ok(c == 2, "Found all hostgroups"); temp_hostgroup = find_hostgroup("hostgroup1"); for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) { //printf("host pointer=%d\n", temp_member->host_ptr); } temp_hostgroup = find_hostgroup("hostgroup2"); for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) { //printf("host pointer=%d\n", temp_member->host_ptr); } host1 = find_host("host1"); host2 = find_host("host2"); ok(host1 != NULL && host2 != NULL, "find_host() should work"); ok(host1->current_state == 0, "State is assumed OK on initial load"); ok(host1->notifications_enabled == 1, "host1 notifications_enabled set from config"); ok(host2->notifications_enabled == 1, "host2 notifications_enabled set from config"); initialize_retention_data(NULL); initialize_downtime_data(); init_event_queue(); ok(xrddefault_read_state_information() == OK, "Reading retention data"); ok(host1->current_state == 1, "State changed due to retention file settings"); ok(host1->notifications_enabled == 1, "Config change should override notifications_enabled for host1"); ok(host2->notifications_enabled == 0, "Retention data should win on no config change"); ok(find_host_comment(418) != NULL, "Found host comment id 418"); ok(find_service_comment(419) != NULL, "Found service comment id 419"); ok(find_service_comment(420) == NULL, "Did not find service comment id 420 as not persistent"); ok(find_host_comment(1234567888) == NULL, "No such host comment"); ok(find_host_downtime(1102) != NULL, "Found host downtime id 1102"); ok(find_service_downtime(1110) != NULL, "Found service downtime 1110"); ok(find_host_downtime(1234567888) == NULL, "No such host downtime"); cleanup(); my_free(config_file); return exit_status(); }