You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(4) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(9) |
Feb
(11) |
Mar
(37) |
Apr
(50) |
May
(51) |
Jun
(31) |
Jul
(35) |
Aug
(30) |
Sep
(39) |
Oct
(85) |
Nov
(91) |
Dec
(30) |
2003 |
Jan
(65) |
Feb
(56) |
Mar
(80) |
Apr
(73) |
May
(84) |
Jun
(108) |
Jul
(62) |
Aug
(53) |
Sep
(46) |
Oct
(44) |
Nov
(59) |
Dec
(91) |
2004 |
Jan
(71) |
Feb
(25) |
Mar
(87) |
Apr
(67) |
May
(65) |
Jun
(60) |
Jul
(31) |
Aug
(100) |
Sep
(97) |
Oct
(133) |
Nov
(87) |
Dec
(65) |
2005 |
Jan
(84) |
Feb
(133) |
Mar
(67) |
Apr
(74) |
May
(108) |
Jun
(92) |
Jul
(54) |
Aug
(82) |
Sep
(22) |
Oct
(10) |
Nov
(69) |
Dec
(65) |
2006 |
Jan
(89) |
Feb
(133) |
Mar
(100) |
Apr
(69) |
May
(138) |
Jun
(85) |
Jul
(45) |
Aug
(56) |
Sep
(33) |
Oct
(69) |
Nov
(33) |
Dec
(78) |
2007 |
Jan
(120) |
Feb
(120) |
Mar
(136) |
Apr
(153) |
May
(75) |
Jun
(65) |
Jul
(64) |
Aug
(129) |
Sep
(122) |
Oct
(231) |
Nov
(145) |
Dec
(93) |
2008 |
Jan
(163) |
Feb
(157) |
Mar
(60) |
Apr
(96) |
May
(92) |
Jun
(67) |
Jul
(90) |
Aug
(75) |
Sep
(87) |
Oct
(81) |
Nov
(158) |
Dec
(71) |
2009 |
Jan
(83) |
Feb
(77) |
Mar
(94) |
Apr
(78) |
May
(210) |
Jun
(146) |
Jul
(104) |
Aug
(208) |
Sep
(80) |
Oct
(54) |
Nov
(55) |
Dec
(84) |
2010 |
Jan
(21) |
Feb
(67) |
Mar
(85) |
Apr
(20) |
May
(29) |
Jun
(11) |
Jul
(13) |
Aug
(48) |
Sep
(56) |
Oct
(70) |
Nov
(100) |
Dec
(83) |
2011 |
Jan
(59) |
Feb
(36) |
Mar
(59) |
Apr
(21) |
May
(96) |
Jun
(27) |
Jul
(17) |
Aug
(58) |
Sep
(12) |
Oct
(15) |
Nov
(27) |
Dec
(20) |
2012 |
Jan
(36) |
Feb
(3) |
Mar
(19) |
Apr
(9) |
May
(22) |
Jun
(34) |
Jul
(7) |
Aug
(31) |
Sep
(65) |
Oct
(18) |
Nov
(78) |
Dec
(24) |
2013 |
Jan
(46) |
Feb
(73) |
Mar
(50) |
Apr
(11) |
May
(32) |
Jun
(10) |
Jul
(6) |
Aug
(18) |
Sep
(36) |
Oct
|
Nov
|
Dec
|
From: Andreas E. <ae...@op...> - 2013-05-24 07:43:29
|
On 2013-05-22 21:43, Deepak Kosaraju wrote: > Hi Whether "Service Check Scheduling" concepts explained in following > Nagios2 documentation still applies to Nagios 3 and Nagios 4, if not > where can I find details documentation for Nagios3 and Nagios4 > "Service Check Scheduling". > > http://nagios.manubulon.com/traduction/docs14en/checkscheduling.html > It's mostly correct, except that Nagios 4 reaps service checks as fast as they come in. We get that for free due to the event-driven design implemented in Nagios 4. That also means zombie processes should be very, very rare on a Nagios 4 system. The scheduling parts are still valid though. Only the backend for the scheduling queue has changed. The logic using the backend is still identical. -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. |
From: Cyril F. <na...@fe...> - 2013-05-24 06:37:33
|
From 530f99c0d840ddb52257175e61b963ae7ffb3212 Mon Sep 17 00:00:00 2001 From: Feraudet Cyril <cy...@fe...> Date: Mon, 20 May 2013 11:10:41 +0200 Subject: [PATCH] Prefix error with "CHECK_NRPE: " as in check_nrpe.c --- src/utils.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils.c b/src/utils.c index 48d7e58..8791bae 100644 --- a/src/utils.c +++ b/src/utils.c @@ -136,7 +136,7 @@ int my_connect(char *host_name,int port,int *sd,char *proto){ /* else do a DNS lookup */ hp=gethostbyname((const char *)host_name); if(hp==NULL){ - printf("Invalid host name '%s'\n",host_name); + printf("CHECK_NRPE: Invalid host name '%s'\n",host_name); return STATE_UNKNOWN; } @@ -145,14 +145,14 @@ int my_connect(char *host_name,int port,int *sd,char *proto){ /* map transport protocol name to protocol number */ if(((ptrp=getprotobyname(proto)))==NULL){ - printf("Cannot map \"%s\" to protocol number\n",proto); + printf("CHECK_NRPE: Cannot map \"%s\" to protocol number\n",proto); return STATE_UNKNOWN; } /* create a socket */ *sd=socket(PF_INET,(!strcmp(proto,"udp"))?SOCK_DGRAM:SOCK_STREAM,ptrp->p_proto); if(*sd<0){ - printf("Socket creation failed\n"); + printf("CHECK_NRPE: Socket creation failed\n"); return STATE_UNKNOWN; } @@ -161,16 +161,16 @@ int my_connect(char *host_name,int port,int *sd,char *proto){ if(result<0){ switch(errno){ case ECONNREFUSED: - printf("Connection refused by host\n"); + printf("CHECK_NRPE: Connection refused by host\n"); break; case ETIMEDOUT: - printf("Timeout while attempting connection\n"); + printf("CHECK_NRPE: Timeout while attempting connection\n"); break; case ENETUNREACH: - printf("Network is unreachable\n"); + printf("CHECK_NRPE: Network is unreachable\n"); break; default: - printf("Connection refused or timed out\n"); + printf("CHECK_NRPE: Connection refused or timed out\n"); } return STATE_CRITICAL; -- 1.8.1.2 |
From: Deepak K. <dee...@gm...> - 2013-05-22 19:43:37
|
Hi Whether "Service Check Scheduling" concepts explained in following Nagios2 documentation still applies to Nagios 3 and Nagios 4, if not where can I find details documentation for Nagios3 and Nagios4 "Service Check Scheduling". http://nagios.manubulon.com/traduction/docs14en/checkscheduling.html With Regards Deepak Kosaraju |
From: Max S. <max...@op...> - 2013-05-22 09:51:35
|
From: Max Sikström <msi...@op...> This tests escaping and url-encoding of some macros This doesn't test all macros, but the functionality of escaping. Signed-off-by: Max Sikström <msi...@op...> --- t-tap/Makefile.in | 4 + t-tap/test_macros.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+), 0 deletions(-) create mode 100644 t-tap/test_macros.c diff --git a/t-tap/Makefile.in b/t-tap/Makefile.in index 3079ee0..324cb8b 100644 --- a/t-tap/Makefile.in +++ b/t-tap/Makefile.in @@ -18,6 +18,7 @@ TESTS += test_checks TESTS += test_strtoul TESTS += test_commands TESTS += test_downtime +TESTS += test_macros XSD_OBJS = $(SRC_CGI)/statusdata-cgi.o $(SRC_CGI)/xstatusdata-cgi.o XSD_OBJS += $(SRC_CGI)/objects-cgi.o $(SRC_CGI)/xobjects-cgi.o @@ -114,6 +115,9 @@ test_nagios_config: test_nagios_config.o $(CFG_OBJS) $(TAPOBJ) test_timeperiods: test_timeperiods.o $(TP_OBJS) $(TAPOBJ) $(CC) $(CFLAGS) -o $@ $^ $(BROKER_LDFLAGS) $(LDFLAGS) $(MATHLIBS) $(SOCKETLIBS) $(BROKERLIBS) $(LIBS) +test_macros: test_macros.o $(TP_OBJS) $(TAPOBJ) + $(CC) $(CFLAGS) -o $@ $^ $(BROKER_LDFLAGS) $(LDFLAGS) $(MATHLIBS) $(SOCKETLIBS) $(LIBS) + test_xsddefault: test_xsddefault.o $(XSD_OBJS) $(TAPOBJ) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) diff --git a/t-tap/test_macros.c b/t-tap/test_macros.c new file mode 100644 index 0000000..ebc6a03 --- /dev/null +++ b/t-tap/test_macros.c @@ -0,0 +1,211 @@ +/***************************************************************************** + * + * test_macros.c - Test macro expansion and escaping + * + * Program: Nagios Core Testing + * License: GPL + * + * First Written: 2013-05-21 + * + * Description: + * + * Tests expansion of macros and escaping. + * + * License: + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + *****************************************************************************/ + +#include <string.h> +#include "../include/objects.h" +#include "../include/nagios.h" +#include "tap.h" + +/*****************************************************************************/ +/* Dummy functions */ +/*****************************************************************************/ +void logit(int data_type, int display, const char *fmt, ...) { +} +int my_sendall(int s, char *buf, int *len, int timeout) { + return 0; +} +void free_comment_data(void) { +} + +int log_debug_info(int level, int verbosity, const char *fmt, ...) { + return 0; +} + +int neb_free_callback_list(void) { + return 0; +} + +int neb_deinit_modules(void) { + return 0; +} +void broker_program_state(int type, int flags, int attr, + struct timeval *timestamp) { +} +int neb_unload_all_modules(int flags, int reason) { + return 0; +} +int neb_add_module(char *filename, char *args, int should_be_loaded) { + return 0; +} +void broker_system_command(int type, int flags, int attr, + struct timeval start_time, struct timeval end_time, double exectime, + int timeout, int early_timeout, int retcode, char *cmd, char *output, + struct timeval *timestamp) { +} + +timed_event *schedule_new_event(int event_type, int high_priority, + time_t run_time, int recurring, unsigned long event_interval, + void *timing_func, int compensate_for_time_change, void *event_data, + void *event_args, int event_options) { + return NULL ; +} +int my_tcp_connect(char *host_name, int port, int *sd, int timeout) { + return 0; +} +int my_recvall(int s, char *buf, int *len, int timeout) { + return 0; +} +int neb_free_module_list(void) { + return 0; +} +int close_command_file(void) { + return 0; +} +int close_log_file(void) { + return 0; +} +int fix_log_file_owner(uid_t uid, gid_t gid) { + return 0; +} +int handle_async_service_check_result(service *temp_service, + check_result *queued_check_result) { + return 0; +} +int handle_async_host_check_result(host *temp_host, + check_result *queued_check_result) { + return 0; +} + +/*****************************************************************************/ +/* Local test environment */ +/*****************************************************************************/ + +host test_host = { .name = "name'&%", .address = "address'&%", .notes_url = + "notes_url'&%($HOSTNOTES$)", .notes = "notes'&%($HOSTACTIONURL$)", + .action_url = "action_url'&%" }; + +/*****************************************************************************/ +/* Helper functions */ +/*****************************************************************************/ + +void init_environment() { + char *p; + + my_free(illegal_output_chars); + illegal_output_chars = strdup("'&"); /* For this tests, remove ' and & */ + + /* This is a part of preflight check, which we can't run */ + for (p = illegal_output_chars; *p; p++) { + illegal_output_char_map[(int) *p] = 1; + } +} + +nagios_macros *setup_macro_object(void) { + nagios_macros *mac = (nagios_macros *) calloc(1, sizeof(nagios_macros)); + grab_host_macros_r(mac, &test_host); + return mac; +} + +#define RUN_MACRO_TEST(_STR, _EXPECT, _OPTS) \ + do { \ + if( OK == process_macros_r(mac, (_STR), &output, _OPTS ) ) {\ + ok( 0 == strcmp( output, _EXPECT ), "'%s': '%s' == '%s'", (_STR), output, (_EXPECT) ); \ + } else { \ + fail( "process_macros_r returns ERROR for " _STR ); \ + } \ + } while(0) + +/*****************************************************************************/ +/* Tests */ +/*****************************************************************************/ + +void test_escaping(nagios_macros *mac) { + char *output; + + /* Nothing should be changed... options == 0 */ + RUN_MACRO_TEST( "$HOSTNAME$ '&%", "name'&% '&%", 0); + + /* ' and & should be stripped from the macro, according to + * init_environment(), but not from the initial string + */ + RUN_MACRO_TEST( "$HOSTNAME$ '&%", "name% '&%", STRIP_ILLEGAL_MACRO_CHARS); + + /* ESCAPE_MACRO_CHARS doesn't seem to do anything... exist always in pair + * with STRIP_ILLEGAL_MACRO_CHARS + */ + RUN_MACRO_TEST( "$HOSTNAME$ '&%", "name'&% '&%", ESCAPE_MACRO_CHARS); + RUN_MACRO_TEST( "$HOSTNAME$ '&%", "name% '&%", + STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS); + + /* $HOSTNAME$ should be url-encoded, but not the tailing chars */ + RUN_MACRO_TEST( "$HOSTNAME$ '&%", "name%27%26%25 '&%", + URL_ENCODE_MACRO_CHARS); + + /* The notes in the notesurl should be url-encoded, no more encoding should + * exist + */ + RUN_MACRO_TEST( "$HOSTNOTESURL$ '&%", + "notes_url'&%(notes%27%26%25%28action_url%27%26%25%29) '&%", 0); + + /* '& in the source string should be removed, as in the url. the macros + * included in the string should be url-encoded, and therefore not contain & + * and ' + */ + RUN_MACRO_TEST( "$HOSTNOTESURL$ '&%", + "notes_url%(notes%27%26%25%28action_url%27%26%25%29) '&%", + STRIP_ILLEGAL_MACRO_CHARS); + + /* This should double-encode some chars ($HOSTNOTESURL$ should contain + * url-encoded chars, and should itself be url-encoded + */ + RUN_MACRO_TEST( "$HOSTNOTESURL$ '&%", + "notes_url%27%26%25%28notes%2527%2526%2525%2528action_url%2527%2526%2525%2529%29 '&%", + URL_ENCODE_MACRO_CHARS); +} + +/*****************************************************************************/ +/* Main function */ +/*****************************************************************************/ + +int main(void) { + nagios_macros *mac; + + reset_variables(); + init_environment(); + init_macros(); + + mac = setup_macro_object(); + + test_escaping(mac); + + cleanup(); + free(mac); + return exit_status(); +} -- 1.7.1 |
From: Max S. <max...@op...> - 2013-05-22 09:51:31
|
From: Max Sikström <msi...@op...> Command line arguments should be stripped of a couple characters, so it isn't possible to break out of for example strings, and start redirecting output and write to files, given values of macros. And extra important is for macros that can be updated from a user. Previously, this wasn't that big issue, when macros itself could say that they should be escaped. But the concept of escaping also depending which macro it entered gives lot of other problems (notable for url:s at least, see previous commit). Only the requestor of the macro expansion knows where it's going to be used, so only the requestor has the information to tell what to escape, and therefore, this patch tells the macro expansion to escape the macros to be used as a command line for check commands... Signed-off-by: Max Sikström <msi...@op...> --- base/checks.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/base/checks.c b/base/checks.c index 0f99f82..c9c4851 100644 --- a/base/checks.c +++ b/base/checks.c @@ -155,6 +155,7 @@ int run_async_service_check(service *svc, int check_options, double latency, int double old_latency = 0.0; check_result *cr; int runchk_result = OK; + int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; #ifdef USE_EVENT_BROKER int neb_result = OK; #endif @@ -222,7 +223,7 @@ int run_async_service_check(service *svc, int check_options, double latency, int grab_service_macros_r(&mac, svc); /* get the raw command line */ - get_raw_command_line_r(&mac, svc->check_command_ptr, svc->check_command, &raw_command, 0); + get_raw_command_line_r(&mac, svc->check_command_ptr, svc->check_command, &raw_command, macro_options); if(raw_command == NULL) { clear_volatile_macros_r(&mac); log_debug_info(DEBUGL_CHECKS, 0, "Raw check command for service '%s' on host '%s' was NULL - aborting.\n", svc->description, svc->host_name); @@ -233,7 +234,7 @@ int run_async_service_check(service *svc, int check_options, double latency, int } /* process any macros contained in the argument */ - process_macros_r(&mac, raw_command, &processed_command, 0); + process_macros_r(&mac, raw_command, &processed_command, macro_options); my_free(raw_command); if(processed_command == NULL) { clear_volatile_macros_r(&mac); @@ -2060,6 +2061,7 @@ int execute_sync_host_check(host *hst) { int early_timeout = FALSE; double exectime; char *temp_plugin_output = NULL; + int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; #ifdef USE_EVENT_BROKER int neb_result = OK; #endif @@ -2109,14 +2111,14 @@ int execute_sync_host_check(host *hst) { time(&hst->last_check); /* get the raw command line */ - get_raw_command_line_r(&mac, hst->check_command_ptr, hst->check_command, &raw_command, 0); + get_raw_command_line_r(&mac, hst->check_command_ptr, hst->check_command, &raw_command, macro_options); if(raw_command == NULL) { clear_volatile_macros_r(&mac); return ERROR; } /* process any macros contained in the argument */ - process_macros_r(&mac, raw_command, &processed_command, 0); + process_macros_r(&mac, raw_command, &processed_command, macro_options); if(processed_command == NULL) { my_free(raw_command); clear_volatile_macros_r(&mac); @@ -2302,6 +2304,7 @@ int run_async_host_check(host *hst, int check_options, double latency, int sched double old_latency = 0.0; check_result *cr; int runchk_result = OK; + int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; #ifdef USE_EVENT_BROKER int neb_result = OK; #endif @@ -2365,7 +2368,7 @@ int run_async_host_check(host *hst, int check_options, double latency, int sched grab_host_macros_r(&mac, hst); /* get the raw command line */ - get_raw_command_line_r(&mac, hst->check_command_ptr, hst->check_command, &raw_command, 0); + get_raw_command_line_r(&mac, hst->check_command_ptr, hst->check_command, &raw_command, macro_options); if(raw_command == NULL) { clear_volatile_macros_r(&mac); log_debug_info(DEBUGL_CHECKS, 0, "Raw check command for host '%s' was NULL - aborting.\n", hst->name); @@ -2373,7 +2376,7 @@ int run_async_host_check(host *hst, int check_options, double latency, int sched } /* process any macros contained in the argument */ - process_macros_r(&mac, raw_command, &processed_command, 0); + process_macros_r(&mac, raw_command, &processed_command, macro_options); my_free(raw_command); if(processed_command == NULL) { clear_volatile_macros_r(&mac); -- 1.7.1 |
From: Max S. <max...@op...> - 2013-05-22 09:51:26
|
From: Max Sikström <msi...@op...> No macros should be escaped because of which macros is resolved, but for where the macros is put. URL-encoding macros should be done when building an URL, not if the URL is included in the macro. Therefore, encoding options should only be brought downwards, and only one level in the encoding. An example: notes: this is a string escaped with & and other chars for $HOSTADDRESS$ notes_url: http://wiki.example.org/?notes=$HOSTNOTES$&address=$HOSTADDRESS$ action_url: http://example.org/?notes_url=$HOSTNOTESURL$¬es=$HOSTNOTES$ The result should be something like: notes: address should be included, but not escaped. It should be readable by a person notes_url: both notes and address should be url-encoded, because they are a part of the url, but shouldn't change the structure of the url (like including new variables) action_url: should urlencode notes_url, which means parts is double-encoded, because the notes_url-attribute should, when unpacked by the web server, contain the notes_url, and the notes should be encoded, so the same applies to notes Signed-off-by: Max Sikström <msi...@op...> --- common/macros.c | 101 ++++++++++++++++++++++-------------------------------- 1 files changed, 41 insertions(+), 60 deletions(-) diff --git a/common/macros.c b/common/macros.c index e76acef..b544dbb 100644 --- a/common/macros.c +++ b/common/macros.c @@ -38,7 +38,6 @@ char *macro_user[MAX_USER_MACROS]; /* $USERx$ macros */ struct macro_key_code { char *name; /* macro key name */ int code; /* numeric macro code, usable in case statements */ - int clean_options; char *value; }; @@ -110,9 +109,7 @@ int process_macros_r(nagios_macros *mac, char *input_buffer, char **output_buffe char *selected_macro = NULL; char *original_macro = NULL; int result = OK; - int clean_options = 0; int free_macro = FALSE; - int macro_options = 0; log_debug_info(DEBUGL_FUNCTIONS, 0, "process_macros_r()\n"); @@ -164,13 +161,10 @@ int process_macros_r(nagios_macros *mac, char *input_buffer, char **output_buffe /* looks like we're in a macro, so process it... */ else { - /* reset clean options */ - clean_options = 0; - /* grab the macro value */ free_macro = FALSE; - result = grab_macro_value_r(mac, temp_buffer, &selected_macro, &clean_options, &free_macro); - log_debug_info(DEBUGL_MACROS, 2, " Processed '%s', Clean Options: %d, Free: %d\n", temp_buffer, clean_options, free_macro); + result = grab_macro_value_r(mac, temp_buffer, &selected_macro, NULL, &free_macro); + log_debug_info(DEBUGL_MACROS, 2, " Processed '%s', Free: %d\n", temp_buffer, free_macro); /* an error occurred - we couldn't parse the macro, so continue on */ if(result == ERROR) { @@ -201,15 +195,10 @@ int process_macros_r(nagios_macros *mac, char *input_buffer, char **output_buffe /* insert macro */ if(selected_macro != NULL) { - log_debug_info(DEBUGL_MACROS, 2, " Processed '%s', Clean Options: %d, Free: %d\n", temp_buffer, clean_options, free_macro); - - /* include any cleaning options passed back to us */ - macro_options = (options | clean_options); - - log_debug_info(DEBUGL_MACROS, 2, " Cleaning options: global=%d, local=%d, effective=%d\n", options, clean_options, macro_options); + log_debug_info(DEBUGL_MACROS, 2, " Processed '%s', Free: %d, Cleaning options: %d\n", temp_buffer, free_macro, options); /* URL encode the macro if requested - this allocates new memory */ - if(macro_options & URL_ENCODE_MACRO_CHARS) { + if(options & URL_ENCODE_MACRO_CHARS) { original_macro = selected_macro; selected_macro = get_url_encoded_string(selected_macro); if(free_macro == TRUE) { @@ -219,11 +208,11 @@ int process_macros_r(nagios_macros *mac, char *input_buffer, char **output_buffe } /* some macros are cleaned... */ - if(macro_options & STRIP_ILLEGAL_MACRO_CHARS || macro_options & ESCAPE_MACRO_CHARS) { + if((options & STRIP_ILLEGAL_MACRO_CHARS) || (options & ESCAPE_MACRO_CHARS)) { char *cleaned_macro = NULL; /* add the (cleaned) processed macro to the end of the already processed buffer */ - if(selected_macro != NULL && (cleaned_macro = clean_macro_chars(selected_macro, macro_options)) != NULL) { + if(selected_macro != NULL && (cleaned_macro = clean_macro_chars(selected_macro, options)) != NULL) { *output_buffer = (char *)realloc(*output_buffer, strlen(*output_buffer) + strlen(cleaned_macro) + 1); strcat(*output_buffer, cleaned_macro); if(*cleaned_macro) @@ -413,7 +402,7 @@ int grab_macro_value_r(nagios_macros *mac, char *macro_buffer, char **output, in /* clear the old macro value */ my_free(*output); - if(macro_buffer == NULL || clean_options == NULL || free_macro == NULL) + if(macro_buffer == NULL || free_macro == NULL) return ERROR; @@ -488,10 +477,6 @@ int grab_macro_value_r(nagios_macros *mac, char *macro_buffer, char **output, in if ((mkey = find_macro_key(macro_name))) { log_debug_info(DEBUGL_MACROS, 2, " macros[%d] (%s) match.\n", mkey->code, macro_x_names[mkey->code]); - if (mkey->clean_options) { - *clean_options |= mkey->clean_options; - log_debug_info(DEBUGL_MACROS, 2, " New clean options: %d\n", *clean_options); - } /* get the macro value */ result = grab_macrox_value_r(mac, mkey->code, arg[0], arg[1], output, free_macro); @@ -2389,12 +2374,6 @@ char *clean_macro_chars(char *macro, int options) { ret[y++] = '\x0'; } -#ifdef ON_HOLD_FOR_NOW - /* escape nasty character in macro */ - if(options & ESCAPE_MACRO_CHARS) { - } -#endif - return ret; } @@ -2402,6 +2381,32 @@ char *clean_macro_chars(char *macro, int options) { /* encodes a string in proper URL format */ char *get_url_encoded_string(char *input) { + /* From RFC 3986: + segment = *pchar + + [...] + + pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + + query = *( pchar / "/" / "?" ) + + fragment = *( pchar / "/" / "?" ) + + pct-encoded = "%" HEXDIG HEXDIG + + unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + reserved = gen-delims / sub-delims + gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" + sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + / "*" / "+" / "," / ";" / "=" + + Encode everything but "unreserved", to be on safe side. + + Another note: + nowhere in the RFC states that + is interpreted as space. Therefore, encode + space as %20 (as all other characters that should be escaped) + */ + register int x = 0; register int y = 0; char *encoded_url_string = NULL; @@ -2420,17 +2425,17 @@ char *get_url_encoded_string(char *input) { for(x = 0, y = 0; input[x] != (char)'\x0'; x++) { /* alpha-numeric characters and a few other characters don't get encoded */ - if(((char)input[x] >= '0' && (char)input[x] <= '9') || ((char)input[x] >= 'A' && (char)input[x] <= 'Z') || ((char)input[x] >= (char)'a' && (char)input[x] <= (char)'z') || (char)input[x] == (char)'.' || (char)input[x] == (char)'-' || (char)input[x] == (char)'_' || (char)input[x] == (char)':' || (char)input[x] == (char)'/' || (char)input[x] == (char)'?' || (char)input[x] == (char)'=' || (char)input[x] == (char)'&') { + if( ((char)input[x] >= '0' && (char)input[x] <= '9') || + ((char)input[x] >= 'A' && (char)input[x] <= 'Z') || + ((char)input[x] >= 'a' && (char)input[x] <= 'z') || + (char)input[x] == '.' || + (char)input[x] == '-' || + (char)input[x] == '_' || + (char)input[x] == '~') { encoded_url_string[y] = input[x]; y++; } - /* spaces are pluses */ - else if((char)input[x] <= (char)' ') { - encoded_url_string[y] = '+'; - y++; - } - /* anything else gets represented by its hex value */ else { encoded_url_string[y] = '\x0'; @@ -2492,31 +2497,7 @@ int init_macros(void) { for (x = 0; x < MACRO_X_COUNT; x++) { macro_keys[x].code = x; macro_keys[x].name = macro_x_names[x]; - macro_keys[x].clean_options = 0; - - switch (x) { - /* output, perfdata, comments and author names need cleaning */ - case MACRO_HOSTOUTPUT: case MACRO_SERVICEOUTPUT: - case MACRO_HOSTPERFDATA: case MACRO_SERVICEPERFDATA: - case MACRO_HOSTACKAUTHOR: case MACRO_HOSTACKCOMMENT: - case MACRO_SERVICEACKAUTHOR: case MACRO_SERVICEACKCOMMENT: - case MACRO_LONGHOSTOUTPUT: case MACRO_LONGSERVICEOUTPUT: - case MACRO_HOSTGROUPNOTES: case MACRO_SERVICEGROUPNOTES: - macro_keys[x].clean_options = (STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS); - break; - - /* url macros get url-encoded */ - case MACRO_HOSTACTIONURL: case MACRO_HOSTNOTESURL: - case MACRO_SERVICEACTIONURL: case MACRO_SERVICENOTESURL: - case MACRO_HOSTGROUPNOTESURL: case MACRO_HOSTGROUPACTIONURL: - case MACRO_SERVICEGROUPNOTESURL: case MACRO_SERVICEGROUPACTIONURL: - macro_keys[x].clean_options = URL_ENCODE_MACRO_CHARS; - break; - default: - macro_keys[x].clean_options = 0; - break; - } - } + } qsort(macro_keys, x, sizeof(struct macro_key_code), macro_key_cmp); return OK; -- 1.7.1 |
From: Andreas E. <ae...@op...> - 2013-05-22 09:04:47
|
Will apply. Thanks. On 2013-05-22 10:41, Robin Sonefors wrote: > It's used after the main loop ends in the main function to remove the > lock file once we're shut down. > > As the variable was already freed and pointed to NULL, unlink would not > remove the lock file, but instead return EFAULT. This is not how daemons > are supposed to behave. > > Signed-off-by: Robin Sonefors <rob...@op...> > --- > base/utils.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/base/utils.c b/base/utils.c > index 5e038cb..362e683 100644 > --- a/base/utils.c > +++ b/base/utils.c > @@ -2902,7 +2902,6 @@ void free_memory(nagios_macros *mac) { > my_free(command_file); > mac->x[MACRO_COMMANDFILE] = NULL; /* assigned from command_file */ > my_free(log_archive_path); > - my_free(lock_file); > > for (i = 0; i < MAX_USER_MACROS; i++) { > my_free(macro_user[i]); > -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. |
From: Robin S. <rob...@op...> - 2013-05-22 08:41:43
|
It's used after the main loop ends in the main function to remove the lock file once we're shut down. As the variable was already freed and pointed to NULL, unlink would not remove the lock file, but instead return EFAULT. This is not how daemons are supposed to behave. Signed-off-by: Robin Sonefors <rob...@op...> --- base/utils.c | 1 - 1 file changed, 1 deletion(-) diff --git a/base/utils.c b/base/utils.c index 5e038cb..362e683 100644 --- a/base/utils.c +++ b/base/utils.c @@ -2902,7 +2902,6 @@ void free_memory(nagios_macros *mac) { my_free(command_file); mac->x[MACRO_COMMANDFILE] = NULL; /* assigned from command_file */ my_free(log_archive_path); - my_free(lock_file); for (i = 0; i < MAX_USER_MACROS; i++) { my_free(macro_user[i]); -- 1.7.11.7 |
From: Páll G. S. <pa...@ok...> - 2013-05-15 22:39:44
|
+like on moving to git. To celebrate i sent you a micro pull request on github. - Palli ----- Original Message ----- From: "Andreas Ericsson" <ae...@op...> To: "nagios-devel" <nag...@li...>, Nag...@li... Sent: Tuesday, May 14, 2013 1:48:15 PM Subject: [Nagios-users] svn -> git conversion As of today, the migration from subversion to git has been completed. The new git repository is still hosted at sourceforge. You can clone the repository using the following command: git clone git://git.code.sf.net/p/nagios/nagioscore and then browse the code locally in your own nagioscore folder. The svn repository will be decommisioned without further warning, so anyone who likes to stick to the bleeding edge of Nagios core should migrate to git ASAP. Cheers -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. ------------------------------------------------------------------------------ AlienVault Unified Security Management (USM) platform delivers complete security visibility with the essential security capabilities. Easily and efficiently configure, manage, and operate all of your security controls from a single console and one unified framework. Download a free trial. http://p.sf.net/sfu/alienvault_d2d _______________________________________________ Nagios-users mailing list Nag...@li... https://lists.sourceforge.net/lists/listinfo/nagios-users ::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. ::: Messages without supporting info will risk being sent to /dev/null |
From: Andreas E. <ae...@op...> - 2013-05-15 16:15:44
|
On 2013-05-15 15:32, Frost, Mark {BIS} wrote: > I take it this means you got Ethan to relent? :-) > I persuaded Eric Stanley, actually. He's in charge of most of the core-related issues on behalf of Nagios Enterprises, afaiu. It's nice to finally be able to give people proper credit for their work though. It always bugged me that I came out as author in the logs just because I happened to apply a patch that someone else wrote. Next step; Getting people to put up their own patch-queues and send me pull-requests so I can integrate useful stuff with my left hand while I drink beer with my right ;) -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. |
From: Frost, M. {BIS} <mar...@pe...> - 2013-05-15 14:07:08
|
I take it this means you got Ethan to relent? :-) -----Original Message----- From: Andreas Ericsson [mailto:ae...@op...] Sent: Tuesday, May 14, 2013 9:48 AM To: nagios-devel; Nag...@li... Subject: [Nagios-devel] svn -> git conversion As of today, the migration from subversion to git has been completed. The new git repository is still hosted at sourceforge. You can clone the repository using the following command: git clone git://git.code.sf.net/p/nagios/nagioscore and then browse the code locally in your own nagioscore folder. The svn repository will be decommisioned without further warning, so anyone who likes to stick to the bleeding edge of Nagios core should migrate to git ASAP. Cheers -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. ------------------------------------------------------------------------------ AlienVault Unified Security Management (USM) platform delivers complete security visibility with the essential security capabilities. Easily and efficiently configure, manage, and operate all of your security controls from a single console and one unified framework. Download a free trial. http://p.sf.net/sfu/alienvault_d2d _______________________________________________ Nagios-devel mailing list Nag...@li... https://lists.sourceforge.net/lists/listinfo/nagios-devel |
From: Andreas E. <ae...@op...> - 2013-05-14 13:48:27
|
As of today, the migration from subversion to git has been completed. The new git repository is still hosted at sourceforge. You can clone the repository using the following command: git clone git://git.code.sf.net/p/nagios/nagioscore and then browse the code locally in your own nagioscore folder. The svn repository will be decommisioned without further warning, so anyone who likes to stick to the bleeding edge of Nagios core should migrate to git ASAP. Cheers -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. |
From: Andreas E. <ae...@op...> - 2013-05-12 09:22:56
|
On 2013-05-10 17:43, Jeff wrote: > Hi all, > > I discovered an issue with the latest version of Nagios from svn with my > company's configuration. When a contactgroup definition contains both > members and contactgroup_members, Nagios segfaults when trying to verify > the configuration. After some debugging, I came up with a solution that > appears to work for us. > > The issue is that the when Nagios is "recombobulating" the > contactgroup_members, the call to strchr() is done with a null pointer, > because the loop with the existing controlling expression allows for an > extra iteration. Switching the controlling expression to use next_ptr > allows the loop to exit when it should, because the last iteration's call > to strchr() returns a null pointer. I'm not sure why it doesn't segfault > when specifying either members or contactgroup_members (not both), but my > solution appears to resolve the problem. > > Forgive me if there's a different way to propose a patch, as this is my > first post to the list. The (extremely simple) patch is as follows: > This works well. Applied and pushed. Thanks. -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. |
From: Jeff <ia...@gm...> - 2013-05-10 15:43:27
|
Hi all, I discovered an issue with the latest version of Nagios from svn with my company's configuration. When a contactgroup definition contains both members and contactgroup_members, Nagios segfaults when trying to verify the configuration. After some debugging, I came up with a solution that appears to work for us. The issue is that the when Nagios is "recombobulating" the contactgroup_members, the call to strchr() is done with a null pointer, because the loop with the existing controlling expression allows for an extra iteration. Switching the controlling expression to use next_ptr allows the loop to exit when it should, because the last iteration's call to strchr() returns a null pointer. I'm not sure why it doesn't segfault when specifying either members or contactgroup_members (not both), but my solution appears to resolve the problem. Forgive me if there's a different way to propose a patch, as this is my first post to the list. The (extremely simple) patch is as follows: --- diff -ur a/xdata/xodtemplate.c b/xdata/xodtemplate.c --- a/xdata/xodtemplate.c 2013-05-10 09:30:57.000000000 -0600 +++ b/xdata/xodtemplate.c 2013-05-10 09:31:01.000000000 -0600 @@ -6099,7 +6099,7 @@ xodtemplate_contactgroup *cg; char *ptr, *next_ptr; - for(next_ptr = ptr = temp_contactgroup->contactgroup_members; ptr; ptr = next_ptr + 1) { + for(next_ptr = ptr = temp_contactgroup->contactgroup_members; next_ptr; ptr = next_ptr + 1) { next_ptr = strchr(ptr, ','); if(next_ptr) *next_ptr = 0; --- Cheers, -- Jeff |
From: Andreas E. <ae...@op...> - 2013-05-08 16:53:37
|
On 2013-05-08 18:38, Robin Sonefors wrote: > contact_names are allowed to have spaces in them, so using space as a > delimiter doesn't really work. Space is thus not a valid delimiter for > contacts anywhere, except in escalations, where it is only valid after > the first comma. So you could have one contact with a space in its name, > as long as you put it first - and no more than that! > And we always strip() them afterwards, so no risk of getting the spaces included in the contact names. Neat. Thanks. -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. |
From: Robin S. <rob...@op...> - 2013-05-08 16:38:30
|
contact_names are allowed to have spaces in them, so using space as a delimiter doesn't really work. Space is thus not a valid delimiter for contacts anywhere, except in escalations, where it is only valid after the first comma. So you could have one contact with a space in its name, as long as you put it first - and no more than that! This patch allows you to have as many contacts with as many spaces as you want in your escalations. Signed-off-by: Robin Sonefors <rob...@op...> --- xdata/xodtemplate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c index bb1e14d..f1fe86e 100644 --- a/xdata/xodtemplate.c +++ b/xdata/xodtemplate.c @@ -7358,7 +7358,7 @@ int xodtemplate_register_serviceescalation(xodtemplate_serviceescalation *this_s /* add the contact groups */ if(this_serviceescalation->contact_groups != NULL) { - for(contact_group = strtok(this_serviceescalation->contact_groups, ","); contact_group != NULL; contact_group = strtok(NULL, ", ")) { + for(contact_group = strtok(this_serviceescalation->contact_groups, ","); contact_group != NULL; contact_group = strtok(NULL, ",")) { strip(contact_group); new_contactgroupsmember = add_contactgroup_to_serviceescalation(new_serviceescalation, contact_group); @@ -7372,7 +7372,7 @@ int xodtemplate_register_serviceescalation(xodtemplate_serviceescalation *this_s /* add the contacts */ if(this_serviceescalation->contacts != NULL) { - for(contact_name = strtok(this_serviceescalation->contacts, ","); contact_name != NULL; contact_name = strtok(NULL, ", ")) { + for(contact_name = strtok(this_serviceescalation->contacts, ","); contact_name != NULL; contact_name = strtok(NULL, ",")) { strip(contact_name); new_contactsmember = add_contact_to_serviceescalation(new_serviceescalation, contact_name); @@ -7715,7 +7715,7 @@ int xodtemplate_register_hostescalation(xodtemplate_hostescalation *this_hostesc /* add the contacts */ if(this_hostescalation->contacts != NULL) { - for(contact_name = strtok(this_hostescalation->contacts, ","); contact_name != NULL; contact_name = strtok(NULL, ", ")) { + for(contact_name = strtok(this_hostescalation->contacts, ","); contact_name != NULL; contact_name = strtok(NULL, ",")) { strip(contact_name); new_contactsmember = add_contact_to_hostescalation(new_hostescalation, contact_name); -- 1.7.11.7 |
From: nap <nap...@gm...> - 2013-05-07 06:04:39
|
On Mon, May 6, 2013 at 6:04 PM, Robin Sonefors <rob...@op...>wrote: > Hi list, > > A couple of excellent tests by Jean Gabès - marked as todo - pointed out > problems with how nagios calculates the next valid time in a timeperiod > that > has complicated combinations of exceptions and exclusions. > > This patchset refactors the relevant code to fix all failing tests, as > well as adds a > new one. > > > > Hi, Congrats, these timeperiod computation are really a nigthmare :D Especially with corner case like "I need the last monday but we are the last tuesday". If you need more tests for theses special cases, I can provide you some more, with really crazy time computation :p Jean |
From: Andreas E. <ae...@op...> - 2013-05-06 21:50:35
|
On 05/06/2013 06:04 PM, Robin Sonefors wrote: > Hi list, > > A couple of excellent tests by Jean Gabès - marked as todo - pointed out > problems with how nagios calculates the next valid time in a timeperiod that > has complicated combinations of exceptions and exclusions. > > This patchset refactors the relevant code to fix all failing tests, as well as adds a > new one. > Neat series. I'll apply tomorrow when I've had time to look at 2/6 a bit closer. -- Andreas Ericsson and...@op... OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace. |
From: Robin S. <rob...@op...> - 2013-05-06 16:21:49
|
There was a mention about the old prototype (for an internal method) making the code easier to test - in fact, it didn't, it just made things more awkward. Signed-off-by: Robin Sonefors <rob...@op...> --- base/utils.c | 14 +++++++------- t-tap/test_timeperiods.c | 36 ++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/base/utils.c b/base/utils.c index 739087c..99946fb 100644 --- a/base/utils.c +++ b/base/utils.c @@ -970,9 +970,9 @@ int check_time_against_period(time_t test_time, timeperiod *tperiod) { /*#define TEST_TIMEPERIODS_B 1*/ -void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod); +void _get_next_valid_time(time_t pref_time, time_t *valid_time, timeperiod *tperiod); -static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t *invalid_time, timeperiod *tperiod) { +static void _get_next_invalid_time(time_t pref_time, time_t *invalid_time, timeperiod *tperiod) { timeperiodexclusion *temp_timeperiodexclusion = NULL; int depth = 0; int max_depth = 300; // commonly roughly equal to "days in the future" @@ -1029,7 +1029,7 @@ static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t } for(temp_timeperiodexclusion = tperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { - _get_next_valid_time(last_earliest_time, current_time, &potential_time, temp_timeperiodexclusion->timeperiod_ptr); + _get_next_valid_time(last_earliest_time, &potential_time, temp_timeperiodexclusion->timeperiod_ptr); if (potential_time + 60 < earliest_time) earliest_time = potential_time + 60; } @@ -1044,8 +1044,8 @@ static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t *invalid_time = earliest_time; } -/* Separate this out from public get_next_valid_time for testing, so we can mock current_time */ -void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) { +/* Separate this out from public get_next_valid_time for testing */ +void _get_next_valid_time(time_t pref_time, time_t *valid_time, timeperiod *tperiod) { timeperiodexclusion *temp_timeperiodexclusion = NULL; int depth = 0; int max_depth = 300; // commonly roughly equal to "days in the future" @@ -1119,7 +1119,7 @@ void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_t earliest_time = midnight + 86400; } else { for(temp_timeperiodexclusion = tperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { - _get_next_invalid_time(earliest_time, current_time, &earliest_time, temp_timeperiodexclusion->timeperiod_ptr); + _get_next_invalid_time(earliest_time, &earliest_time, temp_timeperiodexclusion->timeperiod_ptr); #ifdef TEST_TIMEPERIODS_B printf(" FINAL EARLIEST TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); #endif @@ -1145,7 +1145,7 @@ void get_next_valid_time(time_t pref_time, time_t *valid_time, timeperiod *tperi pref_time = (pref_time < current_time) ? current_time : pref_time; - _get_next_valid_time(pref_time, current_time, valid_time, tperiod); + _get_next_valid_time(pref_time, valid_time, tperiod); } diff --git a/t-tap/test_timeperiods.c b/t-tap/test_timeperiods.c index e660855..6aa292f 100644 --- a/t-tap/test_timeperiods.c +++ b/t-tap/test_timeperiods.c @@ -147,7 +147,7 @@ int main(int argc, char **argv) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Always OK for 24x7 with TZ=UTC, time_t=%lu", test_time); chosen_valid_time = 0L; - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time"); test_time += 1800; c++; @@ -160,7 +160,7 @@ int main(int argc, char **argv) { while(c < iterations) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Always OK for 24x7 with TZ=Europe/London, time_t=%lu", test_time); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time, time_t=%lu", test_time); test_time += 1800; c++; @@ -178,7 +178,7 @@ int main(int argc, char **argv) { while(c < iterations) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Always OK for 24x7 with TZ=America/New_York, time_t=%lu", test_time); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time, time_t=%lu", test_time); test_time += 1800; c++; @@ -200,7 +200,7 @@ int main(int argc, char **argv) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1288103400, "Next valid time should be Tue Oct 26 16:30:00 2010, was %s", ctime(&chosen_valid_time)); @@ -209,7 +209,7 @@ int main(int argc, char **argv) { test_time = 1278939600; //mon jul 12 15:00:00 is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1279058340, "Next valid time should be Tue Jul 13 23:59:00 2010, was %s", ctime(&chosen_valid_time)); @@ -218,7 +218,7 @@ int main(int argc, char **argv) { test_time = 1278939600; //mon jul 12 15:00:00 is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1284474600, "Next valid time should be Tue Sep 14 16:30:00 2010, was %s", ctime(&chosen_valid_time)); @@ -227,7 +227,7 @@ int main(int argc, char **argv) { test_time = 1278939600; //mon jul 12 15:00:00 is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1283265000, "Next valid time should be Tue Aug 31 16:30:00 2010, was %s", ctime(&chosen_valid_time)); @@ -247,62 +247,62 @@ int main(int argc, char **argv) { test_time = 1256421000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sat Oct 24 22:50:00 2009 - false"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009"); test_time = 1256421661; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sat Oct 24 23:01:01 2009 - false"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009"); test_time = 1256425400; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 00:03:20 2009 - true"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 00:03:20 2009"); test_time = 1256429700; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 01:15:00 2009 - true"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 01:15:00 2009"); test_time = 1256430400; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sun Oct 25 01:26:40 2009 - false"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256440500, "Next valid time should be Sun Oct 25 03:15:00 2009, was %s", ctime(&chosen_valid_time)); test_time = 1256440500; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 03:15:00 2009 - true"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 03:15:00 2009"); test_time = 1256500000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 19:46:40 2009 - true"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256500000, "Next valid time=Sun Oct 25 19:46:40 2009"); test_time = 1256508000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 22:00:00 2009 - true"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256508000, "Next valid time=Sun Oct 25 22:00:00 2009"); test_time = 1256508001; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sun Oct 25 22:00:01 2009 - false"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009"); test_time = 1256513000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sun Oct 25 23:23:20 2009 - false"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009"); @@ -316,7 +316,7 @@ int main(int argc, char **argv) { test_time = 1268109420; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Mon Mar 8 23:37:00 2010 - false"); - _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1268115300, "Next valid time=Tue Mar 9 01:15:00 2010"); -- 1.7.11.7 |
From: Robin S. <rob...@op...> - 2013-05-06 16:21:48
|
In particular, that exercises its error path. Signed-off-by: Robin Sonefors <rob...@op...> --- t-tap/smallconfig/minimal.cfg | 6 ++++++ t-tap/test_timeperiods.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/t-tap/smallconfig/minimal.cfg b/t-tap/smallconfig/minimal.cfg index 0615efa..010e584 100644 --- a/t-tap/smallconfig/minimal.cfg +++ b/t-tap/smallconfig/minimal.cfg @@ -192,6 +192,12 @@ define timeperiod{ } +define timeperiod{ + timeperiod_name exclude_always + alias exclude_always + monday 00:00-24:00 + exclude 24x7 +} define contact { contact_name nagiosadmin diff --git a/t-tap/test_timeperiods.c b/t-tap/test_timeperiods.c index 6aa292f..bf35514 100644 --- a/t-tap/test_timeperiods.c +++ b/t-tap/test_timeperiods.c @@ -95,7 +95,7 @@ int main(int argc, char **argv) { int is_valid_time = 0; int iterations = 1000; - plan_tests(6043); + plan_tests(6046); /* reset program variables */ reset_variables(); @@ -230,7 +230,13 @@ int main(int argc, char **argv) { _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1283265000, "Next valid time should be Tue Aug 31 16:30:00 2010, was %s", ctime(&chosen_valid_time)); - + temp_timeperiod = find_timeperiod("exclude_always"); + ok(temp_timeperiod != NULL, "Testing exclude always"); + test_time = 1278939600; //mon jul 12 15:00:00 + is_valid_time = check_time_against_period(test_time, temp_timeperiod); + ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); + _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod); + ok(chosen_valid_time == test_time, "There should be no next valid time, was %s", ctime(&chosen_valid_time)); /* Back to New york */ -- 1.7.11.7 |
From: Robin S. <rob...@op...> - 2013-05-06 16:21:45
|
There are no more todos here - the tests pass. Their output was very unhelpful, though, so making that more helpful as well. Signed-off-by: Robin Sonefors <rob...@op...> --- t-tap/test_timeperiods.c | 50 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/t-tap/test_timeperiods.c b/t-tap/test_timeperiods.c index 9663231..e660855 100644 --- a/t-tap/test_timeperiods.c +++ b/t-tap/test_timeperiods.c @@ -195,56 +195,40 @@ int main(int argc, char **argv) { /* Timeperiod exclude tests, from Jean Gabes */ temp_timeperiod = find_timeperiod("Test_exclude"); - ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod"); + ok(temp_timeperiod != NULL, "Testing Exclude timeperiod"); test_time = 1278939600; //mon jul 12 15:00:00 - /* printf("Testing at time %s", ctime(&test_time)); */ is_valid_time = check_time_against_period(test_time, temp_timeperiod); - ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); + ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); - /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ - todo_start("Bug in exclude"); - ok(chosen_valid_time == 1288103400, "ME: Next valid time=Tue Oct 26 16:30:00 2010, was %i", chosen_valid_time); - todo_end(); + ok(chosen_valid_time == 1288103400, "Next valid time should be Tue Oct 26 16:30:00 2010, was %s", ctime(&chosen_valid_time)); temp_timeperiod = find_timeperiod("Test_exclude2"); - ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 2"); - test_time = 1278939600; - /* printf("Testing at time %s", ctime(&test_time)); */ + ok(temp_timeperiod != NULL, "Testing Exclude timeperiod 2"); + test_time = 1278939600; //mon jul 12 15:00:00 is_valid_time = check_time_against_period(test_time, temp_timeperiod); - ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); + ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); - /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ - todo_start("Bug in exclude 2"); - ok(chosen_valid_time == 1279058340, "ME: Next valid time=Tue Jul 13 23:59:00 2010"); - todo_end(); + ok(chosen_valid_time == 1279058340, "Next valid time should be Tue Jul 13 23:59:00 2010, was %s", ctime(&chosen_valid_time)); temp_timeperiod = find_timeperiod("Test_exclude3"); - ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 3"); - test_time = 1278939600; - /* printf("Testing at time %s", ctime(&test_time)); */ + ok(temp_timeperiod != NULL, "Testing Exclude timeperiod 3"); + test_time = 1278939600; //mon jul 12 15:00:00 is_valid_time = check_time_against_period(test_time, temp_timeperiod); - ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); + ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); - /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ - todo_start("Bug in exclude 3"); - ok(chosen_valid_time == 1284474600, "ME: Next valid time=Tue Sep 14 16:30:00 2010"); - todo_end(); + ok(chosen_valid_time == 1284474600, "Next valid time should be Tue Sep 14 16:30:00 2010, was %s", ctime(&chosen_valid_time)); temp_timeperiod = find_timeperiod("Test_exclude4"); - ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 4"); - test_time = 1278939600; - /* printf("Testing at time %s", ctime(&test_time)); */ + ok(temp_timeperiod != NULL, "Testing Exclude timeperiod 4"); + test_time = 1278939600; //mon jul 12 15:00:00 is_valid_time = check_time_against_period(test_time, temp_timeperiod); - ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); + ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); - /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ - todo_start("Bug in exclude 3"); - ok(chosen_valid_time == 1283265000, "ME: Next valid time=Tue Aug 31 16:30:00 2010"); - todo_end(); + ok(chosen_valid_time == 1283265000, "Next valid time should be Tue Aug 31 16:30:00 2010, was %s", ctime(&chosen_valid_time)); @@ -289,9 +273,7 @@ int main(int argc, char **argv) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sun Oct 25 01:26:40 2009 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); - todo_start("Is a bug in get_next_valid_time for a time that falls in the DST change hour period"); - ok(chosen_valid_time == 1256440500, "Next valid time=Sun Oct 25 03:15:00 2009") || printf("chosen_valid_time=%lu\n", chosen_valid_time); - todo_end(); + ok(chosen_valid_time == 1256440500, "Next valid time should be Sun Oct 25 03:15:00 2009, was %s", ctime(&chosen_valid_time)); test_time = 1256440500; is_valid_time = check_time_against_period(test_time, temp_timeperiod); -- 1.7.11.7 |
From: Robin S. <rob...@op...> - 2013-05-06 16:21:44
|
There were several problems with how it worked, when faced with exceptions and exclusions together with regular logic - Jean Gabes had contributed several examples to the test_timeperiod suite that were marked as TODO, that now passes just fine. This code wraps the old logic in a loop. Once an exclusion hits, we start over with checking for exceptions or weekday rules. If any rule moves the match to tomorrow, we start over checking for new exclusions, exceptions and weekday rules. Before, we didn't start over from scratch, only on the "level" we had already reached. Given that your timeperiod is crazy enough, or you use an empty timeperiod to mean 24x7, nagios might spend slightly more time than before figuring out your next valid time. The first case didn't behave correctly before, so that's not a problem. For the second case, nagios will only run it once, realize the check can't be scheduled, and leave it alone, so that shouldn't affect things in practice. The net line reduction comes from introducing a new helper, as get_next_valid_time and check_time_against_period were using exactly the same code to find rules to match against. Signed-off-by: Robin Sonefors <rob...@op...> --- base/utils.c | 586 +++++++++++++++++------------------------------------------ 1 file changed, 169 insertions(+), 417 deletions(-) diff --git a/base/utils.c b/base/utils.c index 73ac13b..939235c 100644 --- a/base/utils.c +++ b/base/utils.c @@ -711,46 +711,25 @@ static int get_dst_shift(time_t *start, time_t *end) { /*#define TEST_TIMEPERIODS_A 1*/ -/* see if the specified time falls into a valid time range in the given time period */ -int check_time_against_period(time_t test_time, timeperiod *tperiod) { - timeperiodexclusion *temp_timeperiodexclusion = NULL; - timeperiodexclusion *first_timeperiodexclusion = NULL; +static timerange* _get_matching_timerange(time_t test_time, timeperiod *tperiod) { daterange *temp_daterange = NULL; - timerange *temp_timerange = NULL; - time_t midnight = (time_t)0L; time_t start_time = (time_t)0L; time_t end_time = (time_t)0L; - int found_match = FALSE; + unsigned long days = 0L; + int year = 0; + int shift = 0; + time_t midnight = (time_t)0L; struct tm *t, tm_s; int daterange_type = 0; - unsigned long days = 0L; - time_t day_range_start = (time_t)0L; - time_t day_range_end = (time_t)0L; int test_time_year = 0; int test_time_mon = 0; int test_time_wday = 0; - int year = 0; - int shift; - log_debug_info(DEBUGL_FUNCTIONS, 0, "check_time_against_period()\n"); + log_debug_info(DEBUGL_FUNCTIONS, 0, "_get_matching_timerange()\n"); - /* if no period was specified, assume the time is good */ if(tperiod == NULL) - return OK; - - /* test exclusions first - if exclusions match current time, bail out with an error */ - /* clear exclusions list before recursing (and restore afterwards) to prevent endless loops... */ - first_timeperiodexclusion = tperiod->exclusions; - tperiod->exclusions = NULL; - for(temp_timeperiodexclusion = first_timeperiodexclusion; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { - if(check_time_against_period(test_time, temp_timeperiodexclusion->timeperiod_ptr) == OK) { - tperiod->exclusions = first_timeperiodexclusion; - return ERROR; - } - } - tperiod->exclusions = first_timeperiodexclusion; + return NULL; - /* save values for later */ t = localtime_r((time_t *)&test_time, &tm_s); test_time_year = t->tm_year; test_time_mon = t->tm_mon; @@ -930,59 +909,65 @@ int check_time_against_period(time_t test_time, timeperiod *tperiod) { printf("NEW START: %lu = %s", (unsigned long)start_time, ctime(&start_time)); printf("NEW END: %lu = %s", (unsigned long)end_time, ctime(&end_time)); printf("%d DAYS PASSED\n", days); - printf("DLST SHIFT: %d", shift); + printf("DLST SHIFT: %i\n", shift); #endif - /* time falls into the range of days */ - if(midnight >= start_time && midnight <= end_time) - found_match = TRUE; + /* time falls inside the range of days + * end time < start_time when range covers end-of-$unit + * (fe. end-of-month) */ + if((midnight + 84800 >= start_time && (midnight <= end_time || start_time > end_time)) || (midnight <= end_time && start_time > end_time)) { +#ifdef TEST_TIMEPERIODS_A + printf("(MATCH)\n"); +#endif + return temp_daterange->times; + } + } + } - /* found a day match, so see if time ranges are good */ - if(found_match == TRUE) { + return tperiod->days[test_time_wday]; +} - for(temp_timerange = temp_daterange->times; temp_timerange != NULL; temp_timerange = temp_timerange->next) { +/* see if the specified time falls into a valid time range in the given time period */ +int check_time_against_period(time_t test_time, timeperiod *tperiod) { + timerange *temp_timerange = NULL; + timeperiodexclusion *temp_timeperiodexclusion = NULL; + timeperiodexclusion *first_timeperiodexclusion = NULL; + struct tm *t, tm_s; + time_t midnight = (time_t)0L; + time_t day_range_start = (time_t)0L; + time_t day_range_end = (time_t)0L; - /* ranges with start/end of zero mean exlude this day */ - if(temp_timerange->range_start == 0 && temp_timerange->range_end == 0) { -#ifdef TEST_TIMEPERIODS_A - printf("0 MINUTE RANGE EXCLUSION\n"); -#endif - continue; - } + log_debug_info(DEBUGL_FUNCTIONS, 0, "check_time_against_period()\n"); - day_range_start = (time_t)(midnight + temp_timerange->range_start); - day_range_end = (time_t)(midnight + temp_timerange->range_end); + t = localtime_r((time_t *)&test_time, &tm_s); -#ifdef TEST_TIMEPERIODS_A - printf(" RANGE START: %lu (%lu) = %s", temp_timerange->range_start, (unsigned long)day_range_start, ctime(&day_range_start)); - printf(" RANGE END: %lu (%lu) = %s", temp_timerange->range_end, (unsigned long)day_range_end, ctime(&day_range_end)); -#endif + t->tm_sec = 0; + t->tm_min = 0; + t->tm_hour = 0; + midnight = mktime(t); - /* if the user-specified time falls in this range, return with a positive result */ - if(test_time >= day_range_start && test_time <= day_range_end) - return OK; - } + /* if no period was specified, assume the time is good */ + if(tperiod == NULL) + return OK; - /* no match, so bail with error */ - return ERROR; - } + first_timeperiodexclusion = tperiod->exclusions; + tperiod->exclusions = NULL; + for(temp_timeperiodexclusion = first_timeperiodexclusion; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { + if(check_time_against_period(test_time, temp_timeperiodexclusion->timeperiod_ptr) == OK) { + tperiod->exclusions = first_timeperiodexclusion; + return ERROR; } } + tperiod->exclusions = first_timeperiodexclusion; - - /**** check normal, weekly rotating schedule last ****/ - - /* check weekday time ranges */ - for(temp_timerange = tperiod->days[test_time_wday]; temp_timerange != NULL; temp_timerange = temp_timerange->next) { + for(temp_timerange = _get_matching_timerange(test_time, tperiod); temp_timerange != NULL; temp_timerange = temp_timerange->next) { day_range_start = (time_t)(midnight + temp_timerange->range_start); day_range_end = (time_t)(midnight + temp_timerange->range_end); - /* if the user-specified time falls in this range, return with a positive result */ if(test_time >= day_range_start && test_time <= day_range_end) return OK; } - return ERROR; } @@ -990,410 +975,175 @@ int check_time_against_period(time_t test_time, timeperiod *tperiod) { /*#define TEST_TIMEPERIODS_B 1*/ -/* Separate this out from public get_next_valid_time for testing, so we can mock current_time */ -void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) { - time_t preferred_time = (time_t)0L; - timerange *temp_timerange; - daterange *temp_daterange; - time_t midnight = (time_t)0L; +void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod); + +static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t *invalid_time, timeperiod *tperiod) { + timeperiodexclusion *temp_timeperiodexclusion = NULL; + timeperiodexclusion *first_timeperiodexclusion = NULL; + int depth = 0; + int max_depth = 300; // commonly roughly equal to "days in the future" struct tm *t, tm_s; - time_t day_start = (time_t)0L; + time_t earliest_time = pref_time; + time_t last_earliest_time = 0; + time_t midnight = (time_t)0L; time_t day_range_start = (time_t)0L; time_t day_range_end = (time_t)0L; - time_t start_time = (time_t)0L; - time_t end_time = (time_t)0L; - int have_earliest_time = FALSE; - time_t earliest_time = (time_t)0L; - time_t earliest_day = (time_t)0L; - time_t potential_time = (time_t)0L; - int weekday = 0; - int has_looped = FALSE; - int days_into_the_future = 0; - int daterange_type = 0; - unsigned long days = 0L; - unsigned long advance_interval = 0L; - int year = 0; /* new */ - int month = 0; /* new */ - - int pref_time_year = 0; - int pref_time_mon = 0; - int pref_time_wday = 0; - int current_time_year = 0; - int current_time_mon = 0; - int current_time_mday = 0; - int shift; - - /* preferred time must be now or in the future */ - preferred_time = (pref_time < current_time) ? current_time : pref_time; - - /* if no timeperiod, go with preferred time */ - if(tperiod == NULL) { - *valid_time = preferred_time; - return; - } - /* if the preferred time is valid in timeperiod, go with it */ - /* this is necessary because the code below won't catch exceptions where preferred day is last (or only) date in timeperiod (date range) and last valid time has already passed */ - /* performing this check and bailing out early allows us to skip having to check the next instance of a date range exception or weekday to determine the next valid time */ - if(check_time_against_period(preferred_time, tperiod) == OK) { -#ifdef TEST_TIMEPERIODS_B - printf("PREF TIME IS VALID\n"); -#endif - *valid_time = preferred_time; + /* if no period was specified, assume the time is good */ + if(tperiod == NULL) { + *invalid_time = pref_time; return; - } + } - /* calculate the start of the day (midnight, 00:00 hours) of preferred time */ - t = localtime_r(&preferred_time, &tm_s); - t->tm_sec = 0; - t->tm_min = 0; - t->tm_hour = 0; - midnight = mktime(t); + while (earliest_time != last_earliest_time && depth < max_depth) { + time_t potential_time = 0; + depth++; + last_earliest_time = earliest_time; - /* save pref time values for later */ - pref_time_year = t->tm_year; - pref_time_mon = t->tm_mon; - pref_time_wday = t->tm_wday; + t = localtime_r((time_t *)&earliest_time, &tm_s); + t->tm_sec = 0; + t->tm_min = 0; + t->tm_hour = 0; + midnight = mktime(t); - /* save current time values for later */ - t = localtime_r(¤t_time, &tm_s); - current_time_year = t->tm_year; - current_time_mon = t->tm_mon; - current_time_mday = t->tm_mday; + timerange *temp_timerange = _get_matching_timerange(earliest_time, tperiod); -#ifdef TEST_TIMEPERIODS_B - printf("PREF TIME: %lu = %s", (unsigned long)preferred_time, ctime(&preferred_time)); - printf("CURRENT TIME: %lu = %s", (unsigned long)current_time, ctime(¤t_time)); - printf("PREF YEAR: %d, MON: %d, MDAY: %d, WDAY: %d\n", pref_time_year, pref_time_mon, pref_time_mday, pref_time_wday); - printf("CURRENT YEAR: %d, MON: %d, MDAY: %d, WDAY: %d\n", current_time_year, current_time_mon, current_time_mday, current_time_wday); -#endif + for(; temp_timerange != NULL; temp_timerange = temp_timerange->next) { + /* ranges with start/end of zero mean exlude this day */ + if(temp_timerange->range_start == 0 && temp_timerange->range_end == 0) + continue; - /**** check exceptions (in this timeperiod definition) first ****/ - for(daterange_type = 0; daterange_type < DATERANGE_TYPES; daterange_type++) { + day_range_start = (time_t)(midnight + temp_timerange->range_start); + day_range_end = (time_t)(midnight + temp_timerange->range_end); #ifdef TEST_TIMEPERIODS_B - printf("TYPE: %d\n", daterange_type); + printf(" INVALID RANGE START: %lu (%lu) = %s", temp_timerange->range_start, (unsigned long)day_range_start, ctime(&day_range_start)); + printf(" INVALID RANGE END: %lu (%lu) = %s", temp_timerange->range_end, (unsigned long)day_range_end, ctime(&day_range_end)); #endif - for(temp_daterange = tperiod->exceptions[daterange_type]; temp_daterange != NULL; temp_daterange = temp_daterange->next) { - - /* get the start time */ - switch(daterange_type) { - case DATERANGE_CALENDAR_DATE: /* 2009-08-11 */ - t->tm_sec = 0; - t->tm_min = 0; - t->tm_hour = 0; - t->tm_mday = temp_daterange->smday; - t->tm_mon = temp_daterange->smon; - t->tm_year = (temp_daterange->syear - 1900); - t->tm_isdst = -1; - start_time = mktime(t); - break; - case DATERANGE_MONTH_DATE: /* january 1 */ - /* what year should we use? */ - year = (pref_time_year < current_time_year) ? current_time_year : pref_time_year; - /* advance an additional year if we already passed the end month date */ - if((temp_daterange->emon < current_time_mon) || ((temp_daterange->emon == current_time_mon) && temp_daterange->emday < current_time_mday)) - year++; - start_time = calculate_time_from_day_of_month(year, temp_daterange->smon, temp_daterange->smday); - break; - case DATERANGE_MONTH_DAY: /* day 3 */ - /* what year should we use? */ - year = (pref_time_year < current_time_year) ? current_time_year : pref_time_year; - /* use current month */ - month = current_time_mon; - /* advance an additional month (and possibly the year) if we already passed the end day of month */ - if(temp_daterange->emday < current_time_mday) { - /*if(month==1){*/ - if(month == 11) { - month = 0; - year++; - } - else - month++; - } - start_time = calculate_time_from_day_of_month(year, month, temp_daterange->smday); - break; - case DATERANGE_MONTH_WEEK_DAY: /* thursday 2 april */ - /* what year should we use? */ - year = (pref_time_year < current_time_year) ? current_time_year : pref_time_year; - /* calculate time of specified weekday of specific month */ - start_time = calculate_time_from_weekday_of_month(year, temp_daterange->smon, temp_daterange->swday, temp_daterange->swday_offset); - /* advance to next year if we've passed this month weekday already this year */ - if(start_time < preferred_time) { - year++; - start_time = calculate_time_from_weekday_of_month(year, temp_daterange->smon, temp_daterange->swday, temp_daterange->swday_offset); - } - break; - case DATERANGE_WEEK_DAY: /* wednesday 1 */ - /* what year should we use? */ - year = (pref_time_year < current_time_year) ? current_time_year : pref_time_year; - /* calculate time of specified weekday of month */ - start_time = calculate_time_from_weekday_of_month(year, pref_time_mon, temp_daterange->swday, temp_daterange->swday_offset); - /* advance to next month (or year) if we've passed this weekday of this month already */ - if(start_time < preferred_time) { - month = pref_time_mon; - if(month == 11) { - month = 0; - year++; - } - else - month++; - start_time = calculate_time_from_weekday_of_month(year, month, temp_daterange->swday, temp_daterange->swday_offset); - } - break; - default: - continue; - break; - } + if(day_range_start <= earliest_time && day_range_end > earliest_time) + potential_time = day_range_end + 60; + else + potential_time = earliest_time; + if(potential_time > earliest_time) { + earliest_time = potential_time; #ifdef TEST_TIMEPERIODS_B - printf("START TIME: %lu = %s", start_time, ctime(&start_time)); + printf(" EARLIEST INVALID TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); #endif - - /* get the end time */ - switch(daterange_type) { - case DATERANGE_CALENDAR_DATE: - t->tm_sec = 0; - t->tm_min = 0; - t->tm_hour = 0; - t->tm_mday = temp_daterange->emday; - t->tm_mon = temp_daterange->emon; - t->tm_year = (temp_daterange->eyear - 1900); - t->tm_isdst = -1; - end_time = mktime(t); - break; - case DATERANGE_MONTH_DATE: - /* use same year as was calculated for start time above */ - end_time = calculate_time_from_day_of_month(year, temp_daterange->emon, temp_daterange->emday); - /* advance a year if necessary: august 5 - feburary 2 */ - if(end_time < start_time) { - year++; - end_time = calculate_time_from_day_of_month(year, temp_daterange->emon, temp_daterange->emday); - } - break; - case DATERANGE_MONTH_DAY: - /* use same year and month as was calculated for start time above */ - end_time = calculate_time_from_day_of_month(year, month, temp_daterange->emday); - break; - case DATERANGE_MONTH_WEEK_DAY: - /* use same year as was calculated for start time above */ - end_time = calculate_time_from_weekday_of_month(year, temp_daterange->emon, temp_daterange->ewday, temp_daterange->ewday_offset); - /* advance a year if necessary: thursday 2 august - monday 3 february */ - if(end_time < start_time) { - year++; - end_time = calculate_time_from_weekday_of_month(year, temp_daterange->emon, temp_daterange->ewday, temp_daterange->ewday_offset); - } - break; - case DATERANGE_WEEK_DAY: - /* use same year and month as was calculated for start time above */ - end_time = calculate_time_from_weekday_of_month(year, month, temp_daterange->ewday, temp_daterange->ewday_offset); - break; - default: - continue; - break; } + } + first_timeperiodexclusion = tperiod->exclusions; + tperiod->exclusions = NULL; + for(temp_timeperiodexclusion = first_timeperiodexclusion; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { + _get_next_valid_time(last_earliest_time, current_time, &potential_time, temp_timeperiodexclusion->timeperiod_ptr); + if (potential_time + 60 < earliest_time) + earliest_time = potential_time + 60; + } + tperiod->exclusions = first_timeperiodexclusion; + } #ifdef TEST_TIMEPERIODS_B - printf("STARTTIME: %lu = %s", (unsigned long)start_time, ctime(&start_time)); - printf("ENDTIME1: %lu = %s", (unsigned long)end_time, ctime(&end_time)); + printf(" FINAL EARLIEST INVALID TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); #endif - /* start date was bad, so skip this date range */ - if((unsigned long)start_time == 0L) - continue; - - /* end date was bad - see if we can handle the error */ - if((unsigned long)end_time == 0L) { - switch(daterange_type) { - case DATERANGE_CALENDAR_DATE: - continue; - break; - case DATERANGE_MONTH_DATE: - /* end date can't be helped, so skip it */ - if(temp_daterange->emday < 0) - continue; - - /* else end date slipped past end of month, so use last day of month as end date */ - end_time = calculate_time_from_day_of_month(year, temp_daterange->emon, -1); - break; - case DATERANGE_MONTH_DAY: - /* end date can't be helped, so skip it */ - if(temp_daterange->emday < 0) - continue; - - /* else end date slipped past end of month, so use last day of month as end date */ - end_time = calculate_time_from_day_of_month(year, month, -1); - break; - case DATERANGE_MONTH_WEEK_DAY: - /* end date can't be helped, so skip it */ - if(temp_daterange->ewday_offset < 0) - continue; - - /* else end date slipped past end of month, so use last day of month as end date */ - end_time = calculate_time_from_day_of_month(year, pref_time_mon, -1); - break; - case DATERANGE_WEEK_DAY: - /* end date can't be helped, so skip it */ - if(temp_daterange->ewday_offset < 0) - continue; - - /* else end date slipped past end of month, so use last day of month as end date */ - end_time = calculate_time_from_day_of_month(year, month, -1); - break; - default: - continue; - break; - } - } + if (depth == max_depth) + *invalid_time = pref_time; + else + *invalid_time = earliest_time; + } -#ifdef TEST_TIMEPERIODS_B - printf("ENDTIME2: %lu = %s", (unsigned long)end_time, ctime(&end_time)); -#endif +/* Separate this out from public get_next_valid_time for testing, so we can mock current_time */ +void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) { + timeperiodexclusion *temp_timeperiodexclusion = NULL; + timeperiodexclusion *first_timeperiodexclusion = NULL; + int depth = 0; + int max_depth = 300; // commonly roughly equal to "days in the future" + time_t earliest_time = pref_time; + time_t last_earliest_time = 0; + struct tm *t, tm_s; + time_t midnight = (time_t)0L; + time_t day_range_start = (time_t)0L; + time_t day_range_end = (time_t)0L; + int have_earliest_time = FALSE; - /* if skipping days... */ - if(temp_daterange->skip_interval > 1) { + /* if no period was specified, assume the time is good */ + if(tperiod == NULL) { + *valid_time = pref_time; + return; + } - /* advance to the next possible skip date */ - if(start_time < preferred_time) { - /* check if interval is across dlst change and gets the compensation */ - shift = get_dst_shift(&start_time, &midnight); + while (earliest_time != last_earliest_time && depth < max_depth) { + time_t potential_time = 0; + have_earliest_time = FALSE; + depth++; + last_earliest_time = earliest_time; - /* how many days have passed between skip start date and preferred time? */ - days = (shift + (unsigned long)midnight - (unsigned long)start_time) / (3600 * 24); + t = localtime_r((time_t *)&earliest_time, &tm_s); + t->tm_sec = 0; + t->tm_min = 0; + t->tm_hour = 0; + midnight = mktime(t); + timerange *temp_timerange = _get_matching_timerange(earliest_time, tperiod); #ifdef TEST_TIMEPERIODS_B - printf("MIDNIGHT: %lu = %s", midnight, ctime(&midnight)); - printf("%lu SECONDS PASSED\n", (midnight - (unsigned long)start_time)); - printf("%d DAYS PASSED\n", days); - printf("REMAINDER: %d\n", (days % temp_daterange->skip_interval)); - printf("SKIP INTERVAL: %d\n", temp_daterange->skip_interval); - printf("DLST SHIFT: %d", shift); + printf(" RANGE START: %lu\n", temp_timerange ? temp_timerange->range_start : 0); + printf(" RANGE END: %lu\n", temp_timerange ? temp_timerange->range_end : 0); #endif - /* advance start date to next skip day */ - if((days % temp_daterange->skip_interval) == 0) - start_time += (days * 3600 * 24); - else - start_time += ((days - (days % temp_daterange->skip_interval) + temp_daterange->skip_interval) * 3600 * 24); - } + for(; temp_timerange != NULL; temp_timerange = temp_timerange->next) { + /* ranges with start/end of zero mean exlude this day */ + if(temp_timerange->range_start == 0 && temp_timerange->range_end == 0) + continue; - /* if skipping has no end, use start date as end */ - if((daterange_type == DATERANGE_CALENDAR_DATE) && is_daterange_single_day(temp_daterange) == TRUE) - end_time = start_time; - } + day_range_start = (time_t)(midnight + temp_timerange->range_start); + day_range_end = (time_t)(midnight + temp_timerange->range_end); #ifdef TEST_TIMEPERIODS_B - printf("\nSTART: %lu = %s", (unsigned long)start_time, ctime(&start_time)); - printf("END: %lu = %s", (unsigned long)end_time, ctime(&end_time)); - printf("PREFERRED: %lu = %s", (unsigned long)preferred_time, ctime(&preferred_time)); - printf("CURRENT: %lu = %s", (unsigned long)current_time, ctime(¤t_time)); + printf(" RANGE START: %lu (%lu) = %s", temp_timerange->range_start, (unsigned long)day_range_start, ctime(&day_range_start)); + printf(" RANGE END: %lu (%lu) = %s", temp_timerange->range_end, (unsigned long)day_range_end, ctime(&day_range_end)); #endif - /* skip this date range its out of bounds with what we want */ - if(preferred_time > end_time) + /* range is out of bounds */ + if(day_range_end < last_earliest_time) continue; - /* how many days at a time should we advance? */ - if(temp_daterange->skip_interval > 1) - advance_interval = temp_daterange->skip_interval; - else - advance_interval = 1; - - /* advance through the date range */ - for(day_start = start_time; day_start <= end_time; day_start += (advance_interval * 3600 * 24)) { - - /* we already found a time from a higher-precendence date range exception */ - if(day_start >= earliest_day && have_earliest_time == TRUE) - continue; - - for(temp_timerange = temp_daterange->times; temp_timerange != NULL; temp_timerange = temp_timerange->next) { - - /* ranges with start/end of zero mean exlude this day */ - if(temp_timerange->range_start == 0 && temp_timerange->range_end == 0) - continue; - - day_range_start = (time_t)(day_start + temp_timerange->range_start); - day_range_end = (time_t)(day_start + temp_timerange->range_end); + /* preferred time occurs before range start, so use range start time as earliest potential time */ + if(day_range_start >= last_earliest_time) + potential_time = day_range_start; + /* preferred time occurs between range start/end, so use preferred time as earliest potential time */ + else if(day_range_end >= last_earliest_time) + potential_time = last_earliest_time; + /* is this the earliest time found thus far? */ + if(have_earliest_time == FALSE || potential_time < earliest_time) { + earliest_time = potential_time; #ifdef TEST_TIMEPERIODS_B - printf(" RANGE START: %lu (%lu) = %s", temp_timerange->range_start, (unsigned long)day_range_start, ctime(&day_range_start)); - printf(" RANGE END: %lu (%lu) = %s", temp_timerange->range_end, (unsigned long)day_range_end, ctime(&day_range_end)); + printf(" EARLIEST TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); #endif - - /* range is out of bounds */ - if(day_range_end < preferred_time) - continue; - - /* preferred time occurs before range start, so use range start time as earliest potential time */ - if(day_range_start >= preferred_time) - potential_time = day_range_start; - /* preferred time occurs between range start/end, so use preferred time as earliest potential time */ - else if(day_range_end >= preferred_time) - potential_time = preferred_time; - - /* is this the earliest time found thus far? */ - if(have_earliest_time == FALSE || potential_time < earliest_time) { - have_earliest_time = TRUE; - earliest_time = potential_time; - earliest_day = day_start; -#ifdef TEST_TIMEPERIODS_B - printf(" EARLIEST TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); -#endif - } - } } + have_earliest_time = TRUE; } - } - - - /**** find next available time from normal, weekly rotating schedule (in this timeperiod definition) ****/ - - /* check a one week rotation of time */ - has_looped = FALSE; - for(weekday = pref_time_wday, days_into_the_future = 0;; weekday++, days_into_the_future++) { - - /* break out of the loop if we have checked an entire week already */ - if(has_looped == TRUE && weekday >= pref_time_wday) - break; - - if(weekday >= 7) { - weekday -= 7; - has_looped = TRUE; - } - - /* calculate start of this future weekday */ - day_start = (time_t)(midnight + (days_into_the_future * 3600 * 24)); - - /* we already found a time from a higher-precendence date range exception */ - if(day_start == earliest_day) - continue; - - /* check all time ranges for this day of the week */ - for(temp_timerange = tperiod->days[weekday]; temp_timerange != NULL; temp_timerange = temp_timerange->next) { - - /* calculate the time for the start of this time range */ - day_range_start = (time_t)(day_start + temp_timerange->range_start); - - if((have_earliest_time == FALSE || day_range_start < earliest_time) && day_range_start >= preferred_time) { - have_earliest_time = TRUE; - earliest_time = day_range_start; - earliest_day = day_start; + if (have_earliest_time == FALSE) { + earliest_time = midnight + 86400; + } else { + first_timeperiodexclusion = tperiod->exclusions; + tperiod->exclusions = NULL; + for(temp_timeperiodexclusion = first_timeperiodexclusion; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { + _get_next_invalid_time(earliest_time, current_time, &earliest_time, temp_timeperiodexclusion->timeperiod_ptr); +#ifdef TEST_TIMEPERIODS_B + printf(" FINAL EARLIEST TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); +#endif } + tperiod->exclusions = first_timeperiodexclusion; } } - - /* if we couldn't find a time period there must be none defined */ - if(have_earliest_time == FALSE || earliest_time == (time_t)0) - *valid_time = (time_t)preferred_time; - - /* else use the calculated time */ + if (depth == max_depth) + *valid_time = pref_time; else *valid_time = earliest_time; - - return; } @@ -1406,6 +1156,8 @@ void get_next_valid_time(time_t pref_time, time_t *valid_time, timeperiod *tperi /* get time right now, preferred time must be now or in the future */ time(¤t_time); + pref_time = (pref_time < current_time) ? current_time : pref_time; + _get_next_valid_time(pref_time, current_time, valid_time, tperiod); } -- 1.7.11.7 |
From: Robin S. <rob...@op...> - 2013-05-06 16:21:44
|
I intend to refactor the time periods, and need a bit of encouragement from something that tells me that everything is OK. Signed-off-by: Robin Sonefors <rob...@op...> --- base/utils.c | 2 +- t-tap/Makefile.in | 8 +- t-tap/test_timeperiods.c | 196 ++--------------------------------------------- 3 files changed, 13 insertions(+), 193 deletions(-) diff --git a/base/utils.c b/base/utils.c index 44cf98d..73ac13b 100644 --- a/base/utils.c +++ b/base/utils.c @@ -991,7 +991,7 @@ int check_time_against_period(time_t test_time, timeperiod *tperiod) { /*#define TEST_TIMEPERIODS_B 1*/ /* Separate this out from public get_next_valid_time for testing, so we can mock current_time */ -static void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) { +void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) { time_t preferred_time = (time_t)0L; timerange *temp_timerange; daterange *temp_daterange; diff --git a/t-tap/Makefile.in b/t-tap/Makefile.in index f686d99..3079ee0 100644 --- a/t-tap/Makefile.in +++ b/t-tap/Makefile.in @@ -10,7 +10,7 @@ SRC_CGI=../cgi SRC_COMMON=../common CC=@CC@ -CFLAGS=@CFLAGS@ @DEFS@ -DNSCORE -I../include -I../tap/src +CFLAGS=@CFLAGS@ @DEFS@ -DNSCORE -I../include -I../tap/src -I.. TESTS = test_logging test_events test_timeperiods test_nagios_config TESTS += test_xsddefault @@ -22,11 +22,11 @@ TESTS += test_downtime XSD_OBJS = $(SRC_CGI)/statusdata-cgi.o $(SRC_CGI)/xstatusdata-cgi.o XSD_OBJS += $(SRC_CGI)/objects-cgi.o $(SRC_CGI)/xobjects-cgi.o XSD_OBJS += $(SRC_CGI)/comments-cgi.o $(SRC_CGI)/downtime-cgi.o -XSD_OBJS += $(SRC_CGI)/cgiutils.o $(SRC_CGI)/skiplist.o ../common/shared.o +XSD_OBJS += $(SRC_CGI)/cgiutils.o ../common/shared.o TP_OBJS = $(SRC_BASE)/utils.o $(SRC_BASE)/config.o $(SRC_BASE)/macros-base.o TP_OBJS += $(SRC_BASE)/objects-base.o $(SRC_BASE)/xobjects-base.o -TP_OBJS += $(SRC_BASE)/skiplist.o ../common/shared.o +TP_OBJS += ../common/shared.o CFG_OBJS = $(TP_OBJS) CFG_OBJS += $(SRC_BASE)/comments-base.o $(SRC_BASE)/xcomments-base.o @@ -35,7 +35,7 @@ CFG_OBJS += $(SRC_BASE)/retention-base.o $(SRC_BASE)/xretention-base.o LDFLAGS=@LDFLAGS@ -LIBS=@LIBS@ +LIBS=@LIBS@ ../lib/libnagios.a prefix=@prefix@ exec_prefix=@exec_prefix@ diff --git a/t-tap/test_timeperiods.c b/t-tap/test_timeperiods.c index 534ece1..9663231 100644 --- a/t-tap/test_timeperiods.c +++ b/t-tap/test_timeperiods.c @@ -43,191 +43,6 @@ #include "../include/nebmodules.h" #include "tap.h" -char *config_file = NULL; -char *log_file = NULL; -char *command_file = NULL; -char *temp_file = NULL; -char *temp_path = NULL; -char *check_result_path = NULL; -char *lock_file = NULL; -char *log_archive_path = NULL; -char *nagios_user = NULL; -char *nagios_group = NULL; - -extern char *macro_x[MACRO_X_COUNT]; - -char *global_host_event_handler = NULL; -char *global_service_event_handler = NULL; -command *global_host_event_handler_ptr = NULL; -command *global_service_event_handler_ptr = NULL; - -char *ocsp_command = NULL; -char *ochp_command = NULL; -command *ocsp_command_ptr = NULL; -command *ochp_command_ptr = NULL; - -char *illegal_object_chars = NULL; -char *illegal_output_chars = NULL; - -int use_regexp_matches = FALSE; -int use_true_regexp_matching = FALSE; - -int use_syslog = DEFAULT_USE_SYSLOG; -int log_notifications = DEFAULT_NOTIFICATION_LOGGING; -int log_service_retries = DEFAULT_LOG_SERVICE_RETRIES; -int log_host_retries = DEFAULT_LOG_HOST_RETRIES; -int log_event_handlers = DEFAULT_LOG_EVENT_HANDLERS; -int log_initial_states = DEFAULT_LOG_INITIAL_STATES; -int log_external_commands = DEFAULT_LOG_EXTERNAL_COMMANDS; -int log_passive_checks = DEFAULT_LOG_PASSIVE_CHECKS; - -unsigned long logging_options = 0; -unsigned long syslog_options = 0; - -int service_check_timeout = DEFAULT_SERVICE_CHECK_TIMEOUT; -int host_check_timeout = DEFAULT_HOST_CHECK_TIMEOUT; -int event_handler_timeout = DEFAULT_EVENT_HANDLER_TIMEOUT; -int notification_timeout = DEFAULT_NOTIFICATION_TIMEOUT; -int ocsp_timeout = DEFAULT_OCSP_TIMEOUT; -int ochp_timeout = DEFAULT_OCHP_TIMEOUT; - -int interval_length = DEFAULT_INTERVAL_LENGTH; -int service_inter_check_delay_method = ICD_SMART; -int host_inter_check_delay_method = ICD_SMART; -int service_interleave_factor_method = ILF_SMART; -int max_host_check_spread = DEFAULT_HOST_CHECK_SPREAD; -int max_service_check_spread = DEFAULT_SERVICE_CHECK_SPREAD; - -int command_check_interval = DEFAULT_COMMAND_CHECK_INTERVAL; -int check_reaper_interval = DEFAULT_CHECK_REAPER_INTERVAL; -int max_check_reaper_time = DEFAULT_MAX_REAPER_TIME; -int service_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL; -int host_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL; -int auto_rescheduling_interval = DEFAULT_AUTO_RESCHEDULING_INTERVAL; - -int check_external_commands = DEFAULT_CHECK_EXTERNAL_COMMANDS; -int check_orphaned_services = DEFAULT_CHECK_ORPHANED_SERVICES; -int check_orphaned_hosts = DEFAULT_CHECK_ORPHANED_HOSTS; -int check_service_freshness = DEFAULT_CHECK_SERVICE_FRESHNESS; -int check_host_freshness = DEFAULT_CHECK_HOST_FRESHNESS; -int auto_reschedule_checks = DEFAULT_AUTO_RESCHEDULE_CHECKS; -int auto_rescheduling_window = DEFAULT_AUTO_RESCHEDULING_WINDOW; - -int additional_freshness_latency = DEFAULT_ADDITIONAL_FRESHNESS_LATENCY; -int allow_empty_hostgroup_assignment = DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT; - -int check_for_updates = DEFAULT_CHECK_FOR_UPDATES; -int bare_update_check = DEFAULT_BARE_UPDATE_CHECK; -time_t last_update_check = 0L; -int update_available = FALSE; -char *last_program_version = NULL; -char *new_program_version = NULL; - -time_t last_log_rotation = 0L; - -int use_aggressive_host_checking = DEFAULT_AGGRESSIVE_HOST_CHECKING; -unsigned long cached_host_check_horizon = DEFAULT_CACHED_HOST_CHECK_HORIZON; -unsigned long cached_service_check_horizon = DEFAULT_CACHED_SERVICE_CHECK_HORIZON; -int enable_predictive_host_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS; -int enable_predictive_service_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS; - -int soft_state_dependencies = FALSE; - -int retain_state_information = FALSE; -int retention_update_interval = DEFAULT_RETENTION_UPDATE_INTERVAL; -int use_retained_program_state = TRUE; -int use_retained_scheduling_info = FALSE; -int retention_scheduling_horizon = DEFAULT_RETENTION_SCHEDULING_HORIZON; -unsigned long modified_host_process_attributes = MODATTR_NONE; -unsigned long modified_service_process_attributes = MODATTR_NONE; -unsigned long retained_host_attribute_mask = 0L; -unsigned long retained_service_attribute_mask = 0L; -unsigned long retained_contact_host_attribute_mask = 0L; -unsigned long retained_contact_service_attribute_mask = 0L; -unsigned long retained_process_host_attribute_mask = 0L; -unsigned long retained_process_service_attribute_mask = 0L; - -unsigned long next_comment_id = 0L; -unsigned long next_downtime_id = 0L; -unsigned long next_event_id = 0L; -unsigned long next_problem_id = 0L; -unsigned long next_notification_id = 0L; - -int log_rotation_method = LOG_ROTATION_NONE; - -int sigshutdown = FALSE; -int sigrestart = FALSE; -char *sigs[35] = {"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "URG", "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "IO", "PWR", "UNUSED", "ZERR", "DEBUG", (char *)NULL}; -int caught_signal = FALSE; -int sig_id = 0; - -int restarting = FALSE; - -int verify_config = FALSE; -int test_scheduling = FALSE; -int precache_objects = FALSE; -int use_precached_objects = FALSE; - -int daemon_mode = FALSE; -int daemon_dumps_core = TRUE; - -int max_parallel_service_checks = DEFAULT_MAX_PARALLEL_SERVICE_CHECKS; -int currently_running_service_checks = 0; -int currently_running_host_checks = 0; - -time_t program_start = 0L; -time_t event_start = 0L; -int nagios_pid = 0; -int enable_notifications = TRUE; -int execute_service_checks = TRUE; -int accept_passive_service_checks = TRUE; -int execute_host_checks = TRUE; -int accept_passive_host_checks = TRUE; -int enable_event_handlers = TRUE; -int obsess_over_services = FALSE; -int obsess_over_hosts = FALSE; - -int translate_passive_host_checks = DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS; -int passive_host_checks_are_soft = DEFAULT_PASSIVE_HOST_CHECKS_SOFT; - -int status_update_interval = DEFAULT_STATUS_UPDATE_INTERVAL; - -int time_change_threshold = DEFAULT_TIME_CHANGE_THRESHOLD; - -unsigned long event_broker_options = BROKER_NOTHING; - -int process_performance_data = DEFAULT_PROCESS_PERFORMANCE_DATA; - -int enable_flap_detection = DEFAULT_ENABLE_FLAP_DETECTION; - -double low_service_flap_threshold = DEFAULT_LOW_SERVICE_FLAP_THRESHOLD; -double high_service_flap_threshold = DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD; -double low_host_flap_threshold = DEFAULT_LOW_HOST_FLAP_THRESHOLD; -double high_host_flap_threshold = DEFAULT_HIGH_HOST_FLAP_THRESHOLD; - -int use_large_installation_tweaks = DEFAULT_USE_LARGE_INSTALLATION_TWEAKS; -int enable_environment_macros = TRUE; -int free_child_process_memory = -1; -int child_processes_fork_twice = -1; - -int date_format = DATE_FORMAT_US; -char *use_timezone = NULL; - -unsigned long update_uid = 0L; - - -notification *notification_list; - -unsigned long max_check_result_file_age = DEFAULT_MAX_CHECK_RESULT_AGE; - -check_stats check_statistics[MAX_CHECK_STATS_TYPES]; - -char *debug_file; -int debug_level = DEFAULT_DEBUG_LEVEL; -int debug_verbosity = DEFAULT_DEBUG_VERBOSITY; -unsigned long max_debug_file_size = DEFAULT_MAX_DEBUG_FILE_SIZE; - - /* Dummy variables */ sched_info scheduling_info; timed_event event_list_low; @@ -249,10 +64,15 @@ int neb_unload_all_modules(int flags, int reason) {} int neb_add_module(char *filename, char *args, int should_be_loaded) {} void broker_system_command(int type, int flags, int attr, struct timeval start_time, struct timeval end_time, double exectime, int timeout, int early_timeout, int retcode, char *cmd, char *output, struct timeval *timestamp) {} -int schedule_new_event(int event_type, int high_priority, time_t run_time, int recurring, unsigned long event_interval, void *timing_func, int compensate_for_time_change, void *event_data, void *event_args, int event_options) {} +timed_event *schedule_new_event(int event_type, int high_priority, time_t run_time, int recurring, unsigned long event_interval, void *timing_func, int compensate_for_time_change, void *event_data, void *event_args, int event_options) {} int my_tcp_connect(char *host_name, int port, int *sd, int timeout) {} int my_recvall(int s, char *buf, int *len, int timeout) {} int neb_free_module_list(void) {} +int close_command_file(void) {} +int close_log_file(void) {} +int fix_log_file_owner(uid_t uid, gid_t gid) {} +int handle_async_service_check_result(service *temp_service, check_result *queued_check_result) {} +int handle_async_host_check_result(host *temp_host, check_result *queued_check_result) {} int main(int argc, char **argv) { int result; @@ -376,7 +196,7 @@ int main(int argc, char **argv) { /* Timeperiod exclude tests, from Jean Gabes */ temp_timeperiod = find_timeperiod("Test_exclude"); ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod"); - test_time = 1278939600; + test_time = 1278939600; //mon jul 12 15:00:00 /* printf("Testing at time %s", ctime(&test_time)); */ is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); @@ -384,7 +204,7 @@ int main(int argc, char **argv) { _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ todo_start("Bug in exclude"); - ok(chosen_valid_time == 1288103400, "ME: Next valid time=Tue Oct 26 16:30:00 2010"); + ok(chosen_valid_time == 1288103400, "ME: Next valid time=Tue Oct 26 16:30:00 2010, was %i", chosen_valid_time); todo_end(); -- 1.7.11.7 |
From: Robin S. <rob...@op...> - 2013-05-06 16:21:44
|
Nagios no longer loads them, so stop confusing the reader with this. Signed-off-by: Robin Sonefors <rob...@op...> --- base/utils.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/base/utils.c b/base/utils.c index 939235c..739087c 100644 --- a/base/utils.c +++ b/base/utils.c @@ -931,7 +931,6 @@ static timerange* _get_matching_timerange(time_t test_time, timeperiod *tperiod) int check_time_against_period(time_t test_time, timeperiod *tperiod) { timerange *temp_timerange = NULL; timeperiodexclusion *temp_timeperiodexclusion = NULL; - timeperiodexclusion *first_timeperiodexclusion = NULL; struct tm *t, tm_s; time_t midnight = (time_t)0L; time_t day_range_start = (time_t)0L; @@ -950,15 +949,11 @@ int check_time_against_period(time_t test_time, timeperiod *tperiod) { if(tperiod == NULL) return OK; - first_timeperiodexclusion = tperiod->exclusions; - tperiod->exclusions = NULL; - for(temp_timeperiodexclusion = first_timeperiodexclusion; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { + for(temp_timeperiodexclusion = tperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { if(check_time_against_period(test_time, temp_timeperiodexclusion->timeperiod_ptr) == OK) { - tperiod->exclusions = first_timeperiodexclusion; return ERROR; } } - tperiod->exclusions = first_timeperiodexclusion; for(temp_timerange = _get_matching_timerange(test_time, tperiod); temp_timerange != NULL; temp_timerange = temp_timerange->next) { @@ -979,7 +974,6 @@ void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_t static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t *invalid_time, timeperiod *tperiod) { timeperiodexclusion *temp_timeperiodexclusion = NULL; - timeperiodexclusion *first_timeperiodexclusion = NULL; int depth = 0; int max_depth = 300; // commonly roughly equal to "days in the future" struct tm *t, tm_s; @@ -1034,14 +1028,11 @@ static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t } } - first_timeperiodexclusion = tperiod->exclusions; - tperiod->exclusions = NULL; - for(temp_timeperiodexclusion = first_timeperiodexclusion; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { + for(temp_timeperiodexclusion = tperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { _get_next_valid_time(last_earliest_time, current_time, &potential_time, temp_timeperiodexclusion->timeperiod_ptr); if (potential_time + 60 < earliest_time) earliest_time = potential_time + 60; } - tperiod->exclusions = first_timeperiodexclusion; } #ifdef TEST_TIMEPERIODS_B printf(" FINAL EARLIEST INVALID TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); @@ -1056,7 +1047,6 @@ static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t /* Separate this out from public get_next_valid_time for testing, so we can mock current_time */ void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) { timeperiodexclusion *temp_timeperiodexclusion = NULL; - timeperiodexclusion *first_timeperiodexclusion = NULL; int depth = 0; int max_depth = 300; // commonly roughly equal to "days in the future" time_t earliest_time = pref_time; @@ -1128,15 +1118,12 @@ void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_t if (have_earliest_time == FALSE) { earliest_time = midnight + 86400; } else { - first_timeperiodexclusion = tperiod->exclusions; - tperiod->exclusions = NULL; - for(temp_timeperiodexclusion = first_timeperiodexclusion; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { + for(temp_timeperiodexclusion = tperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { _get_next_invalid_time(earliest_time, current_time, &earliest_time, temp_timeperiodexclusion->timeperiod_ptr); #ifdef TEST_TIMEPERIODS_B printf(" FINAL EARLIEST TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time)); #endif } - tperiod->exclusions = first_timeperiodexclusion; } } -- 1.7.11.7 |
From: Robin S. <rob...@op...> - 2013-05-06 16:21:42
|
Hi list, A couple of excellent tests by Jean Gabès - marked as todo - pointed out problems with how nagios calculates the next valid time in a timeperiod that has complicated combinations of exceptions and exclusions. This patchset refactors the relevant code to fix all failing tests, as well as adds a new one. |