-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add a test the checks ack expiry - WIP
A new test file, intended to contain tests that process the event queue and check the results. The first test in it checks if the acknowledgement expiry event does its work.
- Loading branch information
1 parent
f37e375
commit 7dc5bbf
Showing
2 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/***************************************************************************** | ||
* | ||
* 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/>. | ||
* | ||
* | ||
*****************************************************************************/ | ||
#include <string.h> | ||
#include <assert.h> | ||
#include "tap.h" | ||
#include "naemon/objects.h" | ||
#include "naemon/commands.h" | ||
#include "naemon/downtime.h" | ||
#include "naemon/comments.h" | ||
#include "naemon/globals.h" | ||
#include "naemon/utils.h" | ||
#include "naemon/configuration.h" | ||
#include "naemon/defaults.h" | ||
#include "naemon/sretention.h" | ||
#include "naemon/events.h" | ||
|
||
static int *received_persistent; | ||
static char *received_host; | ||
static time_t received_entry_time; | ||
char *addresses[2]; | ||
timeperiod *registered_timeperiod = NULL; | ||
int b_val; | ||
int i_val; | ||
time_t t_val; | ||
GError *error = NULL; | ||
char *s_val; | ||
|
||
|
||
int test__add_host_comment_handler(const struct external_command *ext_command, time_t entry_time) | ||
{ | ||
command_argument_value_copy((void **) &received_host, command_argument_get_value(ext_command, "host"), STRING); | ||
command_argument_value_copy((void **) &received_persistent, command_argument_get_value(ext_command, "persistent"), BOOL); | ||
received_entry_time = entry_time; | ||
return 0; | ||
} | ||
int test__add_service_comment_handler(const struct external_command *ext_command, time_t entry_time) | ||
{ | ||
return 0; | ||
} | ||
|
||
int test__del_host_comment_handler(const struct external_command *ext_command, time_t entry_time) | ||
{ | ||
return 0; | ||
} | ||
|
||
int test__disable_notifications_handler(const struct external_command *ext_command, time_t entry_time) | ||
{ | ||
return 0; | ||
} | ||
|
||
int test__do_thing_with_timeperiod_handler(const struct external_command *ext_command, time_t entry_time) | ||
{ | ||
return 0; | ||
} | ||
|
||
|
||
int test__do_thing_with_contact_handler(const struct external_command *ext_command, time_t entry_time) | ||
{ | ||
return 0; | ||
} | ||
int custom_service_validator(void *value) | ||
{ | ||
return 1; | ||
} | ||
|
||
void test_host_commands(void) | ||
{ | ||
char *host_name = "host1"; | ||
host *target_host = NULL; | ||
time_t current_time = 0; | ||
char *cmdstr = NULL; | ||
target_host = find_host(host_name); | ||
target_host->obsess = FALSE; | ||
|
||
target_host->current_state = STATE_DOWN; | ||
time(¤t_time); | ||
nm_asprintf(&cmdstr, "[1234567890] ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;host1;2;0;0;%llu;myself;expire in two seconds", (unsigned long long int)current_time+2); | ||
ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: ACKNOWLEDGE_HOST_PROBLEM_EXPIRE"); | ||
ok(target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE acknowledgement present before event"); | ||
sleep(3); | ||
/* This should be done better. How do we know how many | ||
events we have to process? */ | ||
event_poll(); | ||
event_poll(); | ||
ok(!target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE acknowledgement gone after event"); | ||
free(cmdstr); | ||
} | ||
|
||
void test_core_commands(void) | ||
{ | ||
/*setup configuration*/ | ||
pre_flight_check(); /*without this, child_host links are not created and *_BEYOND_HOST test cases fail...*/ | ||
registered_commands_init(200); | ||
register_core_commands(); | ||
test_host_commands(); | ||
registered_commands_deinit(); | ||
free(config_file); | ||
} | ||
|
||
int main(int /*@unused@*/ argc, char /*@unused@*/ **arv) | ||
{ | ||
const char *test_config_file = TESTDIR "naemon.cfg"; | ||
plan_tests(3); | ||
init_event_queue(); | ||
|
||
config_file_dir = nspath_absolute_dirname(test_config_file, NULL); | ||
assert(OK == read_main_config_file(test_config_file)); | ||
assert(OK == read_all_object_data(test_config_file)); | ||
assert(OK == initialize_downtime_data()); | ||
assert(OK == initialize_retention_data()); | ||
nagios_iobs = iobroker_create(); | ||
test_core_commands(); | ||
return exit_status(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters