108.32. XML (xm_xml)
This module provides functions and procedures for working with data formatted as Extensible Markup Language (XML). It can convert log messages to XML format and can parse XML into fields.
108.32.1. Configuration
The xm_xml module accepts the following directives in addition to the common module directives.
- IgnoreRootTag
-
This optional boolean directive causes parse_xml() to omit the root tag when setting field names. For example, when this is set to TRUE and the RootTag is set to
Event
, a field might be named$Event.timestamp
. With this directive set to FALSE, that field name would be$timestamp
. The default value is TRUE.
Note that leading dot (.
) is not allowed in XML attribute names thus field names
having a leading dot (.
) will always be excluded from XML output.
- ParseAttributes
-
When this optional boolean directive is set to TRUE, parse_xml() will also parse XML attributes. The default is FALSE (attributes are not parsed). For example, if ParseAttributes is set to TRUE, the following would be parsed into
$Msg.time
,$Msg.type
, and$Msg
:<Msg time='2014-06-27T00:27:38' type='ERROR'>foo</Msg>
- RootTag
-
This optional directive can be used to specify the name of the root tag that will be used by to_xml() to generate XML. The default RootTag is
Event
.
108.32.2. Functions
The following functions are exported by xm_xml.
- string
to_xml()
-
Convert the fields to XML and returns this as a string value. The
$raw_event
field and any field having a leading dot (.
) or underscore (_
) will be automatically excluded.Note that directive IncludeHiddenFields has an effect on fields included in the output.
108.32.3. Procedures
The following procedures are exported by xm_xml.
parse_xml();
-
Parse the
$raw_event
field as XML input. parse_xml(string source);
-
Parse the given string as XML format.
to_xml();
-
Convert the fields to XML and put this into the
$raw_event
field. The$raw_event
field and any field having a leading dot (.
) or underscore (_
) will be automatically excluded.Note that directive IncludeHiddenFields has an effect on fields included in the output.
108.32.4. Examples
The following configuration accepts Syslog (both BSD and IETF) and converts it to XML.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Extension syslog>
Module xm_syslog
</Extension>
<Extension xml>
Module xm_xml
</Extension>
<Input tcp>
Module im_tcp
Port 1514
Host 0.0.0.0
Exec parse_syslog(); to_xml();
</Input>
<Output file>
Module om_file
File "/var/log/log.xml"
</Output>
<Route tcp_to_file>
Path tcp => file
</Route>
<30>Sep 30 15:45:43 host44.localdomain.hu acpid: 1 client rule loaded
<Event>
<MessageSourceAddress>127.0.0.1</MessageSourceAddress>
<EventReceivedTime>2012-03-08 15:05:39</EventReceivedTime>
<SyslogFacilityValue>3</SyslogFacilityValue>
<SyslogFacility>DAEMON</SyslogFacility>
<SyslogSeverityValue>6</SyslogSeverityValue>
<SyslogSeverity>INFO</SyslogSeverity>
<SeverityValue>2</SeverityValue>
<Severity>INFO</Severity>
<Hostname>host44.localdomain.hu</Hostname>
<EventTime>2012-09-30 15:45:43</EventTime>
<SourceName>acpid</SourceName>
<Message>1 client rule loaded</Message>
</Event>
The following configuration reads the Windows EventLog and converts it to the BSD Syslog format where the message part contains the fields in XML.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<Extension syslog>
Module xm_syslog
</Extension>
<Extension xml>
Module xm_xml
</Extension>
<Input eventlog>
Module im_msvistalog
Exec $Message = to_xml(); to_syslog_bsd();
</Input>
<Output tcp>
Module om_tcp
Host 192.168.1.1
Port 1514
</Output>
<Route eventlog_to_tcp>
Path eventlog => tcp
</Route>
<14>Mar 8 15:12:12 WIN-OUNNPISDHIG Service_Control_Manager: <Event><EventTime>2012-03-08 15:12:12</EventTime><EventTimeWritten>2012-03-08 15:12:12</EventTimeWritten><Hostname>WIN-OUNNPISDHIG</Hostname><EventType>INFO</EventType><SeverityValue>2</SeverityValue><Severity>INFO</Severity><SourceName>Service Control Manager</SourceName><FileName>System</FileName><EventID>7036</EventID><CategoryNumber>0</CategoryNumber><RecordNumber>6791</RecordNumber><Message>The nxlog service entered the running state. </Message><EventReceivedTime>2012-03-08 15:12:14</EventReceivedTime></Event>