syslog日志格式-RFC3164和RFC5424

日志格式-RFC3164
syslog格式:<PRI>HEADER MESSAGE

syslog的消息长度:不超过1024。

RFC3164协议手册地址:https://tools.ietf.org/html/rfc3164

syslog格式举例:<15>Jul 10 12:00:00 192.168.1.1 SyslogGen MESSAGE 

格式说明:

PRI:即Priority(优先级),有效值范围为0 - 191。不能有空格、数字前也不能补0。合法的形式如:<15>。PRI值包含两部分信息:Facility和Level。其中Facility值用于判断哪个程序产生了日志信息。Level值用于判断严重等级。计算方法:PRI = Facility * 8 + Level。只有一种情况,当0跟着<时,表示优先级为0。其他情况,不能以0开头

Facility可选值为

 

Level可选值为:

 

HEADER:
HEADER包含两个称为TIMESTAMP和HOSTNAME的字段。TIMESTAMP紧跟着PRI中的“>”。TIMESTAMP和HOSTNAME之间用一个空格分隔。HOSTNAME包含主机名。如果没有主机名,将会包含主机的IP地址。如果设备有多个IP地址,将会使用发送数据的IP地址。两者可以选一个发送。在这种情况下,device可能被配置成使用一个源IP发送所有的消息,不管消息实际从哪个接口发出。这种方式为所有的消息的HOSTNAME字段提供了一致性。 TIMESTAMP是本地事件,格式是“Mmm dd hh:mm:ss”:Mmm是月份的英文缩写,以一个大写的M开始,两个小写的m结束。取值如下:Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec。dd是一个月中的天数。如果小于10,必须表示成空格然后是数字。例如8月的第七天表示成为“Aug 7”,其中g和7之间有两个空格。hh:mm:ss是本地时间。小时表示成为24小时的格式,合法值是00到23。分钟和秒是00到59。在TIMESTAMP之后需要有一个空格。HOSTNAME字段包含发送者的主机名或IP地址。最好的名称是主机名。如果使用主机名,HOSTNAME字段必须包含STD 13中描述的主机名。其中不能包含任何空格主机名不能包含在HOSTNAME字段中。如果使用IPv4地址,必须是点分十进制。如果是IPv6格式,使用RFC 2373中的格式。HOSTNAME字段之后也必须有一个空格。

MESSAGE:
MSG部分是syslog报文的剩余部分。通常它包含生成这个消息进程的其他信息以及消息的文本内容。这部分没有结束分隔符。Syslog报文的MSG部分必须包含可见的(可打印)的字符。通常使用和PRI以及HEADER部分一样的ASCII字符集。在这个字符集中,允许的字符是ABNF VCHAR(%d33-126)以及空格(SP value %d32)。然而,不需要在MSG中使用的代码集的指示,也不期望这样做。可以使用其他的字符集,只要MSG中使用的字符是与上述类似的可见的字符和空格。包含不可见字符集的消息不能被展示,也不能被接收者理解,不会给操作员或管理员任何信息。MSG部分有两个字段,分别是TAG和CONTENT。TAG字段的值是产生消息的程序或进程名称。CONTENT部分包含消息的详细信息。通常是开放格式的消息,包含事件的一些详细信息。TAG是32个字符之内的ABNF数字字母字符集。任何非数字字母的字符会被当作TAG字段的结束标记,并且这个字符会当作CONTENT字段的开始。CONTENT字段的第一个字符表示TAG字段的结束,通常是方括号“[”,冒号“:”或者空格。

日志格式RFC5424
syslog格式:<PRI>VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID

RFC5424协议手册地址:https://tools.ietf.org/html/rfc5424

PRI:参见RFC3164中的PRI。
VERSION :版本用来表示Syslog协议的版本,RFC5424的版本号为“1”
TIMESTAMP :时间戳格式为:yyyy-mm-ddTHH:MM:SS.xxxxxx+/-HH:MM 有几个要求:1."T" "Z"必须大写。2.如果无法获取时间戳,必须使用"-"代替。3.不能使用闰秒。4."T"是必须的
HOSTNAME :hostname标识发送syslog消息的源主机。优先选用几种写法:1.FQDN:全限定域名:同时带有主机名和域名的名称。(通过符号“.”)2.Static IP address:静态IP地址。3.Hostname:主机名。4.Dynamic IP address:动态Ip地址。4.the NILVALUE:"-"
APP-NAME:用于识别产生消息的设备或应用,找不到用"-"代替
PROCID :进程名称或进程ID,得不到用"-"代替;ProcId常用于分析日志生成进程的连续性,但不做可靠性保证,比如进程重启还是可能会分到一样的进程ID
MSGID:标识消息类型。例如TCPIN、TCPOUT分别代表TCP数据的流入或流出;如果无法获取数据类型,用"-"代替。 MSGID可根据数据类型用于数据过滤
RFC 5424 简单示例


Example 1 - with no STRUCTURED-DATA
 
<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47
- BOM'su root' failed for lonvick on /dev/pts/8
 
   In this example, the VERSION is 1 and the Facility has the value of
   4.  The Severity is 2.  The message was created on 11 October 2003 at
   10:14:15pm UTC, 3 milliseconds into the next second.  The message
   originated from a host that identifies itself as
   "mymachine.example.com".  The APP-NAME is "su" and the PROCID is
   unknown.  The MSGID is "ID47".  The MSG is "'su root' failed for
   lonvick...", encoded in UTF-8.  The encoding is defined by the BOM.
   There is no STRUCTURED-DATA present in the message; this is indicated
   by "-" in the STRUCTURED-DATA field.
 
   Example 2 - with no STRUCTURED-DATA
 
 <165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1
 myproc 8710 - - %% It's time to make the do-nuts.
   In this example, the VERSION is again 1.  The Facility is 20, the
   Severity 5.  The message was created on 24 August 2003 at 5:14:15am,
   with a -7 hour offset from UTC, 3 microseconds into the next second.
   The HOSTNAME is "192.0.2.1", so the syslog application did not know
   its FQDN and used one of its IPv4 addresses instead.  The APP-NAME is
   "myproc" and the PROCID is "8710" (for example, this could be the
   UNIX PID).  There is no STRUCTURED-DATA present in the message; this
   is indicated by "-" in the STRUCTURED-DATA field.  There is no
   specific MSGID and this is indicated by the "-" in the MSGID field.
GerhardsStandards Track[Page 19]
 
RFC 5424  The Syslog Protocol March 2009
   The message is "%% It's time to make the do-nuts.".  As the Unicode
   BOM is missing, the syslog application does not know the encoding of
   the MSG part.
   Example 3 - with STRUCTURED-DATA
   <165>1 2003-10-11T22:14:15.003Z mymachine.example.com
   evntslog - ID47 [exampleSDID@32473 iut="3" eventSource=
   "Application" eventID="1011"] BOMAn application
   event log entry...
   This example is modeled after Example 1.  However, this time it
   contains STRUCTURED-DATA, a single element with the value
   "[exampleSDID@32473 iut="3" eventSource="Application"
   eventID="1011"]".  The MSG itself is "An application event log
   entry..."  The BOM at the beginning of MSG indicates UTF-8 encoding.
   Example 4 - STRUCTURED-DATA Only
   <165>1 2003-10-11T22:14:15.003Z mymachine.example.com
   evntslog - ID47 [exampleSDID@32473 iut="3" eventSource=
   "Application" eventID="1011"][examplePriority@32473
   class="high"]


原文链接:https://blog.csdn.net/zhj100921/article/details/104326748

  • 6
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值