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 
26 typedef enum
27 {
28 	ZBX_LOG_ROTATION_LOGRT = 0,	/* pure rotation model */
29 	ZBX_LOG_ROTATION_LOGCPT,	/* copy-truncate rotation model */
30 	ZBX_LOG_ROTATION_REREAD,	/* reread if modification time changes but size does not */
31 	ZBX_LOG_ROTATION_NO_REREAD	/* don't reread if modification time changes but size does not */
32 }
33 zbx_log_rotation_options_t;
34 
35 struct	st_logfile
36 {
37 	char		*filename;
38 	int		mtime;		/* st_mtime from stat() */
39 	int		md5size;	/* size of the initial part for which the md5 sum is calculated */
40 	int		seq;		/* number in processing order */
41 	int		retry;
42 	int		incomplete;	/* 0 - the last record ends with a newline, 1 - the last record contains */
43 					/* no newline at the end */
44 	int		copy_of;	/* '-1' - the file is not a copy. '0 <= copy_of' - this file is a copy of */
45 					/* the file with index 'copy_of' in the old log file list. */
46 	zbx_uint64_t	dev;		/* ID of device containing file */
47 	zbx_uint64_t	ino_lo;		/* UNIX: inode number. Microsoft Windows: nFileIndexLow or FileId.LowPart */
48 	zbx_uint64_t	ino_hi;		/* Microsoft Windows: nFileIndexHigh or FileId.HighPart */
49 	zbx_uint64_t	size;		/* st_size from stat() */
50 	zbx_uint64_t	processed_size;	/* how far the Zabbix agent has analyzed the file */
51 	md5_byte_t	md5buf[MD5_DIGEST_SIZE];	/* md5 sum of the initial part of the file */
52 };
53 
54 typedef int (*zbx_process_value_func_t)(const char *, unsigned short, const char *, const char *, const char *,
55 		unsigned char, zbx_uint64_t *, const int *, unsigned long *, const char *, unsigned short *,
56 		unsigned long *, unsigned char);
57 
58 void	destroy_logfile_list(struct st_logfile **logfiles, int *logfiles_alloc, int *logfiles_num);
59 
60 int	process_logrt(unsigned char flags, const char *filename, zbx_uint64_t *lastlogsize, int *mtime,
61 		zbx_uint64_t *lastlogsize_sent, int *mtime_sent, unsigned char *skip_old_data, int *big_rec,
62 		int *use_ino, char **err_msg, struct st_logfile **logfiles_old, const int *logfiles_num_old,
63 		struct st_logfile **logfiles_new, int *logfiles_num_new, const char *encoding,
64 		zbx_vector_ptr_t *regexps, const char *pattern, const char *output_template, int *p_count, int *s_count,
65 		zbx_process_value_func_t process_value, const char *server, unsigned short port, const char *hostname,
66 		const char *key, int *jumped, float max_delay, double *start_time, zbx_uint64_t *processed_bytes,
67 		zbx_log_rotation_options_t rotation_type);
68 #endif
69