1 /* 2 ** Zabbix 3 ** Copyright (C) 2001-2021 Zabbix SIA 4 ** 5 ** This program is free software; you can redistribute it and/or modify 6 ** it under the terms of the GNU General Public License as published by 7 ** the Free Software Foundation; either version 2 of the License, or 8 ** (at your option) any later version. 9 ** 10 ** This program is distributed in the hope that it will be useful, 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 ** GNU General Public License for more details. 14 ** 15 ** You should have received a copy of the GNU General Public License 16 ** along with this program; if not, write to the Free Software 17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 **/ 19 20 #ifndef ZABBIX_LOGFILES_H 21 #define ZABBIX_LOGFILES_H 22 23 #include "zbxregexp.h" 24 #include "md5.h" 25 #include "../metrics.h" 26 #include "persistent_state.h" 27 28 #define ZBX_MD5_PRINT_BUF_LEN ((MD5_DIGEST_SIZE) * 2 + 1) /* for MD5 sum representation with hex-digits */ 29 30 typedef enum 31 { 32 ZBX_LOG_ROTATION_LOGRT = 0, /* pure rotation model */ 33 ZBX_LOG_ROTATION_LOGCPT, /* copy-truncate rotation model */ 34 ZBX_LOG_ROTATION_REREAD, /* reread if modification time changes but size does not */ 35 ZBX_LOG_ROTATION_NO_REREAD /* don't reread if modification time changes but size does not */ 36 } 37 zbx_log_rotation_options_t; 38 39 struct st_logfile 40 { 41 char *filename; 42 int mtime; /* st_mtime from stat() */ 43 int seq; /* number in processing order */ 44 int retry; 45 int incomplete; /* 0 - the last record ends with a newline, 1 - the last record contains */ 46 /* no newline at the end */ 47 int copy_of; /* '-1' - the file is not a copy. '0 <= copy_of' - this file is a copy of */ 48 /* the file with index 'copy_of' in the old log file list. */ 49 zbx_uint64_t dev; /* ID of device containing file */ 50 zbx_uint64_t ino_lo; /* UNIX: inode number. Microsoft Windows: nFileIndexLow or FileId.LowPart */ 51 zbx_uint64_t ino_hi; /* Microsoft Windows: nFileIndexHigh or FileId.HighPart */ 52 zbx_uint64_t size; /* st_size from stat() */ 53 zbx_uint64_t processed_size; /* how far the Zabbix agent has analyzed the file */ 54 int md5_block_size; /* size of the first and last blocks of file for which the md5 sum is */ 55 /* calculated (in 'first_block_md5') */ 56 md5_byte_t first_block_md5[MD5_DIGEST_SIZE]; /* md5 sum of the initial part of the file */ 57 zbx_uint64_t last_block_offset; /* position of the last block from the beginning of file */ 58 md5_byte_t last_block_md5[MD5_DIGEST_SIZE]; /* md5 sum of the last block */ 59 }; 60 61 typedef int (*zbx_process_value_func_t)(const char *server, unsigned short port, const char *host, 62 const char *key, const char *value, unsigned char state, zbx_uint64_t *lastlogsize, const int *mtime, 63 const unsigned long *timestamp, const char *source, const unsigned short *severity, 64 const unsigned long *logeventid, unsigned char flags); 65 66 void destroy_logfile_list(struct st_logfile **logfiles, int *logfiles_alloc, int *logfiles_num); 67 68 int process_log_check(char *server, unsigned short port, zbx_vector_ptr_t *regexps, ZBX_ACTIVE_METRIC *metric, 69 zbx_process_value_func_t process_value_cb, zbx_uint64_t *lastlogsize_sent, int *mtime_sent, 70 char **error, zbx_vector_pre_persistent_t *prep_vec); 71 struct st_logfile *find_last_processed_file_in_logfiles_list(struct st_logfile *logfiles, int logfiles_num); 72 #endif 73