【logstash】 - 使用mutate處理數據

mutate:http://www.logstash.net/docs/1.4.2/filters/mutate 數據庫


使用logstash提取oracle的alter日誌的ora錯誤。windows

日誌格式以下:ruby

alter database open
Errors in file d:\oracle\diag\rdbms\hxw168\hxw168\trace\hxw168_ora_6148.trc:
ORA-01589: 要打開數據庫則必須使用 RESETLOGS 或 NORESETLOGS 選項
ORA-1589 signalled during: alter database open...
alter database open resetlogs


logstash內容:bash

input{
	file{
		 codec => plain {
			charset => "CP936" #windows下的編碼是cp936(chcp查看)
		}
		type => "oracleerr"
		path => "D:/logsystem/logstash/bin/test/alert_hxw168.log"   
		start_position => "beginning"
	}
	#stdin{type => "hxwtest"}	

}


filter{
	mutate{
	        #以:號分割message內容,分割後以數據方式顯示。
	        #好比abc:efg => message[0] = abc message[1]=efg
	        
		split => ["message",":"]	
	}
	#第一個數據的內容中ORA-xxxxx這種格式,則這條內容是ora錯誤。添加二個字段
	#oraerr orades
	
	if [message][0] =~ /^ORA-[0-9]{5}/ {
		mutate{
		add_field =>   { 
				"ORAERR" => "%{[message][0]}" 
				"ORADES" => "%{[message][1]}"
				}
				}
		}
	

}



output{
     #有ORAERR字段,則輸出。
     if [ORAERR]{ 
      stdout{
		codec => rubydebug
	}
}

}


結果:oracle

1.
{
       "message" => [
        [0] "ORA-00322",
        [1] " 日誌 2 (用於線程 1) 不是最新副本\r"
    ],
      "@version" => "1",
    "@timestamp" => "2014-12-12T15:50:53.790Z",
          "type" => "oracleerr",
          "host" => "huangwen",
          "path" => "D:/logsystem/logstash/bin/test/alert_hxw168.log",
        "ORAERR" => "ORA-00322",
        "ORADES" => " 日誌 2 (用於線程 1) 不是最新副本\r"
}


2.
{
       "message" => [
        [0] "ORA-00312",
        [1] " 聯機日誌 2 線程 1",
        [2] " 'D",
        [3] "\\ORACLE\\ORADATA\\HXW168\\REDO02.LOG'\r"
    ],
      "@version" => "1",
    "@timestamp" => "2014-12-12T15:50:53.790Z",
          "type" => "oracleerr",
          "host" => "huangwen",
          "path" => "D:/logsystem/logstash/bin/test/alert_hxw168.log",
        "ORAERR" => "ORA-00312",
        "ORADES" => " 聯機日誌 2 線程 1"
}
相關文章
相關標籤/搜索