2015-02-08 72 views
1

我需要監視由jPos生成的日誌文件。日誌輸出如下所示:Bash監視jPos XML日誌文件

<log realm="channel/10.10.23.81:18090" at="2015-02-08 00:00:19.540 CET" lifespan="9019ms"> 
    <receive> 
    <isomsg direction="incoming"> 
     <!-- org.jpos.iso.packager.GenericPackager[cfg/iso93ascii.xml] --> 
     <field id="0" value="1804"/> 
     <field id="7" value="20150208000019"/> 
     <field id="11" value="399335"/> 
     <field id="24" value="831"/> 
    </isomsg> 
    </receive> 
</log> 
<log realm="channel/10.10.23.81:18090" at="2015-02-08 00:00:19.540 CET"> 
    <send> 
    <isomsg direction="outgoing"> 
     <!-- org.jpos.iso.packager.GenericPackager[cfg/iso93ascii.xml] --> 
     <field id="0" value="1814"/> 
     <field id="7" value="20150208000019"/> 
     <field id="11" value="399335"/> 
     <field id="24" value="831"/> 
     <field id="39" value="800"/> 
    </isomsg> 
    </send> 
</log> 

一條消息總是在日誌標記之間,並且可能是很多行。也可能包含這樣的錯誤:

<log realm="channel/10.10.23.81:18090" at="2015-02-06 00:01:58.728 CET" lifespan="26768ms"> 
    <receive> 
    <iso-exception> 
     org.jpos.iso.IFA_LLNUM: Problem unpacking field 56 (org.jpos.iso.ISOException: Field length 37 too long. Max: 35) unpacking field=56, consumed=282 
     org.jpos.iso.ISOException: org.jpos.iso.IFA_LLNUM: Problem unpacking field 56 (org.jpos.iso.ISOException: Field length 37 too long. Max: 35) unpacking field=56, consumed=282 
     at org.jpos.iso.ISOBasePackager.unpack(ISOBasePackager.java:265) 
     at org.jpos.iso.ISOMsg.unpack(ISOMsg.java:420) 
     at org.jpos.iso.BaseChannel.unpack(BaseChannel.java:924) 
     at org.jpos.iso.BaseChannel.receive(BaseChannel.java:692) 
     at org.jpos.q2.iso.ChannelAdaptor$Receiver.run(ChannelAdaptor.java:319) 
     at java.lang.Thread.run(Thread.java:745) 
    </iso-exception> 
    --- data --- 
    0000 31 34 32 31 46 36 37 34 30 35 43 35 30 45 45 30 1421F67405C50EE0 
0010 41 31 30 30 30 30 30 30 30 30 30 32 30 34 30 30 A100000000010330 
0020 30 30 30 30 31 36 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 000045********** 
0030 2A 2A 33 34 34 32 30 30 30 30 30 30 30 30 30 30 **35670000000000 
0040 30 30 30 31 38 30 30 30 30 30 30 30 30 30 30 31 0001800000000001 
    </receive> 
</log> 

我想通過特定的時間戳grep整個一個消息(「2015年2月6日16:」)和字符串(如ORA,異例外,...)並逐行得到很好的輸出(作爲原點的樣子)。 jPos日誌文件是巨大的,我嘗試設置監控任何故障,結果要發送到電子郵件,所以應該是可讀的。

任何想法的傢伙?

回答

1

我找出解決方案。使用perlgrep將變量和格式再次合併爲xml通過tiny合併輸出:

log_file=/path/q2.log 
log_hour="2015-02-06 10" 
file_to_send=/path/email.txt 
tidy_temp=/tmp/tidy.temp 

perl -pe 's|\n|| ; s|</log>|</log>\n|' $log_file |grep $log_hour |grep -e "ORA-" -e "iso-exception"| tidy -f $tidy_temp -o $file_to_send -i -xml -