【问题标题】:Change timezone to UTC in rsyslog configuration在 rsyslog 配置中将时区更改为 UTC
【发布时间】:2017-06-01 22:54:21
【问题描述】:

示例 JSON 配置模板: 我想将 dateFormat 更改为 UTC 以统一不同客户端的 TZ

template(name="json-template" type="list") {
    constant(value="{")
    constant(value="\"@timestamp\":\"")
    property(name="timereported" dateFormat="rfc3339")
    constant(value="\",\"@version\":\"1")
    constant(value="\",\"message\":\"")
    property(name="msg" format="json")
    constant(value="\",\"sysloghost\":\"")
    property(name="hostname")
    constant(value="\",\"severity\":\"")
    property(name="syslogseverity-text")
    constant(value="\",\"facility\":\"")
    property(name="syslogfacility-text")
    constant(value="\",\"programname\":\"")
    property(name="programname")
    constant(value="\",\"procid\":\"")
    property(name="procid")
    constant(value="\"}\n")
}

【问题讨论】:

    标签: timestamp rsyslog


    【解决方案1】:

    如果你知道时区,你可以这样做:

    template(name="json-template" type="list") {
    constant(value="{")
    constant(value="\"@timestamp\":\"")
    property(name="timereported" dateFormat="year")
    constant(value="-") property(name="timereported" dateFormat="month")
    constant(value="-") property(name="timereported" dateFormat="day")
    constant(value="T") property(name="timereported" dateFormat="hour")
    constant(value=":") property(name="timereported" dateFormat="minute")
    constant(value=":") property(name="timereported" dateFormat="second")
    constant(value="+00:00")
    ...
    

    如果您愿意,时间将重新计算到您的时区,请参见此处:

    http://www.rsyslog.com/doc/v8-stable/configuration/templates.htmlhttp://www.rsyslog.com/doc/v8-stable/configuration/property_replacer.html

    或在源代码中:

    https://github.com/rsyslog/rsyslog/blob/master/runtime/msg.c

    并使用 -utc 函数,例如:now-utc、year-utc、...

    祝你好运

    欧文

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 2016-02-07
      相关资源
      最近更新 更多