Icinga-core 1.4.0
next gen monitoring
cgi/readlogs.c File Reference

functions to read and filter log files in normal and reverse order More...

#include "../include/cgiutils.h"
#include "../include/readlogs.h"

Go to the source code of this file.

Functions

log reading
int add_log_filter (int requested_filter, int include_exclude)
 Add Filter to the list of log filters.
int get_log_entries (char *log_file, char *search_string, int reverse, time_t ts_start, time_t ts_end)
 Read's a defined log file and stores the entries into entry list struct.
void free_log_filters (void)
 frees all memory allocated to list of log filters in memory
void free_log_entries (void)
 frees all memory allocated to list of log entries in memory
log archive determination
void get_log_archive_to_use (int archive, char *file_name, int file_name_length)
 returns the file name of a log file depending on archive number and log_rotation_method
int determine_archive_to_use_from_time (time_t target_time)
 returns an archive number for a given timestamp corresponding to log_rotation_method
void determine_log_rotation_times (int archive)
 determines the log rotation times

Variables

initializing lists
logfilterfilter_list = NULL
logentryentry_list = NULL
logentrylast_entry = NULL
external vars
int log_rotation_method
char log_file [MAX_FILENAME_LENGTH]
char log_archive_path [MAX_FILENAME_LENGTH]
vars for log archive determination
time_t this_scheduled_log_rotation = 0L
time_t last_scheduled_log_rotation = 0L
time_t next_scheduled_log_rotation = 0L

Detailed Description

functions to read and filter log files in normal and reverse order

Definition in file readlogs.c.


Function Documentation

int add_log_filter ( int  requested_filter,
int  include_exclude 
)

Add Filter to the list of log filters.

Parameters:
[in]requested_filterthe id of the log entry you want to filter for
[in]include_excludetype of filter
  • LOGFILTER_INCLUDE
  • LOGFILTER_EXCLUDE
Returns:
wether adding filter was successful or not (see readlogs.h)
Return values:
READLOG_OK
READLOG_ERROR
READLOG_ERROR_MEMORY
Warning:
at the moment can be only one type of filters for all elements, only include for all OR exclude for all. Combining is not available at the moment
Author:
Ricardo Bartels

With this function you can add filters before reading the actual log entries from file. This will prevent allocating memory for log entries we don't need anyway. Be aware that you can use only one type of filtering (include or exclude). If you want to have all entries except a view, then use the filter with exclude. If you need just a few defined ones (like in notifications.c) then use include.

  • LOGFILTER_INCLUDE keeps the log entries specified and throws out the rest
  • LOGFILTER_EXCLUDE keeps all log entries except the ones which are specified

Definition at line 83 of file readlogs.c.

int determine_archive_to_use_from_time ( time_t  target_time)

returns an archive number for a given timestamp corresponding to log_rotation_method

Parameters:
[in]target_timethe timestamp for which the archive number should be returned for
Returns:
the archive number corresponding to given target_time

This function determines log archive to use, given a specific time. The log archive number represents the log file.

In case the log_rotation_method would be daily then this archive numbers would return:

  • 0 - today
  • 1 - yesterday
  • 2 - 2 days ago
  • 3 - ...

Definition at line 471 of file readlogs.c.

void determine_log_rotation_times ( int  archive)

determines the log rotation times

Parameters:
[in]archivenumber of archive to determine the log rotation times for

determines the log rotation times - past, present, future - depending on archive number and log_rotation_method

Definition at line 506 of file readlogs.c.

void free_log_entries ( void  )

frees all memory allocated to list of log entries in memory

Author:
Ricardo Bartels

Definition at line 387 of file readlogs.c.

void free_log_filters ( void  )

frees all memory allocated to list of log filters in memory

Author:
Ricardo Bartels

Definition at line 369 of file readlogs.c.

void get_log_archive_to_use ( int  archive,
char *  file_name,
int  file_name_length 
)

returns the file name of a log file depending on archive number and log_rotation_method

Parameters:
[in]archivenumber of log archive to return file name for
[out]file_namereturns the file name corresponding to archive
[in]file_name_lengththe maximum length of the char in file_name

This function determines the log file we should use (from current time). Depending which archive number given it returns the full file name of the log file we can read. (get_log_entries)

Definition at line 417 of file readlogs.c.

int get_log_entries ( char *  log_file,
char *  search_string,
int  reverse,
time_t  ts_start,
time_t  ts_end 
)

Read's a defined log file and stores the entries into entry list struct.

Parameters:
[in]log_filethe full path of the log file to read
[in]search_stringa string you are searching for. Set to NULL to disable search function
[in]reversethis bool defines which order the log entries should return
[in]ts_startdefines the start timestamp for log entries
  • >=0 means unix timestamp
  • -1 deactivated
[in]ts_enddefines the end timestamp for log entries
  • >=0 means unix timestamp
  • -1 deactivated
Returns:
Return values:
READLOG_OK
READLOG_ERROR
READLOG_ERROR_MEMORY
READLOG_ERROR_NOFILE
READLOG_ERROR_FILTER
Author:
Ricardo Bartels

This functions reads a log_file and and try's (if set) to filter for a search string. This search string uses regular expressions. The reverse option defines if you want have your log entries returned in normal or revers order. Normal order for returning would be from the newest entry to the oldest. You can also set a time "window". This defines if you want to exclude entries which are outside of these "window". Then only entries will be returned which are between start and end. Very useful if user has all entries in one log file.

Definition at line 142 of file readlogs.c.


Variable Documentation

the list with all current logentries

Definition at line 36 of file readlogs.c.

list of filters which should applyed during log reading

Definition at line 35 of file readlogs.c.

the last used log entry element

Definition at line 37 of file readlogs.c.

timestamp of last log rotation

Definition at line 52 of file readlogs.c.

char log_archive_path[MAX_FILENAME_LENGTH]

the full path to the archived log files

Definition at line 69 of file icinga.c.

char log_file[MAX_FILENAME_LENGTH]

the full file name of the main icinga log file

Definition at line 63 of file icinga.c.

the log rotation method of the main Icinga log file see common.h

readlogs.c

Definition at line 174 of file icinga.c.

timestamp of next log rotation

Definition at line 53 of file readlogs.c.

timestamp of current log rotation

Definition at line 51 of file readlogs.c.

 All Data Structures Files Functions Variables Typedefs Defines