Icinga-core 1.4.0
next gen monitoring
include/readlogs.h File Reference

defines and structures which are used in combination with functions from readlogs.c More...

#include "config.h"

Go to the source code of this file.

Data Structures

struct  logentry_struct
 log entry data struct More...
struct  logentry_filter
 log entry filter struct More...

Defines

LOG ENTRY TYPES
#define LOGENTRY_STARTUP   1
#define LOGENTRY_SHUTDOWN   2
#define LOGENTRY_RESTART   3
#define LOGENTRY_BAILOUT   4
#define LOGENTRY_LOG_ROTATION   5
#define LOGENTRY_ACTIVE_MODE   6
#define LOGENTRY_STANDBY_MODE   7
#define LOGENTRY_EXTERNAL_COMMAND   8
#define LOGENTRY_ERROR_COMMAND_EXECUTION   9
#define LOGENTRY_HOST_DOWN   10
#define LOGENTRY_HOST_UNREACHABLE   11
#define LOGENTRY_HOST_RECOVERY   12
#define LOGENTRY_HOST_UP   13
#define LOGENTRY_HOST_NOTIFICATION   14
#define LOGENTRY_HOST_EVENT_HANDLER   15
#define LOGENTRY_HOST_FLAPPING_STARTED   16
#define LOGENTRY_HOST_FLAPPING_STOPPED   17
#define LOGENTRY_HOST_FLAPPING_DISABLED   18
#define LOGENTRY_HOST_DOWNTIME_STARTED   19
#define LOGENTRY_HOST_DOWNTIME_STOPPED   20
#define LOGENTRY_HOST_DOWNTIME_CANCELLED   21
#define LOGENTRY_HOST_INITIAL_STATE   22
#define LOGENTRY_HOST_CURRENT_STATE   23
#define LOGENTRY_PASSIVE_HOST_CHECK   24
#define LOGENTRY_SERVICE_CRITICAL   25
#define LOGENTRY_SERVICE_WARNING   26
#define LOGENTRY_SERVICE_UNKNOWN   27
#define LOGENTRY_SERVICE_RECOVERY   28
#define LOGENTRY_SERVICE_OK   29
#define LOGENTRY_SERVICE_NOTIFICATION   30
#define LOGENTRY_SERVICE_EVENT_HANDLER   31
#define LOGENTRY_SERVICE_FLAPPING_STARTED   32
#define LOGENTRY_SERVICE_FLAPPING_STOPPED   33
#define LOGENTRY_SERVICE_FLAPPING_DISABLED   34
#define LOGENTRY_SERVICE_DOWNTIME_STARTED   35
#define LOGENTRY_SERVICE_DOWNTIME_STOPPED   36
#define LOGENTRY_SERVICE_DOWNTIME_CANCELLED   37
#define LOGENTRY_SERVICE_INITIAL_STATE   38
#define LOGENTRY_SERVICE_CURRENT_STATE   39
#define LOGENTRY_PASSIVE_SERVICE_CHECK   40
#define LOGENTRY_IDOMOD   41
#define LOGENTRY_NPCDMOD   42
#define LOGENTRY_AUTOSAVE   43
#define LOGENTRY_SYSTEM_WARNING   44
#define LOGENTRY_UNDEFINED   999
LOG FILTER TYPES
#define LOGFILTER_INCLUDE   333
#define LOGFILTER_EXCLUDE   666
READ LOG ENTRIES RETURN CODES
#define READLOG_OK   0
#define READLOG_ERROR   1
#define READLOG_ERROR_MEMORY   2
#define READLOG_ERROR_NOFILE   3
#define READLOG_ERROR_FILTER   4

Typedefs

typedef struct logentry_struct logentry
 log entry data struct
typedef struct logentry_filter logfilter
 log entry filter struct

Functions

log reading
int add_log_filter (int, int)
 Add Filter to the list of log filters.
int get_log_entries (char *, char *, int, time_t, time_t)
 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, char *, int)
 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)
 returns an archive number for a given timestamp corresponding to log_rotation_method
void determine_log_rotation_times (int)
 determines the log rotation times

Detailed Description

defines and structures which are used in combination with functions from readlogs.c

Definition in file readlogs.h.


Define Documentation

#define LOGENTRY_ACTIVE_MODE   6

Definition at line 45 of file readlogs.h.

#define LOGENTRY_AUTOSAVE   43

Definition at line 91 of file readlogs.h.

#define LOGENTRY_BAILOUT   4

Definition at line 43 of file readlogs.h.

#define LOGENTRY_ERROR_COMMAND_EXECUTION   9

Definition at line 48 of file readlogs.h.

#define LOGENTRY_EXTERNAL_COMMAND   8

Definition at line 47 of file readlogs.h.

#define LOGENTRY_HOST_CURRENT_STATE   23

Definition at line 65 of file readlogs.h.

#define LOGENTRY_HOST_DOWN   10

Definition at line 50 of file readlogs.h.

#define LOGENTRY_HOST_DOWNTIME_CANCELLED   21

