%HOSTNAME%的值在rsyslog中是 "未知"。[英] %HOSTNAME% value is "unknown" in rsyslog

本文是小编为大家收集整理的关于%HOSTNAME%的值在rsyslog中是 "未知"。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

GIST

rsyslog在哪里获得%hostName%的值?
为什么Tomcat提供的应用程序具有正确的%主机名%,但是具有相同配置的控制台应用程序具有"未知"为主机名?

我们在EC2实例上使用RSYSLOG,我们正在尝试将登录发送到loggly.如果我tail -f日志消息,我可以在默认格式中看到日志,包括日期,主机名,标签和消息.

如果我使用logger "message",则在控制台和loggly中看到正确的日志条目.但是,如果Java控制台应用程序记录事件,则主机名在控制台和loggly中都是"未知".

奇怪的是,如果rsyslog,syslog4j和log4j的相同配置,如果它来自tomcat托管的Web应用程序,则会产生正确的日志条目.

rsyslog在哪里获得%hostName%的值?为什么Tomcat提供的应用程序具有正确的%主机名%,但是具有相同配置的控制台应用程序具有"未知"为主机名?

推荐答案

如果rsyslog.conf中没有此行,请添加并重新启动rsyslog $ actionfiledEfaultTemplate rsyslog_traditionalfileformat

其他推荐答案

我弄清楚了.为了获得主机名,我需要将主机名映射到主机文件中的IP地址.我实际上以为这已经在发生,但是在脚本运行以附加正确的主机条目时,IP地址未知,只有主机名被附加到文件中.

我添加了正确的条目,并且主机名在rsyslog和loggly中如预期出现.

与此同时,我将落loggly格式从%hostName%转换为%$ myhostname%.这对我们来说很好,因为我们不是远程记录,所以$ myhostname始终是正确的主机名.

本文地址:https://www.itbaoku.cn/post/1575141.html

问题描述

The Gist

Where does rsyslog get the value of %HOSTNAME%?
Why does an application served by Tomcat have the correct %HOSTNAME%, but a console application with the same configuration has "unknown" as the hostname?

We're using rsyslog on an EC2 instance and we're trying to send our logs out to loggly. If I tail -f the log messages, I can see the log in the default format including date, hostname, tag, and message.

If I use logger "message" then I see a correct log entry both in the console and in loggly. However, if a java console application logs an event, the hostname is "unknown" both in the console and in loggly.

Oddly, the same configuration of rsyslog, syslog4j, and log4j results in the correct log entry if it comes from a web application hosted by tomcat.

Where does rsyslog get the value of %HOSTNAME%? Why does an application served by Tomcat have the correct %HOSTNAME%, but a console application with the same configuration has "unknown" as the hostname?

推荐答案

If there is not this line in rsyslog.conf add it and restart rsyslog $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

其他推荐答案

I figured this out. In order to get the hostname I needed to map the hostname to the ip address in the hosts file. I actually thought this was happening already, but at the time the script runs to append the correct hosts entry, the IP address is unknown and just the hostname gets appended to the file.

I added the correct entry and the hostname appears as expected in rsyslog and loggly.

In the meantime, I had changed the loggly format from %HOSTNAME% to %$myhostname%. This worked fine for us because we weren't remote logging so $myhostname was always the correct hostname.