1 /*****************************************************************************
2 *
3 * test_nagios_config.c - Test configuration loading
4 *
5 * Program: Nagios Core Testing
6 * License: GPL
7 *
8 * First Written: 10-08-2009, based on nagios.c
9 *
10 * Description:
11 *
12 * Tests Nagios configuration loading
13 *
14 * License:
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 *****************************************************************************/
30
31 #include "../include/config.h"
32 #include "../include/common.h"
33 #include "../include/objects.h"
34 #include "../include/comments.h"
35 #include "../include/downtime.h"
36 #include "../include/statusdata.h"
37 #include "../include/macros.h"
38 #include "../include/nagios.h"
39 #include "../include/sretention.h"
40 #include "../include/perfdata.h"
41 #include "../include/broker.h"
42 #include "../include/nebmods.h"
43 #include "../include/nebmodules.h"
44
45 #include "tap.h"
46 #include "stub_perfdata.c"
47 #include "stub_workers.c"
48 #include "stub_events.c"
49 #include "stub_logging.c"
50 #include "stub_commands.c"
51 #include "stub_checks.c"
52 #include "stub_nebmods.c"
53 #include "stub_netutils.c"
54 #include "stub_broker.c"
55 #include "stub_statusdata.c"
56 #include "stub_flapping.c"
57 #include "stub_notifications.c"
58
59 int xrddefault_read_state_information(void);
60
main(int argc,char ** argv)61 int main(int argc, char **argv) {
62 int result;
63 int error = FALSE;
64 char *buffer = NULL;
65 int display_license = FALSE;
66 int display_help = FALSE;
67 int c = 0;
68 struct tm *tm;
69 time_t now;
70 char datestring[256];
71 host *temp_host = NULL;
72 hostgroup *temp_hostgroup = NULL;
73 hostsmember *temp_member = NULL;
74
75 plan_tests(14);
76
77 /* reset program variables */
78 reset_variables();
79
80 printf("Reading configuration data...\n");
81
82 config_file = strdup("smallconfig/nagios.cfg");
83 /* read in the configuration files (main config file, resource and object config files) */
84 result = read_main_config_file(config_file);
85 ok(result == OK, "Read main configuration file okay - if fails, use nagios -v to check");
86
87 result = read_all_object_data(config_file);
88 ok(result == OK, "Read all object config files");
89
90 result = pre_flight_check();
91 ok(result == OK, "Preflight check okay");
92
93 initialize_downtime_data();
94
95 for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
96 c++;
97 //printf("Hostgroup=%s\n", temp_hostgroup->group_name);
98 }
99 ok(c == 2, "Found all hostgroups");
100
101 temp_hostgroup = find_hostgroup("hostgroup1");
102 for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
103 //printf("host pointer=%d\n", temp_member->host_ptr);
104 }
105
106 temp_hostgroup = find_hostgroup("hostgroup2");
107 for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
108 //printf("host pointer=%d\n", temp_member->host_ptr);
109 }
110
111 temp_host = find_host("host1");
112 ok(temp_host->current_state == 0, "State is assumed OK on initial load");
113
114 // xrddefault_retention_file = strdup("smallconfig/retention.dat");
115 ok(xrddefault_read_state_information() == OK, "Reading retention data");
116
117 ok(temp_host->current_state == 1, "State changed due to retention file settings");
118
119 ok(find_host_comment(418) != NULL, "Found host comment id 418");
120 ok(find_service_comment(419) != NULL, "Found service comment id 419");
121 ok(find_service_comment(420) == NULL, "Did not find service comment id 420 as not persistent");
122 ok(find_host_comment(1234567888) == NULL, "No such host comment");
123
124 ok(find_host_downtime(1102) != NULL, "Found host downtime id 1102");
125 ok(find_service_downtime(1110) != NULL, "Found service downtime 1110");
126 ok(find_host_downtime(1234567888) == NULL, "No such host downtime");
127
128 cleanup();
129
130 my_free(config_file);
131
132 return exit_status();
133 }
134
135
136