forked from NagiosEnterprises/nagioscore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_downtime.c
199 lines (158 loc) · 10.1 KB
/
test_downtime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*****************************************************************************
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*****************************************************************************/
#define NSCORE 1
#include "config.h"
#include "common.h"
#include "nagios.h"
#include "downtime.h"
#include "perfdata.h"
#include "comments.h"
#include "statusdata.h"
#include "macros.h"
#include "broker.h"
#include "../lib/lnag-utils.h"
#include "stub_sehandlers.c"
#include "stub_comments.c"
#include "stub_perfdata.c"
#include "stub_notifications.c"
#include "stub_logging.c"
#include "stub_broker.c"
#include "stub_workers.c"
#include "stub_events.c"
#include "stub_statusdata.c"
#include "stub_flapping.c"
#include "stub_nebmods.c"
#include "stub_netutils.c"
#include "stub_commands.c"
#include "tap.h"
timed_event *event_list_high = NULL;
timed_event *event_list_high_tail = NULL;
extern scheduled_downtime *scheduled_downtime_list;
int main(int argc, char **argv)
{
time_t now = 0L;
time_t temp_start_time = 1234567890L;
time_t temp_end_time = 2134567890L;
unsigned long downtime_id = 0L;
scheduled_downtime *temp_downtime;
int i = 0;
char *main_config_file = "../t/etc/nagios-test-downtime.cfg";
/* Initialize configuration variables */
init_main_cfg_vars(1);
init_shared_cfg_vars(1);
/* Read the configuration */
read_main_config_file(main_config_file);
read_object_config_data(main_config_file, READ_ALL_OBJECT_DATA);
pre_flight_check();
initialize_downtime_data();
plan_tests(38);
time(&now);
next_downtime_id = 1L;
schedule_downtime(HOST_DOWNTIME, "host1", NULL, temp_start_time, "user", "test comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 1L, "Got host1 downtime: %lu", downtime_id);
schedule_downtime(HOST_DOWNTIME, "host2", NULL, temp_start_time, "user", "test comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 2L, "Got host2 downtime: %lu", downtime_id);
schedule_downtime(HOST_DOWNTIME, "host3", NULL, temp_start_time, "user", "diff comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 3L, "Got host3 downtime: %lu", downtime_id);
schedule_downtime(HOST_DOWNTIME, "host4", NULL, temp_start_time, "user", "test comment", temp_start_time + 1, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 4L, "Got host4 downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host1", "svc", temp_start_time, "user", "svc comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 5L, "Got host1::svc downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host2", "svc", temp_start_time, "user", "diff comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 6L, "Got host2::svc downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host3", "svc", temp_start_time, "user", "svc comment", temp_start_time + 1, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 7L, "Got host3::svc downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host4", "svc", temp_start_time, "user", "uniq comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 8L, "Got host4::svc downtime: %lu", downtime_id);
for(temp_downtime = scheduled_downtime_list, i = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next, i++) {}
ok(i == 8, "Got 8 downtimes: %d", i);
i = delete_downtime_by_hostname_service_description_start_time_comment(NULL, NULL, 0, NULL);
ok(i == 0, "No deletions") || diag("%d", i);
i = delete_downtime_by_hostname_service_description_start_time_comment(NULL, NULL, 0, NULL);
ok(i == 0, "No deletions");
i = delete_downtime_by_hostname_service_description_start_time_comment(NULL, NULL, temp_start_time, "test comment");
ok(i == 2, "Deleted 2 downtimes");
for(temp_downtime = scheduled_downtime_list, i = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next, i++) {}
ok(i == 6, "Got 6 downtimes left: %d", i);
i = delete_downtime_by_hostname_service_description_start_time_comment(NULL, NULL, temp_start_time + 200, "test comment");
ok(i == 0, "Nothing matched, so 0 downtimes deleted");
i = delete_downtime_by_hostname_service_description_start_time_comment(NULL, NULL, temp_start_time + 1, NULL);
ok(i == 2, "Deleted 2 by start_time only: %d", i);
i = delete_downtime_by_hostname_service_description_start_time_comment(NULL, NULL, 0, "uniq comment");
ok(i == 1, "Deleted 1 by unique comment: %d", i);
for(temp_downtime = scheduled_downtime_list, i = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next, i++) {
printf("# downtime id: %lu\n", temp_downtime->downtime_id);
}
ok(i == 3, "Got 3 downtimes left: %d", i);
unschedule_downtime(HOST_DOWNTIME, 3);
unschedule_downtime(SERVICE_DOWNTIME, 5);
unschedule_downtime(SERVICE_DOWNTIME, 6);
for(temp_downtime = scheduled_downtime_list, i = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next, i++) {}
ok(i == 0, "No downtimes left");
/* Set all downtimes up again */
schedule_downtime(HOST_DOWNTIME, "host1", NULL, temp_start_time, "user", "test comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 9L, "Got host1 downtime: %lu", downtime_id);
schedule_downtime(HOST_DOWNTIME, "host2", NULL, temp_start_time, "user", "test comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 10L, "Got host2 downtime: %lu", downtime_id);
schedule_downtime(HOST_DOWNTIME, "host3", NULL, temp_start_time, "user", "diff comment", temp_start_time + 1, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 11L, "Got host3 downtime: %lu", downtime_id);
schedule_downtime(HOST_DOWNTIME, "host4", NULL, temp_start_time, "user", "test comment", temp_start_time + 1, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 12L, "Got host4 downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host1", "svc", temp_start_time, "user", "svc comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 13L, "Got host1::svc downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host2", "svc", temp_start_time, "user", "diff comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 14L, "Got host2::svc downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host3", "svc", temp_start_time, "user", "svc comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 15L, "Got host3::svc downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host4", "svc", temp_start_time, "user", "uniq comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 16L, "Got host4::svc downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host1", "svc2", temp_start_time, "user", "svc2 comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 17L, "Got host1::svc2 downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host2", "svc2", temp_start_time, "user", "test comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 18L, "Got host2::svc2 downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host3", "svc2", temp_start_time, "user", "svc2 comment", temp_start_time + 1, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 19L, "Got host3::svc2 downtime: %lu", downtime_id);
schedule_downtime(SERVICE_DOWNTIME, "host4", "svc2", temp_start_time, "user", "test comment", temp_start_time, temp_end_time, 1, 0, 0, &downtime_id);
ok(downtime_id == 20L, "Got host4::svc2 downtime: %lu", downtime_id);
i = delete_downtime_by_hostname_service_description_start_time_comment("host2", NULL, 0, "test comment");
ok(i == 2, "Deleted 2");
i = delete_downtime_by_hostname_service_description_start_time_comment("host1", "svc", 0, NULL);
ok(i == 1, "Deleted 1") || diag("Actually deleted: %d", i);
i = delete_downtime_by_hostname_service_description_start_time_comment("host3", NULL, temp_start_time + 1, NULL);
ok(i == 2, "Deleted 2");
i = delete_downtime_by_hostname_service_description_start_time_comment(NULL, "svc2", 0, NULL);
ok(i == 2, "Deleted 2") || diag("Actually deleted: %d", i);
i = delete_downtime_by_hostname_service_description_start_time_comment("host4", NULL, 0, "test comment");
ok(i == 1, "Deleted 1") || diag("Actually deleted: %d", i);
i = delete_downtime_by_hostname_service_description_start_time_comment("host4", NULL, 0, "svc comment");
ok(i == 0, "Deleted 0") || diag("Actually deleted: %d", i);
for(temp_downtime = scheduled_downtime_list, i = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next, i++) {
printf("# downtime id: %lu\n", temp_downtime->downtime_id);
}
ok(i == 4, "Got 4 downtimes left: %d", i);
unschedule_downtime(HOST_DOWNTIME, 9);
unschedule_downtime(SERVICE_DOWNTIME, 14);
unschedule_downtime(SERVICE_DOWNTIME, 15);
unschedule_downtime(SERVICE_DOWNTIME, 16);
for(temp_downtime = scheduled_downtime_list, i = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next, i++) {}
ok(i == 0, "No downtimes left") || diag("Left: %d", i);
free_downtime_data();
cleanup();
cleanup_downtime_data();
return exit_status();
}