Definition at line 62 of file readlogs.h.

#define LOGENTRY_HOST_DOWNTIME_STARTED   19

Definition at line 60 of file readlogs.h.

#define LOGENTRY_HOST_DOWNTIME_STOPPED   20

Definition at line 61 of file readlogs.h.

#define LOGENTRY_HOST_EVENT_HANDLER   15

Definition at line 55 of file readlogs.h.

#define LOGENTRY_HOST_FLAPPING_DISABLED   18

Definition at line 59 of file readlogs.h.

#define LOGENTRY_HOST_FLAPPING_STARTED   16

Definition at line 57 of file readlogs.h.

#define LOGENTRY_HOST_FLAPPING_STOPPED   17

Definition at line 58 of file readlogs.h.

#define LOGENTRY_HOST_INITIAL_STATE   22

Definition at line 64 of file readlogs.h.

#define LOGENTRY_HOST_NOTIFICATION   14

Definition at line 54 of file readlogs.h.

#define LOGENTRY_HOST_RECOVERY   12

Definition at line 52 of file readlogs.h.

#define LOGENTRY_HOST_UNREACHABLE   11

Definition at line 51 of file readlogs.h.

#define LOGENTRY_HOST_UP   13

Definition at line 53 of file readlogs.h.

#define LOGENTRY_IDOMOD   41

Definition at line 89 of file readlogs.h.

#define LOGENTRY_LOG_ROTATION   5

Definition at line 44 of file readlogs.h.

#define LOGENTRY_NPCDMOD   42

Definition at line 90 of file readlogs.h.

#define LOGENTRY_PASSIVE_HOST_CHECK   24

Definition at line 67 of file readlogs.h.

#define LOGENTRY_PASSIVE_SERVICE_CHECK   40

Definition at line 87 of file readlogs.h.

#define LOGENTRY_RESTART   3

Definition at line 42 of file readlogs.h.

#define LOGENTRY_SERVICE_CRITICAL   25

Definition at line 69 of file readlogs.h.

#define LOGENTRY_SERVICE_CURRENT_STATE   39

Definition at line 85 of file readlogs.h.

#define LOGENTRY_SERVICE_DOWNTIME_CANCELLED   37

Definition at line 82 of file readlogs.h.

#define LOGENTRY_SERVICE_DOWNTIME_STARTED   35

Definition at line 80 of file readlogs.h.

#define LOGENTRY_SERVICE_DOWNTIME_STOPPED   36

Definition at line 81 of file readlogs.h.

#define LOGENTRY_SERVICE_EVENT_HANDLER   31

Definition at line 75 of file readlogs.h.

#define LOGENTRY_SERVICE_FLAPPING_DISABLED   34

Definition at line 79 of file readlogs.h.

#define LOGENTRY_SERVICE_FLAPPING_STARTED   32

Definition at line 77 of file readlogs.h.

#define LOGENTRY_SERVICE_FLAPPING_STOPPED   33

Definition at line 78 of file readlogs.h.

#define LOGENTRY_SERVICE_INITIAL_STATE   38

Definition at line 84 of file readlogs.h.

#define LOGENTRY_SERVICE_NOTIFICATION   30

Definition at line 74 of file readlogs.h.

#define LOGENTRY_SERVICE_OK   29

Definition at line 73 of file readlogs.h.

#define LOGENTRY_SERVICE_RECOVERY   28

Definition at line 72 of file readlogs.h.

#define LOGENTRY_SERVICE_UNKNOWN   27

Definition at line 71 of file readlogs.h.

#define LOGENTRY_SERVICE_WARNING   26

Definition at line 70 of file readlogs.h.

#define LOGENTRY_SHUTDOWN   2

Definition at line 41 of file readlogs.h.

#define LOGENTRY_STANDBY_MODE   7

Definition at line 46 of file readlogs.h.

#define LOGENTRY_STARTUP   1

Definition at line 40 of file readlogs.h.

#define LOGENTRY_SYSTEM_WARNING   44

Definition at line 92 of file readlogs.h.

#define LOGENTRY_UNDEFINED   999

Definition at line 94 of file readlogs.h.

#define LOGFILTER_EXCLUDE   666

Definition at line 100 of file readlogs.h.

#define LOGFILTER_INCLUDE   333

Definition at line 99 of file readlogs.h.

#define READLOG_ERROR   1

Definition at line 108 of file readlogs.h.

#define READLOG_ERROR_FILTER   4

Definition at line 111 of file readlogs.h.

#define READLOG_ERROR_MEMORY   2

Definition at line 109 of file readlogs.h.

#define READLOG_ERROR_NOFILE   3

Definition at line 110 of file readlogs.h.

#define READLOG_OK   0

Definition at line 107 of file readlogs.h.


Typedef Documentation

typedef struct logentry_struct logentry

log entry data struct

structure to hold single log entries get_log_entries

typedef struct logentry_filter logfilter

log entry filter struct

structure to hold log file filters add_log_filter


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.

 All Data Structures Files Functions Variables Typedefs Defines