使用rsyslog+loganalzey收集日誌顯示客戶端ip

parakai發表於2014-11-07

1、資料庫修改

LogAnalyzer 預設表欄位只有一個 FromHost,我們在新增一個 FromIP,用於記錄源IP地址。

mysql> use Syslog;
mysql> alter table SystemEvents add FromIP varchar(60) default null after FromHost; 

2、修改rsyslog.conf

rsyslog 預設情況下插入語句沒有 FromIP欄位,我們修改插入SQL 語句新增 FromIP欄位即可。

$template insertpl,"insert into SystemEvents (Message, Facility, FromHost, FromIP, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%, '%HOSTNAME%', '%fromhost-ip%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",SQL
$ModLoad ommysql 
 *.*       :ommysql:localhost,Syslog,rsyslog,syslog;insertpl 
#應用上面SQL語句,template在ModLoad上面

3、LogAnalyzer新增源IP地址

3.1、登入管理後臺

enter image description here

使用管理員賬號登入

enter image description here

進入Admin Center

enter image description here

3.2、新增Fields

enter image description here

3.3、新增views

enter image description here

3.4新增DBMappings,用於建立欄位對應關係

enter image description here

注: DBMappings注意大小寫,對應後面全部小寫,不能有錯,對應如下。

uID => id, Date => devicereportedtime, Host => fromhost, Messagetype => infounitid, Message => message, Facility => facility, Severity => priority, Syslogtag => syslogtag, ProcessID => processid, Event ID => eventid, Eventlog Type => eventlogtype, Event Source => eventsource, Event Category => eventcategory, Event User => eventuser, SystemID => systemid, Checksum => checksum

3.5、修改資料來源配置

修改預設 Table type =>> MonitorWare, 修改為 NewSyslog 也就是上面新新增的NewSyslog。

修改日誌選擇 Select View => NewSyslog。 enter image description here

4、效果圖

enter image description here

相關文章