[icinga-checkins] icinga.org: icinga-core/r1.8: classic-ui: fixed backtrack_archives only getting calculated on a daily log rotation basis #3416

git at icinga.org git at icinga.org
Wed Nov 21 16:11:45 CET 2012


Module: icinga-core
Branch: r1.8
Commit: 0c72eb6b91e13b3851d650d622e71b92f4949217
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=0c72eb6b91e13b3851d650d622e71b92f4949217

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Tue Nov 20 21:34:36 2012 +0100

classic-ui: fixed backtrack_archives only getting calculated on a daily log rotation basis #3416

refs: #3416

number of backtrack_archives are set to find the initial state of
a host/service when reading historical data. since the log reading
got changed with 1.8 the calculation wasn't correct anymore. Now
it calculates the seconds which have to be substract from
start_time_stamp when reading logs, based on @log_rotation_method
and @ backtrack_archives correctly.

---

 Changelog          |    2 ++
 cgi/avail.c        |    2 +-
 cgi/histogram.c    |    2 +-
 cgi/readlogs.c     |   22 ++++++++++++++++++++++
 cgi/trends.c       |    2 +-
 include/readlogs.h |    1 +
 6 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index e3bf040..37c86b9 100644
--- a/Changelog
+++ b/Changelog
@@ -30,6 +30,8 @@ FIXES
 * classic ui: fixed Double-listed host dependencies in host extinfo.cgi #3295 - RB
 * classic ui: fixed sort_icinga_logfiles_by_name() in readlogs.c fails to take NULL pointers into consideration #3398 - CF
 * classic ui: fixed committing acknowledgement cmd negates flags for send_notification and sticky_ack #3329 - RB
+* classic ui: fixed backtrack_archives only getting calculated on a daily log rotation basis #3416 - RB
+
 
 CHANGES
 
diff --git a/cgi/avail.c b/cgi/avail.c
index a2dc80c..872ec26 100644
--- a/cgi/avail.c
+++ b/cgi/avail.c
@@ -2868,7 +2868,7 @@ void read_archived_state_data(void) {
 	logentry *entry_list = NULL;
 	logfilter *filter_list = NULL;
 
-	status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - (60 * 60 * 24 * backtrack_archives), t2);
+	status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - get_backtrack_seconds(backtrack_archives), t2);
 
 	if (status != READLOG_ERROR_FATAL) {
 
diff --git a/cgi/histogram.c b/cgi/histogram.c
index 19b41af..8862192 100644
--- a/cgi/histogram.c
+++ b/cgi/histogram.c
@@ -2046,7 +2046,7 @@ void read_archived_state_data(void) {
 	add_log_filter(&filter_list, LOGENTRY_SHUTDOWN, LOGFILTER_INCLUDE);
 	add_log_filter(&filter_list, LOGENTRY_BAILOUT, LOGFILTER_INCLUDE);
 
-	status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - (60 * 60 * 24 * backtrack_archives), t2);
+	status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - get_backtrack_seconds(backtrack_archives), t2);
 
 	free_log_filters(&filter_list);
 
diff --git a/cgi/readlogs.c b/cgi/readlogs.c
index 85e0a03..3c3d87a 100644
--- a/cgi/readlogs.c
+++ b/cgi/readlogs.c
@@ -41,6 +41,7 @@ struct file_data {
     @{ **/
 extern char	log_file[MAX_FILENAME_LENGTH];		/**< the full file name of the main icinga log file */
 extern char	log_archive_path[MAX_FILENAME_LENGTH];	/**< the full path to the archived log files */
+extern int	log_rotation_method;			/**< time interval of log rotation */
 /** @} */
 
 
@@ -591,3 +592,24 @@ void free_log_entries(logentry **entry_list) {
 
 	return;
 }
+
+/** @brief returns amount of backtrack_seconds to substract from start_time_stamp
+ *  @param [in] backtrack_archives number of backtrack_archives
+ *  @return amount of backtrack_seconds
+ *  @author Ricardo Bartels
+ *
+ * returns amount of backtrack_seconds to substract from start_time_stamp
+ * when reading logs, based on @log_rotation_method and @ backtrack_archives
+**/
+time_t get_backtrack_seconds(int backtrack_archives) {
+
+	if (log_rotation_method == LOG_ROTATION_MONTHLY)
+		return ( 60 * 60 * 24 * 31 * backtrack_archives);
+	else if (log_rotation_method == LOG_ROTATION_DAILY)
+		return ( 60 * 60 * 24  * backtrack_archives);
+	else if (log_rotation_method == LOG_ROTATION_HOURLY)
+		return ( 60 * 60 * backtrack_archives);
+	else	// LOG_ROTATION_WEEKLY
+		return ( 60 * 60 * 24 * 7 * backtrack_archives);
+
+}
diff --git a/cgi/trends.c b/cgi/trends.c
index ad2bd56..84047d5 100644
--- a/cgi/trends.c
+++ b/cgi/trends.c
@@ -2346,7 +2346,7 @@ void read_archived_state_data(void) {
 		add_log_filter(&filter_list, LOGENTRY_BAILOUT, LOGFILTER_INCLUDE);
 	}
 
-	status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - (60 * 60 * 24 * backtrack_archives), t2);
+	status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - get_backtrack_seconds(backtrack_archives), t2);
 
 	free_log_filters(&filter_list);
 
diff --git a/include/readlogs.h b/include/readlogs.h
index cc90825..02080c5 100644
--- a/include/readlogs.h
+++ b/include/readlogs.h
@@ -141,6 +141,7 @@ int add_log_filter(logfilter **filter_list, int requested_filter, int include_ex
 int get_log_entries(logentry **entry_list, logfilter **filter_list, char **error_text, char *search_string, int reverse, time_t ts_start, time_t ts_end);
 void free_log_filters(logfilter **filter_list);
 void free_log_entries(logentry **entry_list);
+time_t get_backtrack_seconds(int backtrack_archives);
 /**@}*/
 
 #ifdef __cplusplus





More information about the icinga-checkins mailing list