Collect Log Analytics Data from Syslog Messages
Related pages:
To set this up:
- Configure your web server, such as Apache, to send logs to the Analytics Agent. There are two ways to direct the syslog data to the Analytics Agent:
- Write the log messages to the usual log files and then read and forward to the agent from the log file. See Read syslog Messages From the Log File and Send to Analytics Agent.
- Send the log data directly to the Analytics Agent without writing to a file first. See Send syslog Data Directly to the Analytics Agent.
- Configure the Analytics Agent to receive and parse the logs. There are two ways to configure syslog message collection for Log Analytics:
- Job files (for <= 4.2), see Configure Log Analytics TCP Job File.
- Source rules (for 4.3) Recommended for your new log file sources. See Configure Log Analytics TCP Source Rule.
Supported Environment Details
- Linux only
- Network protocol is TCP only
- A template for Apache Web Server syslog format is shipped with the Analytics Agent. You can bring any log data in through syslog over TCP as long as you provide the correct configuration to parse the log message.
- One job file per Analytics Agent can be enabled to receive syslog messages over TCP.
Send syslog Data Directly to the Analytics Agent
You can use the Linux Logger utility to direct your Apache access and error log messages to the syslog daemon directly. Using this method, the logs are not written to the usual access log and error log apache files or to the /var/log/message file. Instead, the log lines are sent directly to a syslog daemon which then forwards the data to the analytics-agent.
Configure:
- Configure Apache to delegate logs to /usr/bin/logger .
- Configure the rsyslog client.
- Restart apache and rsyslog, and look at /var/log/messages for any rsyslog errors.
Read syslog Messages From the Log File and Send to Analytics Agent
In this case, the Apache server writes logs to the usual access log and error log files, and the rsyslog daemon is configured to read from these log files and forward the log data to analytics agent. This method preserves the original log files. In this case, the access and the error log messages are logged in the /var/log/message file.
In this example, the rsyslog client is configured to read from a specific file and forward the message with facility local6 and severity level info over the specified port (default port is 514).
- Locate and edit rsyslog.conf, typically located at /etc/ .
-
In the begin forwarding section of the rsyslog.conf file, add the following lines:
# add these lines in the begin forwarding section $ModLoad imfile $InputFileName /etc/httpd/logs/access_log << your file $InputFileTag apache-access $InputFileStateFile stat-apache-access $InputFileSeverity info $InputFileFacility local6 $InputRunFileMonitor local6.info @@localhost:514$InputFileName: path to the log file you want to tail.
local6.info: Use the Analytics Agent IP address if your analytics agent is not local to the controller. If needed, replace 514 with the port where the analytics-agent is listening for syslog messages. This must match the port specified in the job file or the source rule.
-
Restart rsyslog and review /var/log/messages for any rsyslog errors.
Configure Log Analytics TCP Source Rule
Using the Centralized Log Management UI, you can configure a source rule to extract log analytics fields from syslog messages over TCP.
Configure Log Analytics TCP Job File
When selecting and configuring the port where the analytics agent will listen for the syslog data, make sure it does not conflict with anything else active in the network. If no port number is provided, port 514 is used. Both the syslog utility and analytics-agent should have root access to send logs to port 514 (binding to ports less than 1024 requires root access).
To allow the analytics-agent to listen at a port, specify the log file source property and associated parameters for type=syslog. For example, add the following to the appropriate job file:
source:
type: syslog
port: 514
protocol: tcp
numThreads: 1A job file for apache commons is included in the analytics distribution at /<analytics-agent-home>/conf/job/sample-apache-httpserver-access-syslog.job.
Your job file should look similar to the following:
version: 2
enabled: true
source:
type: syslog
port: 514
protocol: tcp
numThreads: 5
fields:
sourceType: apache-httpserver-access-syslog
nodeName: Node1
tierName: Tier1
appName: App1
grok:
patterns:
- "%{SYSLOG5424PRI}%{SYSLOGBASE2} %{COMBINEDAPACHELOG}"
eventTimestamp:
pattern: "dd/MMM/yyyy:HH:mm:ss Z"