blob: f39c9c490dc97b9c0f19e1365bd36533b7938903 [file] [log] [blame]
Nathan Skrzypczakd4a70642021-10-08 14:01:27 +02001.. _syslog_doc:
2
3Syslog protocol support
4=======================
5
6VPP provides `RFC5424 <https://tools.ietf.org/html/rfc5424>`__ syslog
7protocol logging, which is used to transport event messages across
8network. VPP currently supports UDP transport based on
9`RFC5426 <https://tools.ietf.org/html/rfc5426>`__.
10
11The syslog message has the following format: \* header \* structured
12data \* free-form message
13
14The header contains, priority, version, timestamp, hostname,
15application, process id and message id. It is followed by structured
16data, which provides a mechanism to express event data in easily
17parsable format. Structured data can contain zero, one or multiple
18structured data elements. Structured data element contains name-value
19pairs. Structured data can by followed by free-form message.
20
21Following example explains how to use the internal APIs to generate
22syslog message:
23
24.. code:: c
25
26 #include <vnet/syslog/syslog.h>
27
28 ...
29
30 syslog_msg_t syslog_msg;
31
32 /* Check if syslog logging is enabled */
33 if (!syslog_is_enabled ())
34 return;
35
36 /* Severity filer test */
37 if (syslog_severity_filter_block (severity))
38 return;
39
40 /* Initialize syslog message header */
41 syslog_msg_init (&syslog_msg, facility, severity, "NAT", "SADD");
42
43 /* Create structured data element */
44 syslog_msg_sd_init (&syslog_msg, "nsess");
45 /* Add structured data element parameters (name-value pairs) */
46 syslog_msg_add_sd_param (&syslog_msg, "SSUBIX", "%d", ssubix);
47 syslog_msg_add_sd_param (&syslog_msg, "SVLAN", "%d", svlan);
48 syslog_msg_add_sd_param (&syslog_msg, "IATYP", "IPv4");
49 syslog_msg_add_sd_param (&syslog_msg, "ISADDR", "%U",
50 format_ip4_address, isaddr);
51 syslog_msg_add_sd_param (&syslog_msg, "ISPORT", "%d", isport);
52 syslog_msg_add_sd_param (&syslog_msg, "XATYP", "IPv4");
53 syslog_msg_add_sd_param (&syslog_msg, "XSADDR", "%U",
54 format_ip4_address, xsaddr);
55 syslog_msg_add_sd_param (&syslog_msg, "XSPORT", "%d", xsport);
56 syslog_msg_add_sd_param (&syslog_msg, "PROTO", "%d", proto);
57
58 /* Send syslog message */
59 syslog_msg_send (&syslog_msg);
60
61Example above produces following syslog message: <134>1
622018-11-12T11:25:30.252715Z 172.16.4.1 NAT 5901 SADD [nsess SSUBIX=“0
63SVLAN=“0 IATYP=“IPv4 ISADDR=“172.16.1.2 ISPORT=“6303 XATYP=“IPv4
64XSADDR=“10.0.0.3 XSPORT=“16253 PROTO=“6”]
65
66To add free-form message use:
67
68.. code:: c
69
70 syslog_msg_add_msg (&syslog_msg, "event log entry");