︿
Top

1、前言

Microsoft Log Parser 是一個功能強大的日誌分析器,它支援許多格式的文字數據,例如 Log、XML、CSV...等日誌檔案,並且也支援 Windows Event Lo、Registry、File System、Active Directory、IIS Log、Exchange Log...等,但強大的 Log Parser 功能可不只如此您不單單只能用它來進行分析,還可將分析後的日誌輸出為其它文件格式或圖表,也可以對分析的日誌執行類似資料庫的搜尋語法 (ex. SELECT、WHERE、GROUP BY...等)來從眾多的文字當中過濾出您所要查詢的資料。






文章目錄

1、前言
          Log Parser 支援的輸入的文件格式 (Input Formats)
          Log Parser 支援的輸出的文件格式 (Output Formats)
2、實作環境
3、安裝及設定
          步驟1.下載 Log Parser 2.2
          步驟2.開始使用 Log Parser
4、Other Log Parser GUI Tools
5、參考



Log Parser 支援的輸入的文件格式 (Input Formats) 

  • IIS log files (W3C, IIS, NCSA, Centralized Binary Logs, HTTP Error logs, URLScan logs, ODBC logs)
  • Windows Event Log
  • Generic XML, CSV, TSV and W3C - formatted text files (e.g. Exchange Tracking log files, Personal Firewall log files, Windows Media® Services log files, FTP log files, SMTP log files, etc.)
  • Windows Registry
  • Active Directory Objects
  • File and Directory information
  • NetMon .cap capture files
  • Extended/Combined NCSA log files
  • ETW traces
  • Custom plugins (through a public COM interface)

Log Parser 支援的輸出的文件格式 (Output Formats) 

  • Write data to text files in different formats (CSV, TSV, XML, W3C, user-defined, etc.)
  • Send data to a SQL database
  • Send data to a SYSLOG server 
  • Create charts and save them in either GIF or JPG image files
  • Display data to the console or to the screen



2、實作環境




3、安裝及設定

步驟1.下載 Log Parser 2.2

下載並安裝 Microsoft Download Center - Log Parser 2.2 ,安裝完成後即可在程式集中找到 Log Parser,點選左下角【開始】 >> 選擇【所有程式】 >> 選擇【Log Parser 2.2】 >> 【Log Parser 2.2】會開出【命令提示字元視窗】其路徑在 ex. C:\Program Files\Log Parser 2.2 下,您可輸入指令 logparser -h EXAMPLE |more 來查看範例指令。
C:\Program Files\Log Parser 2.2> logparser -h EXAMPLE |more
Create a CSV file containing basic information from an ETW .etl binary log
  file:
LogParser "SELECT * INTO Trace.csv FROM myFile.etl"
-- More  --




步驟2.開始使用 Log Parser

此次實作為使用 Log Parser,針對 Exchange Message Tracking Log File 進行文件格式轉換及搜尋 Log 中相關資料。

實作2-1.將 Exchange Message Tracking Log 輸出為 CSV 格式

由於 Exchange Message Tracking Log 若直接查看內容很難找到您所需要的資料,我們利用如下指令來將 Exchange Message Tracking Log 由 W3C 格式重新輸出為 CSV 格式,如此一來即可使用 Excel 來開啟 CSV 檔案增加 Log 辨識度,輸入 / 輸出 (input / output formats) 格式及名稱如下:
  • Exchange Message Tracking Log Name: 20090522.log
  • Exchange Message Tracking Log Formats: W3C
  • Output File Name: 20090522.csv 
  • Output Formats: CSV (文件格式輸出為 Excel)
 cd "C:\Program Files\Log Parser 2.2"
 LogParser "SELECT * INTO 20090522.csv FROM 20090522.log" -i:W3C -o:CSV


實作2-2.搜尋收件人欄位並輸出結果

利用如下指令來搜尋 Exchange Message Tracking Log 中收件人欄位為 weithenn@weithenn.org 的記錄,並將結果輸出為 CSV 格式,輸入 / 輸出 (input / output formats) 格式及名稱如下:
  • Exchange Message Tracking Log Name: 20090522.log
  • Exchange Message Tracking Log Formats: W3C
  • Output File Name: Recipient.csv
  • Output Formats: CSV (文件格式輸出為 Excel)
  • 搜尋收件人欄位名稱: Recipient-Address
  • 搜尋收件人欄位值: weithenn@weithenn.org
cd "C:\Program Files\Log Parser 2.2"
LogParser "SELECT * INTO Recipient.csv FROM 20090522.log WHERE Recipient-Address='weithenn@weithenn.org'" -i:W3C -o:CSV
Statistics:
-----------
Elements processed: 11203           //20090522.log 總共有 11203 筆記錄
Elements output:    268             //符合此條件的有 268 筆
Execution time:     0.22 seconds    //此動作花費時間


實作2-3.搜尋 MTA IP 欄位並輸出結果

利用如下指令來搜尋 Exchange Message Tracking Log 中對方的郵件伺服器 (MTA) 欄位為 60.248.208.146 的 IP 記錄,並將結果輸出為 CSV 格式,輸入 / 輸出 (input / output formats) 格式及名稱如下:
  • Exchange Message Tracking Log Name: 20090522.log
  • Exchange Message Tracking Log Formats: W3C
  • Output File Name: MTA_IP.csv
  • Output Formats: CSV (文件格式輸出為 Excel)
  • 搜尋收件人欄位名稱: client-ip
  • 搜尋收件人欄位值: 60.248.208.146
cd "C:\Program Files\Log Parser 2.2"
LogParser "SELECT * INTO MTA_IP.csv FROM 20090522.log WHERE client-ip='60.248.208.146'" -i:W3C -o:CSV
Statistics:
-----------
Elements processed: 11203           //20090522.log 總共有 11203 筆記錄
Elements output:    15              //符合此條件的有 15 筆
Execution time:     0.21 seconds    //此動作花費時間


實作2-4.搜尋 MTA Hostname 欄位並輸出結果

利用如下指令來搜尋 Exchange Message Tracking Log 中對方的郵件伺服器 (MTA) 欄位為 www.ahasoft.com.tw 的 Hostname 記錄,並將結果輸出為 CSV 格式,輸入 / 輸出 (input / output formats) 格式及名稱如下:
  • Exchange Message Tracking Log Name: 20090522.log
  • Exchange Message Tracking Log Formats: W3C
  • Output File Name: MTA_Host.csv
  • Output Formats: CSV (文件格式輸出為 Excel)
  • 搜尋收件人欄位名稱: Client-hostname
  • 搜尋收件人欄位值: www.ahasoft.com.tw
cd "C:\Program Files\Log Parser 2.2"
LogParser "SELECT * INTO MTA_Host.csv FROM 20090522.log WHERE Client-hostname='www.ahasoft.com.tw'" -i:W3C -o:CSV
Statistics:
-----------
Elements processed: 11203           //20090522.log 總共有 11203 筆記錄
Elements output:    15              //符合此條件的有 15 筆
Execution time:     0.21 seconds    //此動作花費時間




4、Other Log Parser GUI Tools

若您覺得文字介面的 Log Parser 在使用上不是那麼的親切的話,或許您可嘗試另外二套具有 GUI 介面的 Log Parser。





5、參考

文章標籤: