View Source jhn_syslog (jhn_stdlib v5.3.3)
A Syslog library based on: The Syslog Protocol (rfc5424) Transport Layer Security (TLS) Transport Mapping for Syslog (rfc5425) Transmission of Syslog Messages over UDP (rfc5426) Textual Conventions for Syslog Management (rfc5427) Transmission of Syslog Messages over TCP (rfc6587) Datagram Transport Layer Security (DTLS) Transport Mapping for Syslog (rfc6012)
SYSLOG line is represented as follows:
line : #{header => Header, structured => Structured, msg => Message }
Header : #{facility => Facility, severity => Severity, version => Version, time_stamp => TimeStamp, fraction => integer(), offset_sign => '+' | '-' | 'Z', offset => {Hour, Minute}, host_name => iodata(), app_name => iodata(), proc_id => iodata(), msg_id => iodata() }
Facility : kern | user | mail | daemon | auth | syslog | lpr | news | uucp | cron | authpriv | ftp | ntp | audit | console | cron2 | local0 | local1 | local2 | local3 | local4 | local5 | local6 | local7 default: user Severity : emerg | alert | crit | err | warning | notice | info | debug default: info Version : integer() default: 1 TimeStamp : binary() | {{Year, Month, Day}, {Hour, Minute, Second}} | #{year => Year, month => Month, day => Day, hour =>Hour, minute => Minute, second => Second} Year, Month, Day, Hour, Minute, Second : integer()
Structured : [{Id, [{Key, Value}]}] Id, Key, Value : iodata()
Message : #{type => utf8 | any, content => iodata() }
All part of the map are optional. All iodata is in fact a binary when a line is decoded. All header values that can be represented by the nil element "-" has that as default and when decoded omitted from the returned map.
N.B. TCP only supports Octet counting framing. The TLS transport requires the ssl OTP lib which is not included in the application resource file. The DTLS transport requires the ssl OTP lib which is not included in the application resource file.
Summary
Functions
Accepts an incoming connection request on an opened server transport for the TCP and TLS, it returns a connected transport. Equivalent to accept(Transport, []).
Accepts an incoming connection request on an opened server transport for the TCP and TLS, it returns a connected transport.
Closes an already established transport.
Assigns a new controlling process Pid to the Transport socket.
Decodes the binary into a structured Erlang term. Equivalent to decode(Binary, [])
Decodes the binary into a structured Erlang. Decode will give an exception if the binary is not well formed Syslog line.
Encodes the structured Erlang term as an iolist. Equivalent to encode(Line, []).
Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: seconds (default) -> second precision milli -> milli second precision micro -> micro second precision binary -> a binary is returned iolist -> a iolist is returned
Encloses an encoded line in an octet counting frame.
Opens an UDP client or server transport. Equivalent to open([]).
Opens a Transport returning a connected client connection or a listen port for DTLS/TCP/TLS for the server, UDP the difference is quite moot.
Receives a packet from a Transport socket in passive mode. A closed socket is indicated by a return value {error, closed}. Equivalent to recv(Line, []).
Receives a packet from a Transport socket in passive mode. A closed socket is indicated by a return value {error, closed}.
Sends a message over the transport. Equivalent to Send(Transport, Line).
Sends a message over the transport.
Sets one or more options for a transport socket according to the transport.
Extracts the line from an octet counting frame.
Types
-type line() :: map().
-type listen_type() :: dtls_listen | tcp_listen | tls_listen.
-type opt() :: _.
-type socket_options() :: gen_udp:option() | gen_tcp:option() | ssl:socket_option() | ssl:tls_option().
-type transport() :: #transport{type :: type() | listen_type(), role :: client | server, port :: inet:port_number() | undefined, ipv :: ipv4 | ipv6 | undefined, dest :: inet:ip_address() | inet:hostname(), dest_port :: inet:port_number() | undefined, socket :: gen_udp:socket() | gen_tcp:socket() | ssl:sslsocket() | undefined, listen_socket :: gen_tcp:socket() | ssl:sslsocket() | undefined, buf :: binary()}.
-type type() :: udp | dtls | tcp | tls.
Functions
Accepts an incoming connection request on an opened server transport for the TCP and TLS, it returns a connected transport. Equivalent to accept(Transport, []).
Accepts an incoming connection request on an opened server transport for the TCP and TLS, it returns a connected transport.
Options are: timeout -> the time in milliseconds the request is allowed to complete
-spec close(transport()) -> ok | {error, _}.
Closes an already established transport.
Assigns a new controlling process Pid to the Transport socket.
Decodes the binary into a structured Erlang term. Equivalent to decode(Binary, [])
-spec decode(binary(), [opt()] | #opts{type :: type(), role :: client | server, port :: integer() | undefined, opts :: [{atom(), _}], ipv :: ipv4 | ipv6, dest :: inet:ip_address() | inet:hostname(), dest_port :: inet:port_number() | undefined, precision :: seconds | milli | micro, timeout :: integer() | undefined, version :: 'tlsv1.2' | 'tlsv1.3', return_type :: iolist | binary}) -> line().
Decodes the binary into a structured Erlang. Decode will give an exception if the binary is not well formed Syslog line.
Options are: currently none N.B. the timestamp is decode into a date time tuple.
Encodes the structured Erlang term as an iolist. Equivalent to encode(Line, []).
-spec encode(line(), [opt()] | #opts{type :: type(), role :: client | server, port :: integer() | undefined, opts :: [{atom(), _}], ipv :: ipv4 | ipv6, dest :: inet:ip_address() | inet:hostname(), dest_port :: inet:port_number() | undefined, precision :: seconds | milli | micro, timeout :: integer() | undefined, version :: 'tlsv1.2' | 'tlsv1.3', return_type :: iolist | binary}) -> iolist() | binary().
Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: seconds (default) -> second precision milli -> milli second precision micro -> micro second precision binary -> a binary is returned iolist -> a iolist is returned
Encloses an encoded line in an octet counting frame.
-spec open() -> transport() | {error, _}.
Opens an UDP client or server transport. Equivalent to open([]).
-spec open([opt()] | #opts{type :: type(), role :: client | server, port :: integer() | undefined, opts :: [{atom(), _}], ipv :: ipv4 | ipv6, dest :: inet:ip_address() | inet:hostname(), dest_port :: inet:port_number() | undefined, precision :: seconds | milli | micro, timeout :: integer() | undefined, version :: 'tlsv1.2' | 'tlsv1.3', return_type :: iolist | binary}) -> transport() | {error, _}.
Opens a Transport returning a connected client connection or a listen port for DTLS/TCP/TLS for the server, UDP the difference is quite moot.
Options are: client -> opens a client transport (default) server -> open a server transport udp -> uses the UDP protocol (default) dtls -> uses the DTLS v1.2 over UDP tcp -> uses the TCP protocol tls -> uses TLS v1.2(default) or TLS v1.3 over TCP ipv4 -> IPv4 addresses are used (default) ipv6 -> IPv6 addresses are used port -> The port used by client or server with the default in the client case is 0 (the underlying OS assigns an available port number) for the server the default ports are as follows: UDP/514, UDP/6514, TCP/601, TLS/6514 destination -> the IP address or hostname of the server to connect to in the case TCP and TLS and the default server for the UDP/DTLS case destination_port -> the port of the server to connect to in the case TCP/TLS and the default server for the UDP/DTLS case version -> the version used for TLS, v1.2(default) or v1.3. opts -> options to the transport's UDP, DTLS, TCP, or TLS, see the documentation of gen_udp, gen_tcp, ssl respectively timeout -> the time in milliseconds the request is allowed to complete
Receives a packet from a Transport socket in passive mode. A closed socket is indicated by a return value {error, closed}. Equivalent to recv(Line, []).
-spec recv(transport(), [opt()] | #opts{type :: type(), role :: client | server, port :: integer() | undefined, opts :: [{atom(), _}], ipv :: ipv4 | ipv6, dest :: inet:ip_address() | inet:hostname(), dest_port :: inet:port_number() | undefined, precision :: seconds | milli | micro, timeout :: integer() | undefined, version :: 'tlsv1.2' | 'tlsv1.3', return_type :: iolist | binary}) -> {ok, line()} | {ok, line(), transport()} | {error, _}.
Receives a packet from a Transport socket in passive mode. A closed socket is indicated by a return value {error, closed}.
Options are: timeout -> the time in milliseconds the request is allowed to complete
Sends a message over the transport. Equivalent to Send(Transport, Line).
-spec send(transport(), line(), [opt()] | #opts{type :: type(), role :: client | server, port :: integer() | undefined, opts :: [{atom(), _}], ipv :: ipv4 | ipv6, dest :: inet:ip_address() | inet:hostname(), dest_port :: inet:port_number() | undefined, precision :: seconds | milli | micro, timeout :: integer() | undefined, version :: 'tlsv1.2' | 'tlsv1.3', return_type :: iolist | binary}) -> ok | {error, _}.
Sends a message over the transport.
Options are: seconds (default) -> second precision milli -> milli second precision micro -> micro second precision destination -> the IP address or hostname of the peer to send to in the UDP case, otherwise the default provided in open is used destination_port -> the port of the peer in the UDP case
-spec setopts(transport(), socket_options()) -> ok | {error, _}.
Sets one or more options for a transport socket according to the transport.
Extracts the line from an octet counting frame.