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

查看:129
本文介绍了%HOSTNAME%的值是“未知",在rsyslog中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要点

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

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?

我们在EC2实例上使用rsyslog,并且试图将日志发送到loggly.如果我tail -f日志消息,则可以看到默认格式的日志,包括日期,主机名,标记和消息.

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.

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

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.

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

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.

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

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?

推荐答案

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

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.

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

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

同时,我已将Loggly格式从%HOSTNAME%更改为%$ myhostname%.这对我们来说很好,因为我们不是远程日志记录,所以$ myhostname始终是正确的主机名.

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.

这篇关于%HOSTNAME%的值是“未知",在rsyslog中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