Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/types/sink.h |
| 3 | * This file provides definitions for event sinks |
| 4 | * |
| 5 | * Copyright (C) 2000-2019 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _TYPES_SINK_H |
| 23 | #define _TYPES_SINK_H |
| 24 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 25 | #include <haproxy/api-t.h> |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 26 | #include <common/buffer.h> |
Willy Tarreau | eb6f701 | 2020-05-27 16:21:26 +0200 | [diff] [blame] | 27 | #include <import/ist.h> |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 28 | |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 29 | /* A sink may be of 4 distinct types : |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 30 | * - file descriptor (such as stdout) |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 31 | * - ring buffer, readable from CLI |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 32 | */ |
| 33 | enum sink_type { |
| 34 | SINK_TYPE_NEW, // not yet initialized |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 35 | SINK_TYPE_FD, // events sent to a file descriptor |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 36 | SINK_TYPE_BUFFER, // events sent to a ring buffer |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | /* This indicates the default event format, which is the destination's |
| 40 | * preferred format, but may be overridden by the source. |
| 41 | */ |
| 42 | enum sink_fmt { |
| 43 | SINK_FMT_RAW, // raw text sent as-is |
| 44 | SINK_FMT_SHORT, // raw text prefixed with a syslog level |
| 45 | SINK_FMT_ISO, // raw text prefixed with ISO time |
| 46 | SINK_FMT_TIMED, // syslog level then ISO |
| 47 | SINK_FMT_RFC3164, // regular syslog |
| 48 | SINK_FMT_RFC5424, // extended syslog |
| 49 | }; |
| 50 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 51 | struct sink_forward_target { |
| 52 | struct server *srv; // used server |
| 53 | struct appctx *appctx; // appctx of current session |
| 54 | size_t ofs; // ring buffer reader offset |
| 55 | __decl_hathreads(HA_SPINLOCK_T lock); // lock to protect current struct |
| 56 | struct sink_forward_target *next; |
| 57 | }; |
| 58 | |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 59 | /* describes the configuration and current state of an event sink */ |
| 60 | struct sink { |
| 61 | struct list sink_list; // position in the sink list |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 62 | char *name; // sink name |
| 63 | char *desc; // sink description |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 64 | enum sink_fmt fmt; // format expected by the sink |
| 65 | enum sink_type type; // type of storage |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 66 | uint32_t maxlen; // max message length (truncated above) |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 67 | struct proxy* forward_px; // proxy used to forward |
| 68 | struct sink_forward_target *sft; // sink forward targets |
| 69 | struct task *forward_task; // task to handle forward targets conns |
| 70 | struct sig_handler *forward_sighandler; /* signal handler */ |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 71 | struct { |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 72 | __decl_hathreads(HA_RWLOCK_T lock); // shared/excl for dropped |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 73 | struct ring *ring; // used by ring buffer and STRM sender |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 74 | unsigned int dropped; // dropped events since last one. |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 75 | int fd; // fd num for FD type sink |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 76 | } ctx; |
| 77 | }; |
| 78 | |
| 79 | #endif /* _TYPES_SINK_H */ |
| 80 | |
| 81 | /* |
| 82 | * Local variables: |
| 83 | * c-indent-level: 8 |
| 84 | * c-basic-offset: 8 |
| 85 | * End: |
| 86 | */ |