/src/ntopng/include/SyslogCollectorInterface.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * |
3 | | * (C) 2019-24 - ntop.org |
4 | | * |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | | * |
20 | | */ |
21 | | |
22 | | #ifndef _SYSLOG_COLLECTOR_INTERFACE_H_ |
23 | | #define _SYSLOG_COLLECTOR_INTERFACE_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | #ifndef HAVE_NEDGE |
28 | | |
29 | | class LuaEngine; |
30 | | |
31 | | typedef struct { |
32 | | int socket; |
33 | | struct sockaddr_in address; |
34 | | char ip_str[INET_ADDRSTRLEN]; |
35 | | } syslog_client; |
36 | | |
37 | | typedef struct { |
38 | | bool enable; |
39 | | struct sockaddr_in addr; |
40 | | int sock; |
41 | | } syslog_socket; |
42 | | |
43 | | #define USE_RECVLINE |
44 | | |
45 | | class SyslogCollectorInterface : public SyslogParserInterface { |
46 | | private: |
47 | | char *endpoint; |
48 | | syslog_socket udp_socket; |
49 | | syslog_socket tcp_socket; |
50 | | syslog_client tcp_connections[MAX_SYSLOG_SUBSCRIBERS]; |
51 | | |
52 | | struct { |
53 | | u_int32_t num_flows; |
54 | | } recvStats; |
55 | | |
56 | | bool openSocket(syslog_socket *ss, const char *server_address, |
57 | | int server_port, int protocol); |
58 | | void closeSocket(syslog_socket *ss, int protocol); |
59 | | int initFDSetsSocket(syslog_socket *ss, fd_set *read_fds, fd_set *write_fds, |
60 | | fd_set *except_fds, int protocol); |
61 | | int initFDSets(fd_set *read_fds, fd_set *write_fds, fd_set *except_fds); |
62 | | #ifdef USE_RECVLINE |
63 | | int recvLine(int socket, char *buffer, size_t n); |
64 | | #endif |
65 | | |
66 | | public: |
67 | | SyslogCollectorInterface(const char *_endpoint); |
68 | | ~SyslogCollectorInterface(); |
69 | | |
70 | | int handleNewConnection(); |
71 | | void closeConnection(syslog_client *client); |
72 | | int receiveFromClient(syslog_client *client); |
73 | | |
74 | | int receive(int socket, char *client_ip, bool use_recvfrom); |
75 | | |
76 | 0 | virtual const char *get_type() const { |
77 | 0 | return (CONST_INTERFACE_TYPE_SYSLOG); |
78 | 0 | }; |
79 | 0 | virtual InterfaceType getIfType() const { return (interface_type_SYSLOG); } |
80 | 0 | inline char *getEndpoint(u_int8_t id) { return (endpoint); }; |
81 | 0 | virtual bool isPacketInterface() const { return (false); }; |
82 | | void collect_events(); |
83 | | |
84 | | void startPacketPolling(); |
85 | | void shutdown(); |
86 | | bool set_packet_filter(char *filter); |
87 | | virtual void lua(lua_State *vm, bool fullStats); |
88 | | }; |
89 | | |
90 | | #endif /* HAVE_NEDGE */ |
91 | | |
92 | | #endif /* _SYSLOG_COLLECTOR_INTERFACE_H_ */ |