我有一个应用程序创build使用syslog集中的报告,我将它们存储在Postgres数据库中供自定义使用。
数据库有一个特定的格式(假设我集中的数据是一种csv,每列都有特定的含义)。 到目前为止,这么好,数据正确地插入到数据库中,格式正确。
如果格式不正确的消息将其传递给系统日志(例如,使用文本而不是int),则会发生插入错误,因为该types是无效的,这是期望的…但批处理的下一个消息也会被静默地丢弃(我相信这是因为插入事务)
Sep 2 16:10:45 my-computer postgres[7642]: [2-2] 2011-09-02 16:10:45 CEST STATEMENT: insert into RudderSysEvents (executionDate, nodeId, configurationRuleId, policyInstanceId, serial, Component, KeyValue, executionTimeStamp, eventType, msg, Policy) values ('2011-09-02T16:10:45.592739+02:00','bla', '' , '', '', '', '', '', '', '', 'sdfsfsf' ) Sep 2 16:10:45 nicolas-laptop postgres[7643]: [2-1] 2011-09-02 16:10:45 CEST ERROR: invalid input syntax for integer: "" at character 224
我的问题是: 我怎样才能避免这一点?
我正在考虑这些解决scheme:
尝试在rsyslog端使插入非事务性,或者进行单线交易
$ActionQueueSize 1 $ActionQueueType Direct $MainMsgQueueSize 1 $MainMsgQueueType Direct
但它没有奏效(我猜想这会是一个性能杀手)
在插入之前,先用regexp来检查字段的内容
那么,这是一个艰巨的任务,特别是因为我检查$ programname和$味精,我不能真正使用正则expression式
if $programname startswith 'rudder' and $msg startswith ' R: @@' then
那么,我不是非常热衷于这个解决scheme
哦,我正在使用rsyslog 4.6.4-2
谢谢 !
编辑:最后,我通过用相当复杂的正则expression式过滤消息来绕过这个解决scheme
:msg, ereregex, "R: @@[a-zA-Z0-9\-]+?@@[a-zA-Z0-9_\-]{1,64}?@@[a-zA-Z0-9\-]+@@[a-zA-Z0-9\-]+?@@[0-9]+?@@[a-zA-Z0-9\-]+?@@[a-zA-Z0-9\-]+?@@[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}[+-][0-9]{2}:[0-9]{2}##[a-zA-Z0-9\-]+?@#.*" :ompgsql:localhost,rudder,rudder,Normation;RudderDbLinuxReportFormat
这不是很容易维护,但它工作,并没有打破,因为。 感谢您的build议,我会在不远的将来使用存储过程。
只是一个想法,我不知道是否有帮助:
如何修改默认的SQL INSERT模板,以便它调用一个有足够的逻辑来处理乱码的PL / pgSQL STORED PROCEDURE? 这里有一些信息: http : //www.rsyslog.com/doc/ommysql.html (这是MySQL的,但同样适用于PostgreSQL模块)。
最后,我通过用相当复杂的正则expression式过滤消息来绕过这个解决scheme
:msg, ereregex, "R: @@[a-zA-Z0-9\-]+?@@[a-zA-Z0-9_\-]{1,64}?@@[a-zA-Z0-9\-]+@@[a-zA-Z0-9\-]+?@@[0-9]+?@@[a-zA-Z0-9\-]+?@@[a-zA-Z0-9\-]+?@@[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}[+-][0-9]{2}:[0-9]{2}##[a-zA-Z0-9\-]+?@#.*" :ompgsql:localhost,rudder,rudder,Normation;RudderDbLinuxReportFormat
这不是很容易维护,但它工作,并没有打破,因为。 感谢您的build议,我会在不远的将来使用存储过程。